- Migrate front\factory\ShopBasket → Domain\Basket\BasketCalculator (4 static methods, 18 callers updated) - Migrate front\controls\ShopBasket → front\Controllers\ShopBasketController (camelCase, instance methods) - Add snake_case→camelCase action dispatch for new controllers in Site::route() - Update title()/page_title() to check front\Controllers\ before fallback - Remove cms\Layout class (replaced by $layoutsRepo->find()) - Add 8 tests for BasketCalculator (484 tests, 1528 assertions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
namespace Tests\Unit\Domain\Basket;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Domain\Basket\BasketCalculator;
|
|
|
|
class BasketCalculatorTest extends TestCase
|
|
{
|
|
public function testSummaryWpCalculatesTotal(): void
|
|
{
|
|
$basket = [
|
|
['wp' => 2, 'quantity' => 3],
|
|
['wp' => 5, 'quantity' => 1],
|
|
];
|
|
|
|
$this->assertSame(11, BasketCalculator::summaryWp($basket));
|
|
}
|
|
|
|
public function testSummaryWpReturnsZeroForEmptyBasket(): void
|
|
{
|
|
$this->assertSame(0, BasketCalculator::summaryWp([]));
|
|
$this->assertSame(0, BasketCalculator::summaryWp(null));
|
|
}
|
|
|
|
public function testCountProductsSumsQuantities(): void
|
|
{
|
|
$basket = [
|
|
['quantity' => 2],
|
|
['quantity' => 3],
|
|
['quantity' => 1],
|
|
];
|
|
|
|
$this->assertSame(6, BasketCalculator::countProducts($basket));
|
|
}
|
|
|
|
public function testCountProductsReturnsZeroForEmptyBasket(): void
|
|
{
|
|
$this->assertSame(0, BasketCalculator::countProducts([]));
|
|
$this->assertSame(0, BasketCalculator::countProducts(null));
|
|
}
|
|
|
|
public function testCountProductsTextSingular(): void
|
|
{
|
|
$this->assertSame('1 produkt', BasketCalculator::countProductsText(1));
|
|
}
|
|
|
|
public function testCountProductsTextPlural2to4(): void
|
|
{
|
|
$this->assertSame('2 produkty', BasketCalculator::countProductsText(2));
|
|
$this->assertSame('3 produkty', BasketCalculator::countProductsText(3));
|
|
$this->assertSame('4 produkty', BasketCalculator::countProductsText(4));
|
|
}
|
|
|
|
public function testCountProductsTextPlural5Plus(): void
|
|
{
|
|
$this->assertSame('0 produktów', BasketCalculator::countProductsText(0));
|
|
$this->assertSame('5 produktów', BasketCalculator::countProductsText(5));
|
|
$this->assertSame('12 produktów', BasketCalculator::countProductsText(12));
|
|
$this->assertSame('100 produktów', BasketCalculator::countProductsText(100));
|
|
}
|
|
|
|
public function testCountProductsTextCastsToInt(): void
|
|
{
|
|
$this->assertSame('3 produkty', BasketCalculator::countProductsText('3'));
|
|
$this->assertSame('0 produktów', BasketCalculator::countProductsText('abc'));
|
|
}
|
|
}
|