162 regels
4.8 KiB
PHP
162 regels
4.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*
|
|
* https://www.d3data.de
|
|
*
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
* @link https://www.oxidmodule.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace D3\Usermanager\tests\integration\Actions;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
|
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
|
use D3\Usermanager\Application\Model\d3usermanager;
|
|
use D3\Usermanager\Modules\Application\Model\d3_user_usermanager;
|
|
use Doctrine\DBAL\Exception as DoctrineException;
|
|
use donatj\MockWebServer\MockWebServer;
|
|
use Exception;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
|
use OxidEsales\Eshop\Core\Model\ListModel;
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
class actionSendPushNotificationTest extends d3ActionIntegrationTestCase
|
|
{
|
|
public $sManagerId = 'managerTestId';
|
|
public $aUserIdList = [
|
|
'userTestIdNo1',
|
|
'userTestIdNo2',
|
|
];
|
|
|
|
public $sCurrentValue = 'CurrentCity';
|
|
public $sExpectedValue = 'TestCity';
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function createTestData()
|
|
{
|
|
$this->createManager($this->sManagerId);
|
|
|
|
$this->createUser(
|
|
$this->aUserIdList[0],
|
|
[
|
|
'oxcity' => $this->sCurrentValue,
|
|
]
|
|
);
|
|
|
|
$this->createUser(
|
|
$this->aUserIdList[1],
|
|
[
|
|
'oxcity' => $this->sCurrentValue,
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @throws DoctrineException
|
|
*/
|
|
public function cleanTestData()
|
|
{
|
|
$this->deleteManager($this->sManagerId);
|
|
$this->deleteUser($this->aUserIdList[0]);
|
|
$this->deleteUser($this->aUserIdList[1]);
|
|
}
|
|
|
|
/**
|
|
* @return d3usermanager
|
|
* @throws Exception
|
|
*/
|
|
public function getConfiguredManager($serverRoot)
|
|
{
|
|
$oManager = $this->getManagerMock($this->sManagerId);
|
|
|
|
$oManager->setValue('blActionUserSendPushNotification_status', true);
|
|
$oManager->setValue('sActionSendPushNotification_url', $serverRoot);
|
|
$oManager->setValue('sActionSendPushNotification_method', 'GET');
|
|
$oManager->setValue('blItemExecute', true);
|
|
|
|
return $oManager;
|
|
}
|
|
|
|
/**
|
|
* @return ListModel
|
|
* @throws Exception
|
|
*/
|
|
public function getFilledResultList()
|
|
{
|
|
return $this->getResultList([$this->aUserIdList[0]]);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @throws DatabaseConnectionException
|
|
* @throws DatabaseErrorException
|
|
* @throws StandardException
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
* @throws d3_cfg_mod_exception
|
|
* @throws Exception
|
|
*/
|
|
public function actionRequestSuccess()
|
|
{
|
|
// prevent save trigger action in test
|
|
Registry::getSession()->setVariable(d3_user_usermanager::PREVENTION_SAVEUSER, true);
|
|
|
|
$testServer = new MockWebServer(3456);
|
|
$oExecute = $this->getExecuteMock($this->getConfiguredManager($testServer->getServerRoot()));
|
|
|
|
try {
|
|
$testServer->start();
|
|
|
|
$oExecute->startJobItemExecution();
|
|
$this->assertMatchesRegularExpression( '@.*userTestIdNo1.*@', $testServer->getLastRequest()->getInput() );
|
|
} catch (Exception $e) {
|
|
throw $e;
|
|
} finally {
|
|
$testServer->stop();
|
|
Registry::getSession()->setVariable( d3_user_usermanager::PREVENTION_SAVEUSER, false );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @throws DatabaseConnectionException
|
|
* @throws DatabaseErrorException
|
|
* @throws StandardException
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
* @throws d3_cfg_mod_exception
|
|
* @throws Exception
|
|
*/
|
|
public function actionRequestFailed()
|
|
{
|
|
// prevent save trigger action in test
|
|
Registry::getSession()->setVariable(d3_user_usermanager::PREVENTION_SAVEUSER, true);
|
|
|
|
$testServer = new MockWebServer(3456);
|
|
$oExecute = $this->getExecuteMock($this->getConfiguredManager(str_replace('3456', '4567', $testServer->getServerRoot())));
|
|
|
|
try {
|
|
$testServer->start();
|
|
$this->expectException( GuzzleException::class );
|
|
|
|
$oExecute->startJobItemExecution();
|
|
} catch (Exception $e) {
|
|
throw $e;
|
|
} finally {
|
|
$testServer->stop();
|
|
Registry::getSession()->setVariable( d3_user_usermanager::PREVENTION_SAVEUSER, false );
|
|
}
|
|
}
|
|
}
|