донат шоп, управление магазином, яндекс метрика
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\GameAccountUser;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminShopFeatureTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
config(['database.connections.store' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']]);
|
||||
DB::purge('store');
|
||||
|
||||
Schema::connection('store')->create('store_categories', function (Blueprint $table): void {
|
||||
$table->increments('id');
|
||||
$table->string('name')->nullable();
|
||||
$table->text('icon')->nullable();
|
||||
$table->integer('requiredRank')->nullable();
|
||||
$table->unsignedInteger('flags')->default(0);
|
||||
$table->unsignedInteger('enabled')->default(1);
|
||||
});
|
||||
Schema::connection('store')->create('store_services', function (Blueprint $table): void {
|
||||
$table->increments('id');
|
||||
foreach (['type', 'price', 'currency', 'hyperlinkId', 'creatureEntry', 'discountAmount', 'flags'] as $column) {
|
||||
$table->integer($column)->nullable();
|
||||
}
|
||||
foreach (['name', 'tooltipName', 'tooltipType', 'tooltipText', 'icon'] as $column) {
|
||||
$table->text($column)->nullable();
|
||||
}
|
||||
foreach (range(1, 8) as $slot) {
|
||||
$table->unsignedInteger('reward_'.$slot)->nullable();
|
||||
$table->unsignedInteger('rewardcount_'.$slot)->nullable();
|
||||
}
|
||||
$table->unsignedInteger('new')->default(0);
|
||||
$table->unsignedInteger('enabled')->nullable();
|
||||
});
|
||||
Schema::connection('store')->create('store_category_service_link', function (Blueprint $table): void {
|
||||
$table->unsignedInteger('category');
|
||||
$table->unsignedInteger('service');
|
||||
$table->primary(['category', 'service']);
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_can_manage_game_store_category_and_product(): void
|
||||
{
|
||||
$admin = $this->admin();
|
||||
$this->actingAs($admin)->post(route('admin.shop.categories.store'), [
|
||||
'name' => 'Маунты', 'icon' => 'ability_mount', 'requiredRank' => 0, 'flags' => 0, 'enabled' => 1,
|
||||
])->assertSessionHas('status', 'Категория создана.');
|
||||
|
||||
$categoryId = (int) DB::connection('store')->table('store_categories')->value('id');
|
||||
$payload = [
|
||||
'category_ids' => [$categoryId], 'type' => 3, 'name' => 'Спектральный тигр',
|
||||
'tooltipName' => 'Маунт', 'tooltipType' => 'spell', 'tooltipText' => 'Редкий транспорт',
|
||||
'icon' => 'ability_mount_spectraltiger', 'price' => 3000, 'hyperlinkId' => 42777,
|
||||
'creatureEntry' => 24004, 'discountAmount' => 0, 'flags' => 0,
|
||||
'reward_1' => 42777, 'rewardcount_1' => 1, 'new' => 1, 'enabled' => 1,
|
||||
];
|
||||
$this->actingAs($admin)->post(route('admin.shop.products.store'), $payload)
|
||||
->assertSessionHas('status', 'Товар создан.');
|
||||
|
||||
$this->assertDatabaseHas('store_services', ['name' => 'Спектральный тигр', 'price' => 3000], 'store');
|
||||
$this->assertDatabaseHas('store_category_service_link', ['category' => $categoryId], 'store');
|
||||
$this->actingAs($admin)->get(route('admin.shop.index'))->assertOk()->assertSee('Спектральный тигр');
|
||||
}
|
||||
|
||||
public function test_regular_player_cannot_manage_store(): void
|
||||
{
|
||||
$this->actingAs($this->admin(0))->get(route('admin.shop.index'))->assertForbidden();
|
||||
}
|
||||
|
||||
private function admin(int $gmLevel = 3): GameAccountUser
|
||||
{
|
||||
return new GameAccountUser(1, 'ADMIN', 'ADMIN@EXAMPLE.COM', 'ADMIN@EXAMPLE.COM', $gmLevel, false, null, null, str_repeat('AA', 32), str_repeat('BB', 32));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user