First upload
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop GDPR opt-in module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\GdprOptinModule\Tests\Integration;
|
||||
|
||||
/**
|
||||
* Class ContactControllerTest
|
||||
*
|
||||
* @package OxidEsales\GdprOptinModule\Tests\Integration
|
||||
*/
|
||||
class ContactControllerTest extends \OxidEsales\TestingLibrary\UnitTestCase
|
||||
{
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider dataProviderOptInValidationRequired
|
||||
*/
|
||||
public function testOptInValidationRequired($configValue, $expected)
|
||||
{
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam('OeGdprOptinContactFormMethod', $configValue);
|
||||
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ContactController::class);
|
||||
$this->assertSame($expected, $controller->isOptInValidationRequired());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderOptInValidationRequired()
|
||||
{
|
||||
return [
|
||||
'formMethod-deletion' => ['deletion', false],
|
||||
'formMethod-statistical' => ['statistical', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validation error appears if needed
|
||||
*/
|
||||
public function testSendError()
|
||||
{
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam('OeGdprOptinContactFormMethod', "statistical");
|
||||
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ContactController::class);
|
||||
$this->assertFalse($controller->isOptInError());
|
||||
$this->assertFalse($controller->send());
|
||||
$this->assertTrue($controller->isOptInError());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop GDPR opt-in module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\GdprOptinModule\Tests\Integration;
|
||||
|
||||
use OxidEsales\Eshop\Application\Component\BasketComponent;
|
||||
use OxidEsales\Eshop\Application\Component\Widget\ArticleDetails;
|
||||
use OxidEsales\Eshop\Application\Controller\AccountUserController;
|
||||
use OxidEsales\Eshop\Application\Controller\ContactController;
|
||||
use OxidEsales\Eshop\Application\Controller\RegisterController;
|
||||
use OxidEsales\Eshop\Application\Controller\UserController;
|
||||
use OxidEsales\Eshop\Application\Model\Article;
|
||||
use OxidEsales\Eshop\Application\Model\Basket;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
use OxidEsales\Eshop\Core\Field;
|
||||
use OxidEsales\Eshop\Core\Output;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use OxidEsales\TestingLibrary\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Class FrontendTest
|
||||
*
|
||||
* @package OxidEsales\GdprOptinModule\Tests\Integration
|
||||
*/
|
||||
class FrontendTest extends UnitTestCase
|
||||
{
|
||||
const TEST_USER_ID = '_gdprtest';
|
||||
|
||||
const TEST_ARTICLE_OXID = '_gdpr_test_product';
|
||||
|
||||
/**
|
||||
* Test product.
|
||||
*
|
||||
* @var Article
|
||||
*/
|
||||
private $product =null;
|
||||
|
||||
/**
|
||||
* Test set up.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->replaceBlocks();
|
||||
|
||||
$this->createTestUser();
|
||||
$this->createTestProduct();
|
||||
$this->createBasket();
|
||||
Registry::get(UtilsView::class)->getSmarty(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanUpTable('oxuser', 'oxid');
|
||||
$this->cleanUpTable('oxarticles', 'oxid');
|
||||
$this->cleanUpTable('oxtplblocks', 'oxid');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerDeliveryAddressOptin()
|
||||
{
|
||||
return [
|
||||
'enable_optin_true_flow' => [true, 'doAssertStringContainsString', 'flow'],
|
||||
'enable_optin_false_flow' => [false, 'doAssertStringNotContainsString', 'flow']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox visibility.
|
||||
*
|
||||
* @dataProvider providerDeliveryAddressOptin
|
||||
*
|
||||
* @param bool $reqireOptinDeliveryAddress
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
*/
|
||||
public function testDeliveryAddressOptinForCheckout($reqireOptinDeliveryAddress, $assertMethod, $theme)
|
||||
{
|
||||
Registry::getSession()->setVariable('blshowshipaddress', true);
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinDeliveryAddress', $reqireOptinDeliveryAddress);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
|
||||
$content = $this->getTemplateOutput(UserController::class, 'form/user_checkout_change.tpl');
|
||||
|
||||
$this->$assertMethod('id="oegdproptin_deliveryaddress"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox visibility.
|
||||
*
|
||||
* @dataProvider providerDeliveryAddressOptin
|
||||
*
|
||||
* @param bool $reqireOptinDeliveryAddress
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
*/
|
||||
public function testDeliveryAddressOptinForUserAccount($reqireOptinDeliveryAddress, $assertMethod, $theme)
|
||||
{
|
||||
Registry::getSession()->setVariable('blshowshipaddress', true);
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinDeliveryAddress', $reqireOptinDeliveryAddress);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
|
||||
$content = $this->getTemplateOutput(AccountUserController::class, 'form/user.tpl');
|
||||
|
||||
$this->$assertMethod('id="oegdproptin_deliveryaddress"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerInvoiceAddressOptin()
|
||||
{
|
||||
return [
|
||||
'enable_optin_true_flow' => [true, 'doAssertStringContainsString', 'flow'],
|
||||
'enable_optin_false_flow' => [false, 'doAssertStringNotContainsString', 'flow']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox visibility.
|
||||
*
|
||||
* @dataProvider providerInvoiceAddressOptin
|
||||
*
|
||||
* @param bool $reqireOptinInvoiceAddress
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
*/
|
||||
public function testInvoiceAddressOptinForCheckout($reqireOptinInvoiceAddress, $assertMethod, $theme)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinInvoiceAddress', $reqireOptinInvoiceAddress);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
|
||||
$content = $this->getTemplateOutput(UserController::class, 'form/user_checkout_change.tpl');
|
||||
|
||||
$this->$assertMethod('id="oegdproptin_invoiceaddress"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox visibility.
|
||||
*
|
||||
* @dataProvider providerInvoiceAddressOptin
|
||||
*
|
||||
* @param bool $reqireOptinInvoiceAddress
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
*/
|
||||
public function testInvoiceAddressOptinForUserAccount($reqireOptinInvoiceAddress, $assertMethod, $theme)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinInvoiceAddress', $reqireOptinInvoiceAddress);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
|
||||
$content = $this->getTemplateOutput(AccountUserController::class, 'form/user.tpl');
|
||||
|
||||
$this->$assertMethod('id="oegdproptin_invoiceaddress"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerUserRegistrationOptin()
|
||||
{
|
||||
return [
|
||||
'enable_optin_true_flow' => [true, 'doAssertStringContainsString', 'flow'],
|
||||
'enable_optin_false_flow' => [false, 'doAssertStringNotContainsString', 'flow']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox visibility.
|
||||
* NOTE: user must not be logged in here. Need to simulate user registration.
|
||||
*
|
||||
* @dataProvider providerUserRegistrationOptin
|
||||
*
|
||||
* @param bool $blOeGdprOptinUserRegistration
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
*/
|
||||
public function testUserRegistrationOptin($blOeGdprOptinUserRegistration, $assertMethod, $theme)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinUserRegistration', $blOeGdprOptinUserRegistration);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
Registry::getSession()->setUser(null);
|
||||
|
||||
$addViewData = [];
|
||||
$addViewData['oxcmp_basket'] = oxNew(Basket::class);
|
||||
$addViewData['oConfig'] = Registry::getConfig();
|
||||
$addViewData['sidebar'] = '';
|
||||
|
||||
$content = $this->getTemplateOutput(RegisterController::class, 'page/account/register.tpl', $addViewData);
|
||||
$this->$assertMethod('id="oegdproptin_userregistration"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerUserCheckoutRegistrationOptin()
|
||||
{
|
||||
return [
|
||||
'enable_optin_true_flow_noreg' => [true, 'doAssertStringNotContainsString', 'flow', 1],
|
||||
'enable_optin_false_flow_noreg' => [false, 'doAssertStringNotContainsString', 'flow', 1],
|
||||
'enable_optin_true_flow_reg' => [true, 'doAssertStringContainsString', 'flow', 3],
|
||||
'enable_optin_false_flow_reg' => [false, 'doAssertStringNotContainsString', 'flow', 3]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox visibility during registration.
|
||||
* NOTE: user must not be logged in here. Need to simulate user registration.
|
||||
*
|
||||
* @dataProvider providerUserCheckoutRegistrationOptin
|
||||
*
|
||||
* @param bool $blOeGdprOptinUserRegistration
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
* @param int $option
|
||||
*/
|
||||
public function testUserRegistrationOptinDuringCheckout($blOeGdprOptinUserRegistration, $assertMethod, $theme, $option)
|
||||
{
|
||||
$this->setRequestParameter('option', $option);
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinUserRegistration', $blOeGdprOptinUserRegistration);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
Registry::getSession()->setUser(null);
|
||||
|
||||
$addViewData = [];
|
||||
$addViewData['oxcmp_basket'] = oxNew(Basket::class);
|
||||
$addViewData['oConfig'] = Registry::getConfig();
|
||||
$addViewData['sidebar'] = '';
|
||||
|
||||
$content = $this->getTemplateOutput(UserController::class, 'page/checkout/user.tpl', $addViewData);
|
||||
|
||||
$this->$assertMethod('id="oegdproptin_userregistration"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test contact form deletion optin
|
||||
*/
|
||||
public function testContactFormDeletionOptIn()
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('OeGdprOptinContactFormMethod', 'deletion');
|
||||
Registry::getConfig()->setConfigParam('sTheme', 'flow');
|
||||
$expected = Registry::getLang()->translateString("OEGDPROPTIN_CONTACT_FORM_MESSAGE_DELETION");
|
||||
|
||||
$content = $this->getTemplateOutput(ContactController::class, 'form/contact.tpl');
|
||||
|
||||
$this->doAssertStringContainsString($expected, $content);
|
||||
$this->doAssertStringNotContainsString('name="c_oegdproptin"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test contact form statistical optin
|
||||
*/
|
||||
public function testContactFormStatisticalOptIn()
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('OeGdprOptinContactFormMethod', 'statistical');
|
||||
Registry::getConfig()->setConfigParam('sTheme', 'flow');
|
||||
$expected = Registry::getLang()->translateString("OEGDPROPTIN_CONTACT_FORM_MESSAGE_STATISTICAL");
|
||||
|
||||
$content = $this->getTemplateOutput(ContactController::class, 'form/contact.tpl');
|
||||
|
||||
$this->doAssertStringContainsString($expected, $content);
|
||||
$this->doAssertStringContainsString('name="c_oegdproptin"', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates filled basket object and stores it in session.
|
||||
*/
|
||||
private function createBasket()
|
||||
{
|
||||
Registry::getSession()->getBasket();
|
||||
$this->assertNull(Registry::getSession()->getVariable('_newitem'));
|
||||
|
||||
$basketComponent = oxNew(BasketComponent::class);
|
||||
$basketComponent->toBasket(self::TEST_ARTICLE_OXID, 1);
|
||||
$basket = $basketComponent->render();
|
||||
$this->assertEquals(1, $basket->getProductsCount());
|
||||
|
||||
Registry::getSession()->setBasket($basket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test product.
|
||||
*/
|
||||
private function createTestProduct()
|
||||
{
|
||||
$product = oxNew(Article::class);
|
||||
$product->setId(self::TEST_ARTICLE_OXID);
|
||||
$product->oxarticles__oxshopid = new Field(1);
|
||||
$product->oxarticles__oxtitle = new Field(self::TEST_ARTICLE_OXID);
|
||||
$product->oxarticles__oxprice = new Field(6.66);
|
||||
$product->save();
|
||||
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test user.
|
||||
*/
|
||||
private function createTestUser()
|
||||
{
|
||||
$user = oxNew(User::class);
|
||||
$user->setId(self::TEST_USER_ID);
|
||||
$user->assign(
|
||||
[
|
||||
'oxfname' => 'Max',
|
||||
'oxlname' => 'Mustermann',
|
||||
'oxusername' => 'gdpruser@oxid.de',
|
||||
'oxpassword' => md5('agent'),
|
||||
'oxactive' => 1,
|
||||
'oxshopid' => 1,
|
||||
'oxcountryid' => 'a7c40f631fc920687.20179984',
|
||||
'oxboni' => '600',
|
||||
'oxstreet' => 'Teststreet',
|
||||
'oxstreetnr' => '101',
|
||||
'oxcity' => 'Hamburg',
|
||||
'oxzip' => '22769'
|
||||
]
|
||||
);
|
||||
$user->save();
|
||||
|
||||
//Ensure we have it in session and as active user
|
||||
$this->ensureActiveUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we have the test user as active user.
|
||||
*/
|
||||
private function ensureActiveUser()
|
||||
{
|
||||
$this->setSessionParam('usr', self::TEST_USER_ID);
|
||||
$this->setSessionParam('auth', self::TEST_USER_ID);
|
||||
|
||||
$user = oxNew(User::class);
|
||||
$user->load(self::TEST_USER_ID);
|
||||
Registry::getSession()->setUser($user);
|
||||
$user->setUser($user);
|
||||
$this->assertTrue($user->loadActiveUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test helper to replace header and footer as they are not needed for our tests.
|
||||
*/
|
||||
private function replaceBlocks()
|
||||
{
|
||||
$shopId = Registry::getConfig()->getShopId();
|
||||
$query = "INSERT INTO oxtplblocks (OXID, OXACTIVE, OXSHOPID, OXTEMPLATE, OXBLOCKNAME, OXPOS, OXFILE, OXMODULE) VALUES " .
|
||||
"('_test_header', 1, '{$shopId}', 'layout/page.tpl', 'layout_header', 1, 'Tests/Integration/views/blocks/empty.tpl', 'oegdproptin'), " .
|
||||
"('_test_footer', 1, '{$shopId}', 'layout/footer.tpl', 'footer_main', 1, 'Tests/Integration/views/blocks/empty.tpl', 'oegdproptin'), " .
|
||||
"('_test_sidebar', 1, '{$shopId}', 'layout/sidebar.tpl', 'sidebar', 1, 'Tests/Integration/views/blocks/empty.tpl', 'oegdproptin'), " .
|
||||
"('_test_sgvo_icons', 1, '{$shopId}', 'layout/base.tpl', 'theme_svg_icons', 1, 'Tests/Integration/views/blocks/empty.tpl', 'oegdproptin'), " .
|
||||
"('_test_listitem', 1, '{$shopId}', 'page/review/review.tpl', 'widget_product_listitem_line_picturebox', 1, 'Tests/Integration/views/blocks/empty.tpl', 'oegdproptin')";
|
||||
|
||||
DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerContactForm()
|
||||
{
|
||||
return [
|
||||
'flow' => ['flow']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerDetailsReviewOptin()
|
||||
{
|
||||
return [
|
||||
'enable_optin_true_flow_art' => [true, 'doAssertStringContainsString', 'flow', 'oxwArticleDetails'],
|
||||
'enable_optin_false_flow_art' => [false, 'doAssertStringNotContainsString', 'flow', 'oxwArticleDetails']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test review form optin visibility.
|
||||
*
|
||||
* @dataProvider providerDetailsReviewOptin
|
||||
*
|
||||
* @param bool $blOeGdprOptinProductReviews
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
* @param string $class
|
||||
*/
|
||||
public function testDetailsReviewFormOptIn($blOeGdprOptinProductReviews, $assertMethod, $theme, $class)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinProductReviews', $blOeGdprOptinProductReviews);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
|
||||
$content = $this->getTemplateOutput($class, 'widget/reviews/reviews.tpl', null, true);
|
||||
|
||||
$this->$assertMethod('id="rvw_oegdproptin"', $content);
|
||||
|
||||
//Error message always present in DOM, if checkbox present, but is hidden by default
|
||||
$message = Registry::getLang()->translateString("OEGDPROPTIN_REVIEW_FORM_ERROR_MESSAGE");
|
||||
$this->$assertMethod($message, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerOxwArticleDetailsReviewOptinError()
|
||||
{
|
||||
return [
|
||||
'enable_optin_true_flow_art' => [true, 'doAssertStringContainsString', 'flow', 1],
|
||||
'enable_optin_false_flow_art' => [false, 'doAssertStringNotContainsString', 'flow', 0]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test review form optin error message visibility.
|
||||
*
|
||||
* @dataProvider providerOxwArticleDetailsReviewOptinError
|
||||
*
|
||||
* @param bool $blOeGdprOptinProductReviews
|
||||
* @param string $assertMethod
|
||||
* @param string $theme
|
||||
* @param int $count
|
||||
*/
|
||||
public function testOxwArticleDetailsReviewFormOptInError($blOeGdprOptinProductReviews, $assertMethod, $theme, $count)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinProductReviews', $blOeGdprOptinProductReviews);
|
||||
Registry::getConfig()->setConfigParam('sTheme', $theme);
|
||||
|
||||
$controller = $this->getMock(ArticleDetails::class, ['isReviewOptInError']);
|
||||
$controller->expects($this->exactly($count))->method('isReviewOptInError')->will($this->returnValue(true));
|
||||
$controller->init();
|
||||
$controller->setViewProduct($this->product);
|
||||
|
||||
$content = $this->doRender($controller, 'widget/reviews/reviews.tpl');
|
||||
|
||||
$expected = Registry::getLang()->translateString("OEGDPROPTIN_REVIEW_FORM_ERROR_MESSAGE");
|
||||
$this->$assertMethod($expected, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $controllerName
|
||||
* @param string $template
|
||||
* @param null $addViewData
|
||||
* @param bool $setProduct Set true to add test product to view (needed for review tests)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateOutput($controllerName, $template, $addViewData = null, $setProduct = false)
|
||||
{
|
||||
$controller = oxNew($controllerName);
|
||||
$controller->init();
|
||||
|
||||
if ($setProduct) {
|
||||
$controller->setViewProduct($this->product);
|
||||
}
|
||||
|
||||
return $this->doRender($controller, $template, $addViewData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test helper to render output.
|
||||
*
|
||||
* @param object $controller
|
||||
* @param string $template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function doRender($controller, $template, $addViewData = null)
|
||||
{
|
||||
//prepare output
|
||||
$output = oxNew(Output::class);
|
||||
$viewData = $output->processViewArray($controller->getViewData(), $controller->getClassName());
|
||||
if (is_array($addViewData)) {
|
||||
$viewData = array_merge($viewData, $addViewData);
|
||||
} else {
|
||||
$viewData['oxcmp_user'] = Registry::getSession()->getUser();
|
||||
$viewData['oxcmp_basket'] = Registry::getSession()->getBasket();
|
||||
$viewData['oConfig'] = Registry::getConfig();
|
||||
}
|
||||
|
||||
$controller->setViewData($viewData);
|
||||
return Registry::get(UtilsView::class)->getTemplateOutput($template, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $needle
|
||||
* @param string $haystack
|
||||
* @param string $message
|
||||
*/
|
||||
protected function doAssertStringContainsString($needle, $haystack, $message = '')
|
||||
{
|
||||
if (method_exists($this, 'assertStringContainsString')) {
|
||||
parent::assertStringContainsString($needle, $haystack, $message);
|
||||
} else {
|
||||
parent::assertContains($needle, $haystack, $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $needle
|
||||
* @param string $haystack
|
||||
* @param string $message
|
||||
*/
|
||||
protected function doAssertStringNotContainsString($needle, $haystack, $message = '')
|
||||
{
|
||||
if (method_exists($this, 'assertStringNotContainsString')) {
|
||||
parent::assertStringNotContainsString($needle, $haystack, $message);
|
||||
} else {
|
||||
parent::assertNotContains($needle, $haystack, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop GDPR opt-in module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\GdprOptinModule\Tests\Integration;
|
||||
|
||||
use OxidEsales\GdprOptinModule\Controller\ReviewController;
|
||||
|
||||
/**
|
||||
* Class ReviewControllerTest
|
||||
*
|
||||
* @package OxidEsales\GdprOptinModule\Tests\Integration
|
||||
*/
|
||||
class ReviewControllerTest extends \OxidEsales\TestingLibrary\UnitTestCase
|
||||
{
|
||||
/**
|
||||
* Test validation error appears if needed
|
||||
*/
|
||||
public function testSendError()
|
||||
{
|
||||
/** @var ReviewController $controller */
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ReviewController::class);
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam($controller::REVIEW_OPTIN_PARAM, true);
|
||||
$this->assertFalse($controller->saveReview());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validation error appears if needed
|
||||
*/
|
||||
public function testSendNotError()
|
||||
{
|
||||
/** @var ReviewController $controller */
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ReviewController::class);
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam($controller::REVIEW_OPTIN_PARAM, false);
|
||||
$this->assertNull($controller->saveReview());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if validation is required.
|
||||
*
|
||||
* @dataProvider dataProviderReviewOptInValidationRequired
|
||||
*/
|
||||
public function testReviewOptInValidationRequired($configValue, $expected)
|
||||
{
|
||||
/** @var ReviewController $controller */
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ReviewController::class);
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam($controller::REVIEW_OPTIN_PARAM, $configValue);
|
||||
$this->assertSame($expected, $controller->isReviewOptInValidationRequired());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderReviewOptInValidationRequired()
|
||||
{
|
||||
return [
|
||||
'required' => [true, true],
|
||||
'not-required' => [false, false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test opt in validation
|
||||
*
|
||||
* @dataProvider dataProviderValidateOptIn
|
||||
*/
|
||||
public function testValidateOptIn($configValue, $checkboxStatus, $expectedValue)
|
||||
{
|
||||
/** @var ReviewController $controller */
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ReviewController::class);
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam($controller::REVIEW_OPTIN_PARAM, $configValue);
|
||||
$this->setRequestParameter('rvw_oegdproptin', $checkboxStatus);
|
||||
|
||||
$this->assertSame($expectedValue, $controller->validateOptIn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderValidateOptIn()
|
||||
{
|
||||
return [
|
||||
'required-checked' => [true, 1, true],
|
||||
'required-not-checked' => [true, 0, false],
|
||||
'required-not-exist' => [true, null, false],
|
||||
'not-required-checked' => [false, 1, true],
|
||||
'not-required-not-checked' => [false, 0, true],
|
||||
'not-required-not-exits' => [false, null, true]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test opt in validation
|
||||
*
|
||||
* @dataProvider dataProviderReviewOptInError
|
||||
*/
|
||||
public function testReviewOptInError($configValue, $checkboxStatus, $expectedValue)
|
||||
{
|
||||
/** @var ReviewController $controller */
|
||||
$controller = oxNew(\OxidEsales\Eshop\Application\Controller\ReviewController::class);
|
||||
\OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam($controller::REVIEW_OPTIN_PARAM, $configValue);
|
||||
$this->setRequestParameter('rvw_oegdproptin', $checkboxStatus);
|
||||
|
||||
$this->assertSame($expectedValue, $controller->isReviewOptInError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderReviewOptInError()
|
||||
{
|
||||
return [
|
||||
'required-checked' => [true, 1, false],
|
||||
'required-not-checked' => [true, 0, true],
|
||||
'required-not-exist' => [true, null, false],
|
||||
'not-required-checked' => [false, 1, false],
|
||||
'not-required-not-checked' => [false, 0, false],
|
||||
'not-required-not-exits' => [false, null, false]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop GDPR opt-in module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\GdprOptinModule\Tests\Integration;
|
||||
|
||||
use OxidEsales\Eshop\Application\Component\UserComponent;
|
||||
use OxidEsales\Eshop\Application\Controller\RegisterController;
|
||||
use OxidEsales\Eshop\Application\Controller\UserController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\TestingLibrary\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Class UserComponentTest
|
||||
*
|
||||
* @package OxidEsales\GdprOptinModule\Tests\Integration
|
||||
*/
|
||||
class UserComponentTest extends UnitTestCase
|
||||
{
|
||||
const TEST_USER_ID = '_gdprtest';
|
||||
|
||||
/**
|
||||
* Test set up.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createTestUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanUpTable('oxuser', 'oxid');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerDeliveryAddressOptin()
|
||||
{
|
||||
//Optin will only be required on changed or new address.
|
||||
$addAddress = ['oxaddressid' => '-1'];
|
||||
$changedAddress = ['oxaddressid' => 'someuniqueid', 'oegdproptin_changeDelAddress' => '1'];
|
||||
|
||||
return [
|
||||
'optin_true_checkbox_true_show_true_new' => [true, true, 'assertFalse', true, $addAddress],
|
||||
'optin_true_checkbox_true_show_true_change' => [true, true, 'assertFalse', true, $changedAddress],
|
||||
'optin_true_checkbox_true_show_true' => [true, true, 'assertFalse', true, []],
|
||||
|
||||
'optin_true_checkbox_false_show_true_new' => [true, false, 'assertTrue', true, $addAddress],
|
||||
'optin_true_checkbox_false_show_true_change' => [true, false, 'assertTrue', true, $changedAddress],
|
||||
'optin_true_checkbox_false_show_true' => [true, false, 'assertTrue', true, []],
|
||||
|
||||
'optin_false_checkbox_true_show_true' => [false, true, 'assertFalse', true, []],
|
||||
'optin_false_checkbox_false_show_true' => [false, false, 'assertFalse', true, []],
|
||||
|
||||
'optin_true_checkbox_true_show_false' => [true, true, 'assertFalse', false, []],
|
||||
'optin_true_checkbox_false_show_false' => [true, false, 'assertFalse', false, []],
|
||||
|
||||
'optin_false_checkbox_true_show_false' => [false, true, 'assertFalse', false, []],
|
||||
'optin_false_checkbox_false_show_false' => [false, false, 'assertFalse', false, []],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider providerDeliveryAddressOptin
|
||||
*
|
||||
* @param bool $requireGdprOptinDeliveryAddress
|
||||
* @param bool $checkboxChecked
|
||||
* @param string $assertDisplayExc
|
||||
* @param bool $showShip
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function testDeliveryAddressOptinValidationCheckoutUser($requireGdprOptinDeliveryAddress, $checkboxChecked, $assertDisplayExc, $showShip, $parameters)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinDeliveryAddress', $requireGdprOptinDeliveryAddress);
|
||||
|
||||
$parameters['oegdproptin_deliveryaddress'] = (int) $checkboxChecked;
|
||||
$parameters['blshowshipaddress'] = (int) $showShip;
|
||||
$this->addRequestParameters($parameters);
|
||||
|
||||
$cmpUser = oxNew(UserComponent::class);
|
||||
$cmpUser->changeuser();
|
||||
|
||||
$displayErrors = Registry::getSession()->getVariable('Errors');
|
||||
$this->$assertDisplayExc(array_key_exists('oegdproptin_deliveryaddress', $displayErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider providerDeliveryAddressOptin
|
||||
*
|
||||
* @param bool $requireGdprOptinDeliveryAddress
|
||||
* @param bool $checkboxChecked
|
||||
* @param string $assertDisplayExc
|
||||
* @param bool $showShip
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function testDeliveryAddressOptinValidationAccountUser($requireGdprOptinDeliveryAddress, $checkboxChecked, $assertDisplayExc, $showShip, $parameters)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinDeliveryAddress', $requireGdprOptinDeliveryAddress);
|
||||
|
||||
$parameters['oegdproptin_deliveryaddress'] = (int) $checkboxChecked;
|
||||
$parameters['blshowshipaddress'] = (int) $showShip;
|
||||
$this->addRequestParameters($parameters);
|
||||
|
||||
$cmpUser = oxNew(UserComponent::class);
|
||||
$cmpUser->changeuser_testvalues();
|
||||
|
||||
$displayErrors = Registry::getSession()->getVariable('Errors');
|
||||
$this->$assertDisplayExc(array_key_exists('oegdproptin_deliveryaddress', $displayErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerInvoiceAddressOptin()
|
||||
{
|
||||
//Optin will be required on changed invoice address
|
||||
$changedAddress = ['oegdproptin_changeInvAddress' => '1'];
|
||||
|
||||
return [
|
||||
'optin_true_checkbox_true_change' => [true, true, 'assertFalse', $changedAddress],
|
||||
'optin_true_checkbox_true_no_change' => [true, true, 'assertFalse', []],
|
||||
|
||||
'optin_true_checkbox_false_change' => [true, false, 'assertTrue', $changedAddress],
|
||||
'optin_true_checkbox_false_no_change' => [true, false, 'assertFalse', []],
|
||||
|
||||
'optin_false_checkbox_false_change' => [false, false, 'assertFalse', $changedAddress],
|
||||
'optin_false_checkbox_false_no_change' => [false, false, 'assertFalse', []],
|
||||
|
||||
'optin_false_checkbox_true_change' => [false, true, 'assertFalse', $changedAddress],
|
||||
'optin_false_checkbox_true_no_change' => [false, true, 'assertFalse', []],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider providerInvoiceAddressOptin
|
||||
*
|
||||
* @param bool $requireGdprOptinInvoiceAddress
|
||||
* @param bool $checkboxChecked
|
||||
* @param string $assertDisplayExc
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function testInvoiceAddressOptinValidationCheckoutUser($requireGdprOptinInvoiceAddress, $checkboxChecked, $assertDisplayExc, $parameters)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinInvoiceAddress', $requireGdprOptinInvoiceAddress);
|
||||
|
||||
$parameters['oegdproptin_invoiceaddress'] = (int) $checkboxChecked;
|
||||
$this->addRequestParameters($parameters);
|
||||
|
||||
$cmpUser = oxNew(UserComponent::class);
|
||||
$cmpUser->changeuser();
|
||||
|
||||
$displayErrors = Registry::getSession()->getVariable('Errors');
|
||||
$this->$assertDisplayExc(array_key_exists('oegdproptin_invoiceaddress', $displayErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider providerInvoiceAddressOptin
|
||||
*
|
||||
* @param bool $requireGdprOptinInvoiceAddress
|
||||
* @param bool $checkboxChecked
|
||||
* @param string $assertDisplayExc
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function testInvoiceAddressOptinValidationAccountUser($requireGdprOptinInvoiceAddress, $checkboxChecked, $assertDisplayExc, $parameters)
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinInvoiceAddress', $requireGdprOptinInvoiceAddress);
|
||||
|
||||
$parameters['oegdproptin_invoiceaddress'] = (int) $checkboxChecked;
|
||||
$this->addRequestParameters($parameters);
|
||||
|
||||
$cmpUser = oxNew(UserComponent::class);
|
||||
$cmpUser->changeuser_testvalues();
|
||||
|
||||
$displayErrors = Registry::getSession()->getVariable('Errors');
|
||||
$this->$assertDisplayExc(array_key_exists('oegdproptin_invoiceaddress', $displayErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerUserRegistrationOptin()
|
||||
{
|
||||
return [
|
||||
'enable_true_optin_true_register' => [true, true, 'assertFalse'],
|
||||
'enable_true_optin_false_register' => [true, false, 'assertTrue'],
|
||||
'enable_false_optin_true_register' => [false, true, 'assertFalse'],
|
||||
'enable_false_optin_false_register' => [false, false, 'assertFalse']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider providerUserRegistrationOptin
|
||||
*
|
||||
* @param bool $oeGdprUserRegistrationAddress
|
||||
* @param bool $checkboxChecked
|
||||
* @param string $assertDisplayExc
|
||||
* @param string $parent
|
||||
*/
|
||||
public function testUserRegistrationOptinValidation($oeGdprUserRegistrationAddress, $checkboxChecked, $assertDisplayExc)
|
||||
{
|
||||
Registry::getSession()->setUser(null);
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinUserRegistration', $oeGdprUserRegistrationAddress);
|
||||
|
||||
$parameters = ['oegdproptin_userregistration' => (int) $checkboxChecked,
|
||||
'option' => 3];
|
||||
$this->addRequestParameters($parameters);
|
||||
|
||||
$cmpUser = oxNew(UserComponent::class);
|
||||
$parentView = oxNew(RegisterController::class);
|
||||
$cmpUser->setParent($parentView);
|
||||
$cmpUser->createUser();
|
||||
|
||||
$displayErrors = Registry::getSession()->getVariable('Errors');
|
||||
$this->$assertDisplayExc(array_key_exists('oegdproptin_userregistration', $displayErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function providerUserCheckoutRegistrationOptin()
|
||||
{
|
||||
return [
|
||||
'enable_true_optin_true_guestbuy' => [true, true, 'assertFalse', 1],
|
||||
'enable_true_optin_false_guestbuy' => [true, false, 'assertFalse', 1],
|
||||
'enable_false_optin_true_guestbuy' => [false, true, 'assertFalse', 1],
|
||||
'enable_false_optin_false_guestbuy' => [false, false, 'assertFalse', 1],
|
||||
'enable_true_optin_true_createuser' => [true, true, 'assertFalse', 3],
|
||||
'enable_true_optin_false_createuser' => [true, false, 'assertTrue', 3],
|
||||
'enable_false_optin_true_createuser' => [false, true, 'assertFalse', 3],
|
||||
'enable_false_optin_false_createuser' => [false, false, 'assertFalse', 3]
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Test checkbox validation.
|
||||
*
|
||||
* @dataProvider providerUserCheckoutRegistrationOptin
|
||||
*
|
||||
* @param bool $oeGdprUserRegistrationAddress
|
||||
* @param bool $checkboxChecked
|
||||
* @param string $assertDisplayExc
|
||||
* @param int $option (1 = guest buy/no optin, 3 = create account)
|
||||
*/
|
||||
public function testUserRegistrationOptinValidationCheckoutUser($oeGdprUserRegistrationAddress, $checkboxChecked, $assertDisplayExc, $option)
|
||||
{
|
||||
Registry::getSession()->setUser(null);
|
||||
Registry::getConfig()->setConfigParam('blOeGdprOptinUserRegistration', $oeGdprUserRegistrationAddress);
|
||||
|
||||
$parameters = ['oegdproptin_userregistration' => (int) $checkboxChecked,
|
||||
'option' => $option];
|
||||
$this->addRequestParameters($parameters);
|
||||
|
||||
$cmpUser = oxNew(UserComponent::class);
|
||||
$parentView = oxNew(UserController::class);
|
||||
$cmpUser->setParent($parentView);
|
||||
$cmpUser->createUser();
|
||||
|
||||
$displayErrors = Registry::getSession()->getVariable('Errors');
|
||||
$this->$assertDisplayExc(array_key_exists('oegdproptin_userregistration', $displayErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test user.
|
||||
*/
|
||||
private function createTestUser()
|
||||
{
|
||||
$user = oxNew(User::class);
|
||||
$user->setId(self::TEST_USER_ID);
|
||||
$user->assign(
|
||||
[
|
||||
'oxfname' => 'Max',
|
||||
'oxlname' => 'Mustermann',
|
||||
'oxusername' => 'gdpruser@oxid.de',
|
||||
'oxpassword' => md5('agent'),
|
||||
'oxactive' => 1,
|
||||
'oxshopid' => 1,
|
||||
'oxcountryid' => 'a7c40f631fc920687.20179984',
|
||||
'oxboni' => '600',
|
||||
'oxstreet' => 'Teststreet',
|
||||
'oxstreetnr' => '101',
|
||||
'oxcity' => 'Hamburg',
|
||||
'oxzip' => '22769'
|
||||
]
|
||||
);
|
||||
$user->save();
|
||||
|
||||
//Ensure we have it in session and as active user
|
||||
$this->ensureActiveUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we have the test user as active user.
|
||||
*/
|
||||
private function ensureActiveUser()
|
||||
{
|
||||
$this->setSessionParam('usr', self::TEST_USER_ID);
|
||||
$this->setSessionParam('auth', self::TEST_USER_ID);
|
||||
|
||||
$user = oxNew(User::class);
|
||||
$user->load(self::TEST_USER_ID);
|
||||
Registry::getSession()->setUser($user);
|
||||
$user->setUser($user);
|
||||
$this->assertTrue($user->loadActiveUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test helper for setting requets parameters.
|
||||
*
|
||||
* @param array $parameters
|
||||
*/
|
||||
private function addRequestParameters($additionalParameters = [])
|
||||
{
|
||||
$address = 'a:13:{s:16:"oxaddress__oxsal";s:2:"MR";s:18:"oxaddress__oxfname";s:4:"Moxi";' .
|
||||
's:18:"oxaddress__oxlname";s:6:"Muster";s:20:"oxaddress__oxcompany";s:0:"";' .
|
||||
's:20:"oxaddress__oxaddinfo";s:0:"";s:19:"oxaddress__oxstreet";s:10:"Nicestreet";' .
|
||||
's:21:"oxaddress__oxstreetnr";s:3:"666";s:16:"oxaddress__oxzip";s:5:"12345";' .
|
||||
's:17:"oxaddress__oxcity";s:9:"Somewhere";s:22:"oxaddress__oxcountryid";' .
|
||||
's:26:"a7c40f631fc920687.20179984";s:20:"oxaddress__oxstateid";s:0:"";' .
|
||||
's:16:"oxaddress__oxfon";s:0:"";s:16:"oxaddress__oxfax";s:0:"";}';
|
||||
|
||||
$deliveryAddress = unserialize($address);
|
||||
$parameters = ['deladr' => $deliveryAddress,
|
||||
'stoken' => Registry::getSession()->getSessionChallengeToken()];
|
||||
|
||||
$parameters = array_merge($parameters, $additionalParameters);
|
||||
|
||||
foreach ($parameters as $key => $value) {
|
||||
$this->setRequestParameter($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
[{* empty *}]
|
||||
Reference in New Issue
Block a user