|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright © OXID eSales AG. All rights reserved. |
| 5 | + * See LICENSE file for license details. |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +namespace OxidEsales\EshopCommunity\Tests\Integration\Application\Component; |
| 11 | + |
| 12 | +use OxidEsales\Eshop\Application\Component\UserComponent; |
| 13 | +use OxidEsales\Eshop\Application\Controller\FrontendController; |
| 14 | +use OxidEsales\Eshop\Core\Registry; |
| 15 | +use OxidEsales\Eshop\Core\Session; |
| 16 | +use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; |
| 17 | +use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; |
| 18 | + |
| 19 | +final class UserComponentTest extends IntegrationTestCase |
| 20 | +{ |
| 21 | + public function testCreateUserFields(): void |
| 22 | + { |
| 23 | + Registry::getConfig()->setConfigParam('blPsLoginEnabled', true); |
| 24 | + |
| 25 | + $userComponentMock = $this->getUserComponent(); |
| 26 | + $userComponentMock->createUser(); |
| 27 | + $user = $this->fetchUserData(); |
| 28 | + |
| 29 | + $this->assertEquals('fname', $user['OXFNAME']); |
| 30 | + $this->assertEquals('lname', $user['OXLNAME']); |
| 31 | + $this->assertEquals('street', $user['OXSTREET']); |
| 32 | + $this->assertEquals('zip', $user['OXZIP']); |
| 33 | + $this->assertEquals('nr', $user['OXSTREETNR']); |
| 34 | + $this->assertEquals('city', $user['OXCITY']); |
| 35 | + $this->assertEquals('a7c40f631fc920687.20179984', $user['OXCOUNTRYID']); |
| 36 | + } |
| 37 | + |
| 38 | + public function testCreateUserResponse(): void |
| 39 | + { |
| 40 | + Registry::getConfig()->setConfigParam('blPsLoginEnabled', true); |
| 41 | + $userComponentMock = $this->getUserComponent(); |
| 42 | + $createUserReturn = $userComponentMock->createUser(); |
| 43 | + |
| 44 | + $this->assertEquals('payment?new_user=1&success=1', $createUserReturn); |
| 45 | + } |
| 46 | + |
| 47 | + public function testCreateUserPrivateSales(): void |
| 48 | + { |
| 49 | + Registry::getConfig()->setConfigParam('blPsLoginEnabled', true); |
| 50 | + |
| 51 | + $userComponentMock = $this->getUserComponent(); |
| 52 | + $userComponentMock->createUser(); |
| 53 | + $user = $this->fetchUserData(); |
| 54 | + |
| 55 | + $this->assertEquals(0, $user['OXACTIVE']); |
| 56 | + } |
| 57 | + |
| 58 | + public function testCreateUser(): void |
| 59 | + { |
| 60 | + Registry::getConfig()->setConfigParam('blPsLoginEnabled', false); |
| 61 | + |
| 62 | + $userComponentMock = $this->getUserComponent(); |
| 63 | + $userComponentMock->createUser(); |
| 64 | + $user = $this->fetchUserData(); |
| 65 | + |
| 66 | + $this->assertEquals(1, $user['OXACTIVE']); |
| 67 | + } |
| 68 | + |
| 69 | + private function getUserComponent(): UserComponent |
| 70 | + { |
| 71 | + $rawVal = [ |
| 72 | + 'oxuser__oxfname' => 'fname', |
| 73 | + 'oxuser__oxlname' => 'lname', |
| 74 | + 'oxuser__oxstreetnr' => 'nr', |
| 75 | + 'oxuser__oxstreet' => 'street', |
| 76 | + 'oxuser__oxzip' => 'zip', |
| 77 | + 'oxuser__oxcity' => 'city', |
| 78 | + 'oxuser__oxcountryid' => 'a7c40f631fc920687.20179984', |
| 79 | + 'oxuser__oxactive' => 1 |
| 80 | + ]; |
| 81 | + |
| 82 | + $_POST = array_merge($_POST, |
| 83 | + [ |
| 84 | + 'lgn_usr' => 'test@oxid-esales.com', |
| 85 | + 'lgn_pwd' => 'Test@oxid-esales.com', |
| 86 | + 'lgn_pwd2' => 'Test@oxid-esales.com', |
| 87 | + 'invadr' => $rawVal |
| 88 | + ] |
| 89 | + ); |
| 90 | + |
| 91 | + $fronendController = oxNew(FrontendController::class); |
| 92 | + $userComponent = oxNew(UserComponent::class); |
| 93 | + $userComponent->setParent($fronendController); |
| 94 | + $this->setSessionChallenge(); |
| 95 | + |
| 96 | + return $userComponent; |
| 97 | + } |
| 98 | + |
| 99 | + private function fetchUserData(): array |
| 100 | + { |
| 101 | + $queryBuilder = $this->get(QueryBuilderFactoryInterface::class)->create(); |
| 102 | + |
| 103 | + return $queryBuilder |
| 104 | + ->select('*') |
| 105 | + ->from('oxuser') |
| 106 | + ->where('oxusername = :oxusername') |
| 107 | + ->setParameters([ |
| 108 | + 'oxusername' => 'test@oxid-esales.com', |
| 109 | + ]) |
| 110 | + ->execute() |
| 111 | + ->fetch(); |
| 112 | + } |
| 113 | + |
| 114 | + private function setSessionChallenge(): void |
| 115 | + { |
| 116 | + Registry::set( |
| 117 | + Session::class, |
| 118 | + $this->createConfiguredMock( |
| 119 | + Session::class, |
| 120 | + ['checkSessionChallenge' => true] |
| 121 | + ) |
| 122 | + ); |
| 123 | + } |
| 124 | +} |
0 commit comments