diff --git a/src/Application/Model/MessageTypes/AbstractMessage.php b/src/Application/Model/MessageTypes/AbstractMessage.php index 4c496fb..06a96c8 100644 --- a/src/Application/Model/MessageTypes/AbstractMessage.php +++ b/src/Application/Model/MessageTypes/AbstractMessage.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Model\MessageTypes; -use D3\LinkmobilityClient\RecipientsList\RecipientsList; use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface; use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\ValueObject\Recipient; diff --git a/src/tests/integration/LMIntegrationTestCase.php b/src/tests/integration/LMIntegrationTestCase.php new file mode 100644 index 0000000..7a12402 --- /dev/null +++ b/src/tests/integration/LMIntegrationTestCase.php @@ -0,0 +1,84 @@ + + * @link http://www.oxidmodule.com + */ + +namespace D3\Linkmobility4OXID\tests\integration; + +use D3\Linkmobility4OXID\Application\Model\MessageClient; +use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase; +use D3\LinkmobilityClient\Client; +use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Query\QueryBuilder; +use GuzzleHttp\Client as GuzzleClient; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Handler\MockHandler; +use GuzzleHttp\HandlerStack; +use OxidEsales\Eshop\Application\Model\Remark; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use Psr\Http\Message\ResponseInterface; + +abstract class LMIntegrationTestCase extends LMUnitTestCase +{ + /** + * @param $userId + * + * @throws Exception + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function deleteAllRemarksFrom($userId) + { + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->delete(oxNew(Remark::class)->getCoreTableName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($userId) + ) + ); + $queryBuilder->execute(); + } + + /** + * @param ResponseInterface|RequestException $response + */ + protected function setClientResponse($response, callable $history = null) + { + $handlerMock = new MockHandler([$response]); + + $handlerStack = HandlerStack::create($handlerMock); + + if ($history) { + $handlerStack->push($history); + } + + $guzzleMock = new GuzzleClient(['handler' => $handlerStack]); + + /** @var Client $LMClient */ + $LMClient = oxNew(Client::class, 'accessToken', null, $guzzleMock); + + /** @var MessageClient|MockObject $messageClientMock */ + $messageClientMock = $this->getMockBuilder(MessageClient::class) + ->onlyMethods(['getClient']) + ->getMock(); + $messageClientMock->method('getClient')->willReturn($LMClient); + + d3GetOxidDIC()->set(MessageClient::class, $messageClientMock); + } +} \ No newline at end of file diff --git a/src/tests/integration/adminOrderTest.php b/src/tests/integration/adminOrderTest.php new file mode 100644 index 0000000..596d82d --- /dev/null +++ b/src/tests/integration/adminOrderTest.php @@ -0,0 +1,418 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4OXID\tests\integration; + +use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; +use D3\Linkmobility4OXID\Application\Model\Configuration; +use Doctrine\DBAL\Query\QueryBuilder; +use Exception; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Middleware; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; +use OxidEsales\Eshop\Application\Model\Order; +use OxidEsales\Eshop\Application\Model\Remark; +use OxidEsales\Eshop\Application\Model\User; +use OxidEsales\Eshop\Core\Registry; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Http\Message\RequestInterface; + +class adminOrderTest extends LMIntegrationTestCase +{ + /** @var Order */ + protected $order; + protected $userId = 'testUserId'; + protected $orderId = 'testOrderId'; + + public function setUp(): void + { + parent::setUp(); + + /** @var Configuration|MockObject $configuration */ + $configuration = $this->getMockBuilder(Configuration::class) + ->onlyMethods(['getTestMode']) + ->getMock(); + $configuration->method('getTestMode')->willReturn(true); + d3GetOxidDIC()->set(Configuration::class, $configuration); + + /** @var User $order */ + $this->order = $order = oxNew( Order::class); + $order->setId($this->orderId); + $order->assign([ + 'oxbillfon' => '01512 3456789', + 'oxbillcountryid' => 'a7c40f631fc920687.20179984', + 'oxuserid' => $this->userId + ]); + $order->save(); + + /** @var User $user */ + $this->user = $user = oxNew(User::class); + $user->setId($this->userId); + $user->save(); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function succSending() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + ['X-Foo' => 'Bar'], + '{"statusCode":2000,"statusMessage":"OK","clientMessageId":null,"transferId":"0063c11b0100eeda5a1d","smsCount":1}' + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->orderId; + + /** @var AdminOrder $controller */ + $controller = oxNew(AdminOrder::class); + $controller->send(); + + // check requests + $this->assertCount( + 1, + $container + ); + /** @var RequestInterface $request */ + $request = $container[0]['request']; + $this->assertTrue( + (bool) strpos(serialize($request->getBody()->getContents()), 'testMessage') + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), + 1 + ); + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) > 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function apiError() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + [], + '{"statusCode": 4019, "statusMessage": "parameter \"messageContent\" invalid", "clientMessageId": null, "transferId": null, "smsCount": 0}' + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->orderId; + + /** @var AdminOrder $controller */ + $controller = oxNew(AdminOrder::class); + $controller->send(); + + // check requests + $this->assertCount( + 1, + $container + ); + /** @var RequestInterface $request */ + $request = $container[0]['request']; + $this->assertTrue( + (bool) strpos(serialize($request->getBody()->getContents()), 'testMessage') + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), + 'parameter "messageContent" invalid' + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function emptyMessage() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + [], + '{"statusCode": 4019, "statusMessage": "parameter \"messageContent\" invalid", "clientMessageId": null, "transferId": null, "smsCount": 0}' + ), + $history + ); + + $_POST['messagebody'] = ''; + $_POST['oxid'] = $this->orderId; + + /** @var AdminOrder $controller */ + $controller = oxNew(AdminOrder::class); + $controller->send(); + + // check requests + $this->assertCount( + 0, // no request because of internal handling + $container + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH'), + 1 + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function recipientError() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + ['X-Foo' => 'Bar'], + '{"statusCode":2000,"statusMessage":"OK","clientMessageId":null,"transferId":"0063c11b0100eeda5a1d","smsCount":1}' + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->orderId; + + $this->order->assign( [ + 'oxbillfon' => '', + 'oxbillcountryid' => '' + ]); + $this->order->save(); + + /** @var AdminOrder $controller */ + $controller = oxNew(AdminOrder::class); + $controller->send(); + + // check requests + $this->assertCount( + 0, // no request because of internal handling + $container + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), + 'no response' + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function communicationError() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new RequestException( + 'Error Communicating with Server', + new Request('GET', 'test') + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->orderId; + + /** @var AdminOrder $controller */ + $controller = oxNew(AdminOrder::class); + $controller->send(); + + // check requests + $this->assertCount( + 1, + $container + ); + /** @var RequestInterface $request */ + $request = $container[0]['request']; + $this->assertTrue( + (bool) strpos(serialize($request->getBody()->getContents()), 'testMessage') + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), + 'no response' + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @throws Exception + */ + public function tearDown(): void + { + parent::tearDown(); + + $this->order->delete(); + $this->user->delete(); + } +} \ No newline at end of file diff --git a/src/tests/integration/adminUserTest.php b/src/tests/integration/adminUserTest.php new file mode 100644 index 0000000..4b7e64e --- /dev/null +++ b/src/tests/integration/adminUserTest.php @@ -0,0 +1,409 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4OXID\tests\integration; + +use D3\Linkmobility4OXID\Application\Model\Configuration; +use \D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; +use Doctrine\DBAL\Query\QueryBuilder; +use Exception; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Middleware; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; +use OxidEsales\Eshop\Application\Model\Remark; +use OxidEsales\Eshop\Application\Model\User; +use OxidEsales\Eshop\Core\Registry; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Http\Message\RequestInterface; + +class adminUserTest extends LMIntegrationTestCase +{ + /** @var User */ + protected $user; + protected $userId = 'testUserId'; + + public function setUp(): void + { + parent::setUp(); + + /** @var Configuration|MockObject $configuration */ + $configuration = $this->getMockBuilder(Configuration::class) + ->onlyMethods(['getTestMode']) + ->getMock(); + $configuration->method('getTestMode')->willReturn(true); + d3GetOxidDIC()->set(Configuration::class, $configuration); + + /** @var User $user */ + $this->user = $user = oxNew(User::class); + $user->setId($this->userId); + $user->assign([ + 'oxfon' => '01512 3456789', + 'oxcountryid' => 'a7c40f631fc920687.20179984' + ]); + $user->save(); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function succSending() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + ['X-Foo' => 'Bar'], + '{"statusCode":2000,"statusMessage":"OK","clientMessageId":null,"transferId":"0063c11b0100eeda5a1d","smsCount":1}' + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->userId; + + /** @var AdminUser $controller */ + $controller = oxNew(AdminUser::class); + $controller->send(); + + // check requests + $this->assertCount( + 1, + $container + ); + /** @var RequestInterface $request */ + $request = $container[0]['request']; + $this->assertTrue( + (bool) strpos(serialize($request->getBody()->getContents()), 'testMessage') + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), + 1 + ); + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) > 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function apiError() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + [], + '{"statusCode": 4019, "statusMessage": "parameter \"messageContent\" invalid", "clientMessageId": null, "transferId": null, "smsCount": 0}' + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->userId; + + /** @var AdminUser $controller */ + $controller = oxNew(AdminUser::class); + $controller->send(); + + // check requests + $this->assertCount( + 1, + $container + ); + /** @var RequestInterface $request */ + $request = $container[0]['request']; + $this->assertTrue( + (bool) strpos(serialize($request->getBody()->getContents()), 'testMessage') + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), + 'parameter "messageContent" invalid' + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function emptyMessage() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + [], + '{"statusCode": 4019, "statusMessage": "parameter \"messageContent\" invalid", "clientMessageId": null, "transferId": null, "smsCount": 0}' + ), + $history + ); + + $_POST['messagebody'] = ''; + $_POST['oxid'] = $this->userId; + + /** @var AdminUser $controller */ + $controller = oxNew(AdminUser::class); + $controller->send(); + + // check requests + $this->assertCount( + 0, // no request because of internal handling + $container + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH'), + 1 + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function recipientError() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new Response( + 200, + ['X-Foo' => 'Bar'], + '{"statusCode":2000,"statusMessage":"OK","clientMessageId":null,"transferId":"0063c11b0100eeda5a1d","smsCount":1}' + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->userId; + + $this->user->assign([ + 'oxfon' => '', + 'oxcountryid' => '' + ]); + $this->user->save(); + + /** @var AdminUser $controller */ + $controller = oxNew(AdminUser::class); + $controller->send(); + + // check requests + $this->assertCount( + 0, // no request because of internal handling + $container + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), + 'no response' + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @test + * @throws \Doctrine\DBAL\Exception + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function communicationError() + { + $container = []; + $history = Middleware::history($container); + + $this->deleteAllRemarksFrom($this->userId); + + $this->setClientResponse( + new RequestException( + 'Error Communicating with Server', + new Request('GET', 'test') + ), + $history + ); + + $_POST['messagebody'] = 'testMessage'; + $_POST['oxid'] = $this->userId; + + /** @var AdminUser $controller */ + $controller = oxNew(AdminUser::class); + $controller->send(); + + // check requests + $this->assertCount( + 1, + $container + ); + /** @var RequestInterface $request */ + $request = $container[0]['request']; + $this->assertTrue( + (bool) strpos(serialize($request->getBody()->getContents()), 'testMessage') + ); + + // check return message + $search = sprintf( + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), + 'no response' + ); + + $this->assertTrue( + (bool) strpos(serialize(Registry::getSession()->getVariable('Errors')), $search) + ); + + // check remark + /** @var QueryBuilder $queryBuilder */ + $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $queryBuilder->select('oxid') + ->from(oxNew(Remark::class)->getViewName()) + ->where( + $queryBuilder->expr()->eq( + 'oxparentid', + $queryBuilder->createNamedParameter($this->userId) + ) + ); + $remarkIds = $queryBuilder->execute()->fetchAll(); + $this->assertTrue( + count($remarkIds) == 0 + ); + + $this->deleteAllRemarksFrom($this->userId); + } + + /** + * @throws Exception + */ + public function tearDown(): void + { + parent::tearDown(); + + $this->user->delete(); + } +} \ No newline at end of file