| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace App\Test\Service\Typo3;
- use App\Service\Typo3\Typo3Service;
- use PHPUnit\Framework\TestCase;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class TestableTypo3Service extends Typo3Service {
- public function sendCommand(string $route, array $parameters): ResponseInterface { return parent::sendCommand($route, $parameters); }
- }
- class Typo3ServiceTest extends TestCase
- {
- private HttpClientInterface $typo3Client;
- public function setUp(): void {
- $this->typo3Client = $this->getMockBuilder(HttpClientInterface::class)->disableOriginalConstructor()->getMock();
- }
- public function testSendCommand(): void
- {
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $this->typo3Client
- ->expects(self::once())
- ->method('request')
- ->with('GET', '/typo3/index.php?route=foo¶m=bar')
- ->willReturn($response);
- $typo3Service = new TestableTypo3Service($this->typo3Client);
- $typo3Service->sendCommand('foo', ['param' => 'bar']);
- }
- public function testCreateSite() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/create', ['organization-id' => 1])
- ->willReturn($response);
- $typo3Service->createSite(1);
- }
- public function testClearSiteCache() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/update', ['organization-id' => 1])
- ->willReturn($response);
- $typo3Service->updateSite(1);
- }
- public function testDeleteSite() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/delete', ['organization-id' => 1])
- ->willReturn($response);
- $typo3Service->deleteSite(1);
- }
- public function testUndeleteSite() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/undelete', ['organization-id' => 1])
- ->willReturn($response);
- $typo3Service->undeleteSite(1);
- }
- public function testSetSiteDomain() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/set-domain', ['organization-id' => 1, 'domain' => 'new-domain'])
- ->willReturn($response);
- $typo3Service->setSiteDomain(1, 'new-domain', false);
- }
- public function testSetSiteDomainWithRedirection() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/set-domain', ['organization-id' => 1, 'domain' => 'new-domain', 'redirect' => 1])
- ->willReturn($response);
- $typo3Service->setSiteDomain(1, 'new-domain', true);
- }
- public function testResetSitePerms() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/reset-perms', ['organization-id' => 1])
- ->willReturn($response);
- $typo3Service->resetSitePerms(1);
- }
- public function testGetSiteStatus() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/site/status', ['organization-id' => 1])
- ->willReturn($response);
- $typo3Service->getSiteStatus(1);
- }
- public function testAddRedirection() {
- $typo3Service = $this->getMockBuilder(Typo3Service::class)
- ->onlyMethods(['sendCommand'])
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->disableOriginalConstructor()->getMock();
- $typo3Service->expects(self::once())
- ->method('sendCommand')->
- with('/otadmin/redirect/add', ['from-domain' => 'foo', 'to-domain' => 'bar'])
- ->willReturn($response);
- $typo3Service->addRedirection('foo', 'bar');
- }
- }
|