ver. 0.276: ShopOrder migration, Integrations cleanup, global admin search

This commit is contained in:
2026-02-15 16:37:57 +01:00
parent c0030c3cf3
commit 7cc0cadd6d
34 changed files with 2196 additions and 1063 deletions

View File

@@ -0,0 +1,94 @@
<?php
namespace Tests\Unit\Domain\Order;
use PHPUnit\Framework\TestCase;
use Domain\Order\OrderRepository;
class OrderRepositoryTest extends TestCase
{
public function testOrderStatusesReturnsMappedArray(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('select')
->willReturnCallback(function ($table, $columns, $where) {
if ($table === 'pp_shop_statuses') {
return [
['id' => 0, 'status' => 'Nowe'],
['id' => 4, 'status' => 'W realizacji'],
];
}
return [];
});
$repository = new OrderRepository($mockDb);
$statuses = $repository->orderStatuses();
$this->assertIsArray($statuses);
$this->assertSame('Nowe', $statuses[0]);
$this->assertSame('W realizacji', $statuses[4]);
}
public function testNextAndPrevOrderIdReturnNullForInvalidInput(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->never())->method('get');
$repository = new OrderRepository($mockDb);
$this->assertNull($repository->nextOrderId(0));
$this->assertNull($repository->prevOrderId(0));
}
public function testListForAdminReturnsItemsAndTotal(): void
{
$mockDb = $this->createMock(\medoo::class);
$resultSetCount = new class {
public function fetchAll(): array
{
return [[3]];
}
};
$resultSetData = new class {
public function fetchAll(): array
{
return [
[
'id' => 11,
'number' => '2026/02/001',
'date_order' => '2026-02-15 10:00:00',
'client' => 'Jan Kowalski',
'order_email' => 'jan@example.com',
'address' => 'Testowa 1, 00-000 Warszawa',
'status' => 0,
'client_phone' => '111222333',
'transport' => 'Kurier',
'payment_method' => 'Przelew',
'summary' => '123.45',
'paid' => 1,
'total_orders' => 2,
],
];
}
};
$callIndex = 0;
$mockDb->method('query')
->willReturnCallback(function () use (&$callIndex, $resultSetCount, $resultSetData) {
$callIndex++;
return $callIndex === 1 ? $resultSetCount : $resultSetData;
});
$repository = new OrderRepository($mockDb);
$result = $repository->listForAdmin([], 'date_order', 'DESC', 1, 15);
$this->assertSame(3, $result['total']);
$this->assertCount(1, $result['items']);
$this->assertSame(11, $result['items'][0]['id']);
$this->assertSame('2026/02/001', $result['items'][0]['number']);
$this->assertSame(2, $result['items'][0]['total_orders']);
$this->assertSame(1, $result['items'][0]['paid']);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\ShopOrderController;
use Domain\Order\OrderAdminService;
class ShopOrderControllerTest extends TestCase
{
private $service;
private $controller;
protected function setUp(): void
{
$this->service = $this->createMock(OrderAdminService::class);
$this->controller = new ShopOrderController($this->service);
}
public function testConstructorAcceptsService(): void
{
$controller = new ShopOrderController($this->service);
$this->assertInstanceOf(ShopOrderController::class, $controller);
}
public function testHasExpectedActionMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'list'));
$this->assertTrue(method_exists($this->controller, 'view_list'));
$this->assertTrue(method_exists($this->controller, 'details'));
$this->assertTrue(method_exists($this->controller, 'order_details'));
$this->assertTrue(method_exists($this->controller, 'edit'));
$this->assertTrue(method_exists($this->controller, 'order_edit'));
$this->assertTrue(method_exists($this->controller, 'save'));
$this->assertTrue(method_exists($this->controller, 'order_save'));
$this->assertTrue(method_exists($this->controller, 'notes_save'));
$this->assertTrue(method_exists($this->controller, 'order_status_change'));
$this->assertTrue(method_exists($this->controller, 'order_resend_confirmation_email'));
$this->assertTrue(method_exists($this->controller, 'set_order_as_unpaid'));
$this->assertTrue(method_exists($this->controller, 'set_order_as_paid'));
$this->assertTrue(method_exists($this->controller, 'send_order_to_apilo'));
$this->assertTrue(method_exists($this->controller, 'toggle_trustmate_send'));
$this->assertTrue(method_exists($this->controller, 'delete'));
$this->assertTrue(method_exists($this->controller, 'order_delete'));
}
public function testViewActionsReturnString(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
$this->assertEquals('string', (string)$reflection->getMethod('view_list')->getReturnType());
$this->assertEquals('string', (string)$reflection->getMethod('details')->getReturnType());
$this->assertEquals('string', (string)$reflection->getMethod('order_details')->getReturnType());
$this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
$this->assertEquals('string', (string)$reflection->getMethod('order_edit')->getReturnType());
}
public function testMutationActionsReturnVoid(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('order_save')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('notes_save')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('order_status_change')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('order_resend_confirmation_email')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('set_order_as_unpaid')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('set_order_as_paid')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('send_order_to_apilo')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('toggle_trustmate_send')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('delete')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('order_delete')->getReturnType());
}
public function testConstructorRequiresOrderAdminService(): void
{
$reflection = new \ReflectionClass(ShopOrderController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(1, $params);
$this->assertEquals('Domain\\Order\\OrderAdminService', $params[0]->getType()->getName());
}
}