Files
FOSSBilling/tests/modules/Servicehosting/Api/GuestTest.php
T
Belle Aerni 32d011225b Rector & PHP-CS-Fixer Improvements (#2047)
* Added the rector cache to the action

* Enabled PHP-CS fixer for the tests & library folder

* Use the PHP-CS-Fixer Cache

* Fix the tests

* Ensure the Sentry placeholder isn't messed up from CS changes

* Typo..
2024-01-08 00:10:00 +00:00

78 lines
2.5 KiB
PHP

<?php
namespace Box\Mod\Servicehosting\Api;
class GuestTest extends \BBTestCase
{
/**
* @var Guest
*/
protected $api;
public function setup(): void
{
$this->api = new Guest();
}
public function testfreeTlds()
{
$di = new \Pimple\Container();
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->willReturn(null);
$di['validator'] = $validatorMock;
$model = new \Model_Product();
$model->loadBean(new \DummyBean());
$model->type = \Model_Product::HOSTING;
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->willReturn($model);
$di['db'] = $dbMock;
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Servicehosting\Service::class)->getMock();
$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()
{
$di = new \Pimple\Container();
$validatorMock = $this->getMockBuilder('\\' . \FOSSBilling\Validate::class)->disableOriginalConstructor()->getMock();
$validatorMock->expects($this->atLeastOnce())
->method('checkRequiredParamsForArray')
->willReturn(null);
$di['validator'] = $validatorMock;
$model = new \Model_Product();
$model->loadBean(new \DummyBean());
$dbMock = $this->getMockBuilder('\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())
->method('getExistingModelById')
->willReturn($model);
$di['db'] = $dbMock;
$serviceMock = $this->getMockBuilder('\\' . \Box\Mod\Servicehosting\Service::class)->getMock();
$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]);
}
}