Files
shopPRO/tests/Unit/admin/Controllers/ShopOrderControllerTest.php
Jacek Pyziak 21efe28464 ver. 0.295: Admin order product editing — add/remove/modify products, AJAX search, stock adjustment
- Order product CRUD in admin panel (add, delete, edit quantity/prices)
- AJAX product search endpoint for order edit form
- Automatic stock adjustment when editing order products
- Transport cost recalculation based on free delivery threshold
- Fix: promo price = 0 when equal to base price (no real promotion)
- Clean up stale temp/ build artifacts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:30:38 +01:00

89 lines
4.7 KiB
PHP

<?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'));
$this->assertTrue(method_exists($this->controller, 'search_products_ajax'));
}
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());
$this->assertEquals('void', (string)$reflection->getMethod('search_products_ajax')->getReturnType());
}
public function testConstructorRequiresOrderAdminService(): void
{
$reflection = new \ReflectionClass(ShopOrderController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(2, $params);
$this->assertEquals('Domain\\Order\\OrderAdminService', $params[0]->getType()->getName());
$this->assertEquals('Domain\\Product\\ProductRepository', $params[1]->getType()->getName());
$this->assertTrue($params[1]->isOptional());
}
}