Files
FOSSBilling/tests-legacy/modules/Servicehosting/Api/GuestTest.php
T
Belle Aerni 0a156f4161 Fix CS automation (#3209)
* Restore needed gitignore

* Ran the fixes since they are far behind

* Fix for rector causing a problem. Re-ran.

* Update ServiceTest.php
2026-01-26 11:18:35 -08:00

71 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Box\Mod\Servicehosting\Api;
use PHPUnit\Framework\Attributes\Group;
#[Group('Core')]
final class GuestTest extends \BBTestCase
{
protected ?Guest $api;
public function setUp(): void
{
$this->api = new Guest();
}
public function testFreeTlds(): void
{
$di = $this->getDi();
$model = new \Model_Product();
$model->loadBean(new \DummyBean());
$model->type = \Model_Product::HOSTING;
$dbMock = $this->createMock('\Box_Database');
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->willReturn($model);
$di['db'] = $dbMock;
$serviceMock = $this->createMock(\Box\Mod\Servicehosting\Service::class);
$serviceMock->expects($this->atLeastOnce())
->method('getFreeTlds')
->with($model)
->willReturn([]);
$this->api->setService($serviceMock);
$this->api->setDi($di);
$result = $this->api->free_tlds(['product_id' => 1]);
$this->assertIsArray($result);
}
public function testFreeTldsProductTypeIsNotHosting(): void
{
$di = $this->getDi();
$model = new \Model_Product();
$model->loadBean(new \DummyBean());
$dbMock = $this->createMock('\Box_Database');
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->willReturn($model);
$validatorMock = $this->getMockBuilder(\FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$di['db'] = $dbMock;
$di['validator'] = $validatorMock;
$serviceMock = $this->createMock(\Box\Mod\Servicehosting\Service::class);
$serviceMock->expects($this->never())->method('getFreeTlds');
$this->api->setService($serviceMock);
$this->api->setDi($di);
$this->expectException(\FOSSBilling\Exception::class);
$this->expectExceptionMessage('Product type is invalid');
$this->api->free_tlds(['product_id' => 1]);
}
}