Files
Gnuboard7/plugins/_bundled/sirsoft-pay_nicepayments/tests/PluginTestCase.php
T
thisgun 5a9ad97327 fix(payment): 나이스페이 간편결제 표시 라벨 보강
나이스페이 간편결제 선택값을 콜백까지 보존하고 주문완료, 마이페이지, 관리자 주문목록/상세에서 실제 간편결제명을 표시한다.
2026-07-04 10:05:24 +09:00

200 lines
6.3 KiB
PHP

<?php
namespace Plugins\Sirsoft\PayNicepayments\Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
abstract class PluginTestCase extends TestCase
{
use RefreshDatabase;
protected function shouldSeed(): bool
{
return true;
}
protected function seeder(): string
{
return \Modules\Sirsoft\Ecommerce\Database\Seeders\TestingSeeder::class;
}
protected function migrateFreshUsing(): array
{
return [
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
'--seed' => $this->shouldSeed(),
'--seeder' => $this->seeder(),
'--path' => [
'database/migrations',
'modules/sirsoft-ecommerce/database/migrations',
],
];
}
protected function setUp(): void
{
parent::setUp();
$this->registerModuleAutoload();
$this->registerPluginAutoload();
$this->app->register(\Modules\Sirsoft\Ecommerce\Providers\EcommerceServiceProvider::class);
$this->registerModuleRoutes();
$this->registerPluginRoutes();
// SettingsServiceProvider 가 storage/app/settings/general.json 의 site_url 로
// app.url 을 override 하면 Laravel 의 assertRedirect (APP_URL 기반) 와 mismatch.
// 테스트 환경에서는 APP_URL 그대로 사용하도록 명시 리셋.
\Illuminate\Support\Facades\Config::set('app.url', env('APP_URL', 'http://localhost'));
}
protected static function krwCurrencySnapshot(): array
{
return [
'base_currency' => 'KRW',
'order_currency' => 'KRW',
'base_unit' => 1,
'exchange_rates' => [
'KRW' => [
'rate' => 1,
'rounding_unit' => '1',
'rounding_method' => 'round',
'decimal_places' => 0,
'base_unit' => 1,
],
],
];
}
protected function registerModuleAutoload(): void
{
$moduleBasePath = base_path('modules/sirsoft-ecommerce/src/');
spl_autoload_register(function ($class) use ($moduleBasePath) {
$prefix = 'Modules\\Sirsoft\\Ecommerce\\';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relativeClass = substr($class, $len);
$file = $moduleBasePath . str_replace('\\', '/', $relativeClass) . '.php';
if (file_exists($file)) {
require $file;
}
});
$helpersFile = $moduleBasePath . 'Helpers/helpers.php';
if (file_exists($helpersFile)) {
require_once $helpersFile;
}
}
protected function registerPluginAutoload(): void
{
$pluginBasePath = base_path('plugins/sirsoft-pay_nicepayments/src/');
spl_autoload_register(function ($class) use ($pluginBasePath) {
$prefix = 'Plugins\\Sirsoft\\Nicepayments\\';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relativeClass = substr($class, $len);
$file = $pluginBasePath . str_replace('\\', '/', $relativeClass) . '.php';
if (file_exists($file)) {
require $file;
}
});
}
protected function registerModuleRoutes(): void
{
$apiRoutesFile = base_path('modules/sirsoft-ecommerce/src/routes/api.php');
if (file_exists($apiRoutesFile)) {
\Illuminate\Support\Facades\Route::prefix('api/modules/sirsoft-ecommerce')
->name('api.modules.sirsoft-ecommerce.')
->middleware('api')
->group($apiRoutesFile);
}
}
protected function registerPluginRoutes(): void
{
$webRoutesFile = base_path('plugins/sirsoft-pay_nicepayments/src/routes/web.php');
if (file_exists($webRoutesFile)) {
\Illuminate\Support\Facades\Route::prefix('plugins/sirsoft-pay_nicepayments')
->name('plugins.sirsoft-pay_nicepayments.')
->middleware('web')
->group($webRoutesFile);
}
$apiRoutesFile = base_path('plugins/sirsoft-pay_nicepayments/src/routes/api.php');
if (file_exists($apiRoutesFile)) {
\Illuminate\Support\Facades\Route::prefix('api/plugins/sirsoft-pay_nicepayments')
->name('api.plugins.sirsoft-pay_nicepayments.')
->middleware('api')
->group($apiRoutesFile);
}
}
protected function createAdminUser(array $permissions = []): \App\Models\User
{
$user = \App\Models\User::factory()->create();
$uniqueRoleIdentifier = 'admin-test-' . $user->id . '-' . time();
$userRole = \App\Models\Role::create([
'identifier' => $uniqueRoleIdentifier,
'name' => ['ko' => '테스트 관리자', 'en' => 'Test Admin'],
]);
$user->roles()->attach($userRole->id);
$adminAccessPermission = \App\Models\Permission::firstOrCreate(
['identifier' => 'admin.access'],
[
'name' => ['ko' => '관리자 접근', 'en' => 'Admin Access'],
'type' => \App\Enums\PermissionType::Admin,
]
);
$userRole->permissions()->attach($adminAccessPermission->id);
if (! empty($permissions)) {
foreach ($permissions as $permissionIdentifier) {
$permission = \App\Models\Permission::firstOrCreate(
['identifier' => $permissionIdentifier],
[
'name' => ['ko' => $permissionIdentifier, 'en' => $permissionIdentifier],
'type' => 'admin',
]
);
$userRole->permissions()->syncWithoutDetaching([$permission->id]);
}
}
return $user;
}
protected function createUser(): \App\Models\User
{
$userRole = \App\Models\Role::where('identifier', 'user')->first();
$user = \App\Models\User::factory()->create();
if ($userRole) {
$user->roles()->attach($userRole->id);
}
return $user;
}
}