- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation. - Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing. - Add ShopProductPageTest to verify shop product listings, search functionality, and product page details. - Introduce BuildsShop trait for seeding test data related to shop functionality. - Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace Tests\Unit;
|
||
|
||
use App\Domain\Catalog\DomainRuleException;
|
||
use App\Domain\Commerce\Money;
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
class MoneyTest extends TestCase
|
||
{
|
||
public function test_euro_input_is_parsed_to_cents(): void
|
||
{
|
||
$this->assertSame(4900, Money::parse('49'));
|
||
$this->assertSame(4900, Money::parse('49,00'));
|
||
$this->assertSame(1250, Money::parse('12,50'));
|
||
$this->assertSame(1250, Money::parse('12.50'));
|
||
$this->assertSame(129900, Money::parse('1.299'));
|
||
$this->assertSame(129950, Money::parse('1.299,5'));
|
||
$this->assertSame(500, Money::parse(' 5 € '));
|
||
$this->assertSame(0, Money::parse('0'));
|
||
$this->assertSame(Money::MAX_CENTS, Money::parse('1.000.000'));
|
||
$this->assertNull(Money::parse(''));
|
||
$this->assertNull(Money::parse(null));
|
||
}
|
||
|
||
public function test_an_invalid_amount_is_rejected(): void
|
||
{
|
||
foreach (['zwölf', '12,555', '-5', '1,2,3', '1.000.001', '99999999999'] as $input) {
|
||
try {
|
||
Money::parse($input);
|
||
$this->fail('Eingabe ohne Fehler angenommen: '.$input);
|
||
} catch (DomainRuleException) {
|
||
$this->addToAssertionCount(1);
|
||
}
|
||
}
|
||
}
|
||
|
||
public function test_cents_are_formatted_in_german_euro(): void
|
||
{
|
||
$this->assertSame('49,00 €', Money::format(4900));
|
||
$this->assertSame('1.299,50 €', Money::format(129950));
|
||
$this->assertSame('0,05 €', Money::format(5));
|
||
$this->assertSame('–', Money::format(null));
|
||
}
|
||
}
|