Files
FOSSBilling/tests-legacy/library/Model/ProductDomainTableTest.php
T
b2f4cb8ffa Enhance API rate limiting, validation, and subscription features (#3459)
* Validate redirect paths and targets

* Sanitize guest client data and misc cleanups

* Implement API rate limiting and pruning

* Bump `last_patch` setting to 54

* Add tests for `shouldUseTokenLogin` logic

Add tests to cover logic added in #3451.

* Add order/renewal line config for domain pricing

Resolves #2793.

* Add PayPalEmail adapter subscription test

* Add width/height styling for textarea fields

Resolves #2448.

* Send invoice-created email on approve

Resolves #3012.

* Enforce cumulative cart stock and stockSale

Resolves #3130.

* Centralize subscription period retrieval

Resolves #1035.

* Support wildcard staff permissions (default.all)

Resolves #2376.

* Enable quantity selection and enforce stock max

Resolves #2573.

* Extend order expiry on first paid invoice

Resolves #2864.

* Rate-limit request prefix; invoice & promo fixes

* Update src/modules/Redirect/templates/admin/mod_redirect_settings.html.twig

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Api/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Client/Controller/Client.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/modules/Cron/Service.php

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix quantity not passed to getOrderLineConfig in createOrder

Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/669f845c-50c4-4f7e-95cd-f44de162ad72

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Simplify quantity injection into getOrderLineConfig call

Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/669f845c-50c4-4f7e-95cd-f44de162ad72

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix rate limit prefix isolation, whitelist headers, and staff controller prefix

Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/11f3fd58-bb44-46a5-a6cf-0992b038f4a7

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Enforce promo usage limit and add test

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
2026-04-28 22:11:39 +01:00

111 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\Group;
#[Group('Core')]
final class ProductDomainTableTest extends BBTestCase
{
private ?Model_ProductDomainTable $table = null;
protected function setUp(): void
{
$this->table = new Model_ProductDomainTable();
}
public function testGetOrderLineConfigUsesRegistrationAndRenewalPricing(): void
{
$tld = new Model_Tld();
$tld->loadBean(new DummyBean());
$tld->tld = '.com';
$tld->price_registration = 13;
$tld->price_renew = 20;
$tld->price_transfer = 15;
$tldService = $this->getMockBuilder(\Box\Mod\Servicedomain\ServiceTld::class)
->disableOriginalConstructor()
->onlyMethods(['findOneByTld'])
->getMock();
$tldService->expects($this->atLeastOnce())
->method('findOneByTld')
->with('.com')
->willReturn($tld);
$di = $this->getDi();
$di['period'] = $di->protect(fn (string $period): Box_Period => new Box_Period($period));
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $tldService);
$this->table->setDi($di);
$product = new Model_Product();
$product->loadBean(new DummyBean());
$line = $this->table->getOrderLineConfig($product, [
'action' => 'register',
'register_tld' => '.com',
'register_years' => 2,
'period' => '2Y',
]);
$renewal = $this->table->getRenewalLineConfig($product, [
'action' => 'register',
'register_tld' => '.com',
'register_years' => 2,
'period' => '2Y',
]);
$this->assertSame(['price' => 33.0, 'quantity' => 1, 'setup_price' => 0.0], $line);
$this->assertSame(['price' => 20.0, 'quantity' => 2], $renewal);
}
public function testGetRelatedDiscountUsesRenewalPricingForFreeMultiYearDomain(): void
{
$tld = new Model_Tld();
$tld->loadBean(new DummyBean());
$tld->tld = '.com';
$tld->price_registration = 13;
$tld->price_renew = 20;
$tld->price_transfer = 15;
$tldService = $this->getMockBuilder(\Box\Mod\Servicedomain\ServiceTld::class)
->disableOriginalConstructor()
->onlyMethods(['findOneByTld'])
->getMock();
$tldService->expects($this->once())
->method('findOneByTld')
->with('.com')
->willReturn($tld);
$di = $this->getDi();
$di['period'] = $di->protect(fn (string $period): Box_Period => new Box_Period($period));
$di['mod_service'] = $di->protect(fn (): \PHPUnit\Framework\MockObject\MockObject => $tldService);
$this->table->setDi($di);
$product = new Model_Product();
$product->loadBean(new DummyBean());
$discount = $this->table->getRelatedDiscount([
[
'config' => [
'action' => 'register',
'domain' => [
'action' => 'register',
'register_sld' => 'example',
'register_tld' => '.com',
],
'free_domain' => true,
'free_domain_periods' => ['2Y'],
'period' => '2Y',
],
],
], $product, [
'action' => 'register',
'register_sld' => 'example',
'register_tld' => '.com',
'period' => '2Y',
]);
$this->assertSame(33.0, $discount);
}
}