* @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 Exception; use OxidEsales\Eshop\Application\Model\User; 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 actionSetActiveFlagTest extends d3ActionIntegrationTestCase { public $sManagerId = 'managerTestId'; public $aUserIdList = [ 'userTestIdNo1', 'userTestIdNo2', 'userTestIdNo3', 'userTestIdNo4', ]; /** * @throws Exception */ public function createTestData() { $this->createManager($this->sManagerId); $this->createUser( $this->aUserIdList[0], [ 'oxactive' => '0', ] ); $this->createUser( $this->aUserIdList[1], [ 'oxactive' => '1', ] ); $this->createUser( $this->aUserIdList[2], [ 'oxactive' => '0', 'oxcompany' => __METHOD__, ] ); $this->createUser( $this->aUserIdList[3], [ 'oxactive' => '1', 'oxcompany' => __METHOD__, ] ); } /** * @throws DoctrineException */ public function cleanTestData() { $this->deleteManager($this->sManagerId); $this->deleteUser($this->aUserIdList[0]); $this->deleteUser($this->aUserIdList[1]); $this->deleteUser($this->aUserIdList[2]); $this->deleteUser($this->aUserIdList[3]); } /** * @return d3usermanager * @throws Exception */ public function getConfiguredManagerSetActive() { $oManager = $this->getManagerMock($this->sManagerId); $oManager->setValue('blActionCustActivate_status', true); $oManager->setValue('sActionCustActivateType', 'set'); $oManager->setValue('blItemExecute', true); return $oManager; } /** * @return d3usermanager * @throws Exception */ public function getConfiguredManagerUnsetActive() { $oManager = $this->getManagerMock($this->sManagerId); $oManager->setValue('blActionCustActivate_status', true); $oManager->setValue('sActionCustActivateType', 'notset'); $oManager->setValue('blItemExecute', true); return $oManager; } /** * @return ListModel * @throws Exception */ public function getFilledResultList() { return $this->getResultList([$this->aUserIdList[0], $this->aUserIdList[1]]); } /** * @test * @throws DatabaseConnectionException * @throws DatabaseErrorException * @throws StandardException * @throws d3ShopCompatibilityAdapterException * @throws d3_cfg_mod_exception * @throws Exception */ public function actionChangeConcernedUserSetActive() { // prevent save trigger action in test Registry::getSession()->setVariable(d3_user_usermanager::PREVENTION_SAVEUSER, true); $oExecute = $this->getExecuteMock($this->getConfiguredManagerSetActive()); $oExecute->startJobItemExecution(); Registry::getSession()->setVariable(d3_user_usermanager::PREVENTION_SAVEUSER, false); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[0]); $this->assertSame( 1, $oUser->getFieldData('oxactive') ); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[1]); $this->assertSame( 1, $oUser->getFieldData('oxactive') ); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[2]); $this->assertSame( 0, $oUser->getFieldData('oxactive') ); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[3]); $this->assertSame( 1, $oUser->getFieldData('oxactive') ); } /** * @test * @throws DatabaseConnectionException * @throws DatabaseErrorException * @throws StandardException * @throws d3ShopCompatibilityAdapterException * @throws d3_cfg_mod_exception * @throws Exception */ public function actionChangeConcernedUserUnsetActive() { // prevent save trigger action in test Registry::getSession()->setVariable(d3_user_usermanager::PREVENTION_SAVEUSER, true); $oExecute = $this->getExecuteMock($this->getConfiguredManagerUnsetActive()); $oExecute->startJobItemExecution(); Registry::getSession()->setVariable(d3_user_usermanager::PREVENTION_SAVEUSER, false); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[0]); $this->assertSame( 0, $oUser->getFieldData('oxactive') ); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[1]); $this->assertSame( 0, $oUser->getFieldData('oxactive') ); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[2]); $this->assertSame( 0, $oUser->getFieldData('oxactive') ); /** @var User $oUser */ $oUser = d3GetOxidDIC()->get('d3ox.usermanager.'.User::class); $oUser->load($this->aUserIdList[3]); $this->assertSame( 1, $oUser->getFieldData('oxactive') ); } }