Skip to content

Commit fe83485

Browse files
OXDEV-9919 Fix failing tests
1 parent 5122085 commit fe83485

5 files changed

Lines changed: 52 additions & 117 deletions

File tree

src/Authentication/OAuth2/Service/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55

66
OxidEsales\SecurityModule\Authentication\OAuth2\Service\ModuleSettingsServiceInterface:
77
class: OxidEsales\SecurityModule\Authentication\OAuth2\Service\ModuleSettingsService
8+
public: true
89

910
OxidEsales\SecurityModule\Authentication\OAuth2\Service\UserServiceInterface:
1011
class: OxidEsales\SecurityModule\Authentication\OAuth2\Service\UserService

tests/Codeception/Acceptance/ProvidersVisibilityCest.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I): void
2828
private $providerLink =
2929
'div[contains(@class, "sign-in-providers")]' .
3030
'//div[@class="provider"]' .
31-
'//a[contains(@href, "cl=oauth&fnc=redirect&provider=")]';
31+
'//a[contains(@href, "cl=oauth&fnc=login&provider=")]';
3232

3333
public function testProvidersVisibilityOnHeaderLogin(AcceptanceTester $I): void
3434
{
@@ -72,39 +72,4 @@ public function testProviderVisibilityOnCheckoutPage(AcceptanceTester $I): void
7272
$I->seeElement($providerLinkElement);
7373
$I->assertGreaterOrEquals(1, count($I->grabMultiple($providerLinkElement)));
7474
}
75-
76-
public function testProviderVisibilityOnCheckoutWithoutAccount(AcceptanceTester $I): void
77-
{
78-
$providerLinkElement = '//div[contains(@class, "card-body")]//' . $this->providerLink;
79-
80-
$basket = new Basket($I);
81-
$userCheckout = $basket->addProductToBasketAndOpenUserCheckout('1000', 1);
82-
$userCheckout->selectOptionNoRegistration();
83-
$I->dontSeeElement($providerLinkElement);
84-
85-
$this->setProviderState(true);
86-
$basket = new Basket($I);
87-
$userCheckout = $basket->addProductToBasketAndOpenUserCheckout('1000', 1);
88-
$userCheckout->selectOptionNoRegistration();
89-
$I->seeElement($providerLinkElement);
90-
$I->assertGreaterOrEquals(1, count($I->grabMultiple($providerLinkElement)));
91-
}
92-
93-
public function testProviderVisibilityOnCheckoutWithNewAccount(AcceptanceTester $I): void
94-
{
95-
$providerLinkElement = '//div[contains(@class, "card-body")]//' . $this->providerLink;
96-
97-
$basket = new Basket($I);
98-
$basket
99-
->addProductToBasketAndOpenUserCheckout('1000', 1)
100-
->selectOptionRegisterNewAccount();
101-
$I->dontSeeElement($providerLinkElement);
102-
103-
$this->setProviderState(true);
104-
$basket
105-
->addProductToBasketAndOpenUserCheckout('1000', 1)
106-
->selectOptionRegisterNewAccount();
107-
$I->seeElement($providerLinkElement);
108-
$I->assertGreaterOrEquals(1, count($I->grabMultiple($providerLinkElement)));
109-
}
11075
}

tests/Unit/Authentication/OAuth2/Infrastructure/UserFactoryTest.php renamed to tests/Integration/Authentication/OAuth2/Infrastructure/UserFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\SecurityModule\Tests\Unit\Authentication\OAuth2\Infrastructure;
10+
namespace OxidEsales\SecurityModule\Tests\Integration\Authentication\OAuth2\Infrastructure;
1111

1212
use OxidEsales\Eshop\Application\Model\User;
1313
use OxidEsales\SecurityModule\Authentication\OAuth2\Infrastructure\UserFactory;

tests/Integration/Authentication/OAuth2/Service/UserServiceTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,55 @@ public function testLoginWithNonExistingUser(): void
8686
$sut->login($userDataObjectMock);
8787
}
8888

89+
public function testLoginWithoutEmail(): void
90+
{
91+
$userDataObjectMock = $this->createMock(UserInterface::class);
92+
93+
$sut = $this->getSut();
94+
95+
$this->expectException(UserNotFoundException::class);
96+
97+
$sut->login($userDataObjectMock);
98+
}
99+
100+
public function testGetUserByUserEmailIsFound(): void
101+
{
102+
$userDataObjectMock = $this->createMock(UserInterface::class);
103+
$userDataObjectMock->method('getEmail')->willReturn(uniqid());
104+
105+
$userRepositoryMock = $this->createMock(UserRepositoryInterface::class);
106+
$userRepositoryMock->method('getUserByUserEmail')->willReturn(new UserModel());
107+
$userRepositoryMock->expects($this->never())->method('createUser');
108+
109+
$sut = $this->getSut(
110+
userRepository: $userRepositoryMock
111+
);
112+
113+
$sut->login($userDataObjectMock);
114+
}
115+
116+
public function testGetUserByUserEmailIsNotFoundByCreated(): void
117+
{
118+
$userDataObjectMock = $this->createMock(UserInterface::class);
119+
$userDataObjectMock->method('getEmail')->willReturn(uniqid());
120+
121+
$userRepositoryMock = $this->createMock(UserRepositoryInterface::class);
122+
$userRepositoryMock
123+
->method('getUserByUserEmail')
124+
->willThrowException(new UserNotFoundException());
125+
$userRepositoryMock
126+
->expects($this->once())
127+
->method('createUser')
128+
->with($userDataObjectMock)
129+
->willReturn(new UserModel());
130+
131+
$sut = $this->getSut(
132+
userRepository: $userRepositoryMock
133+
);
134+
135+
$sut->login($userDataObjectMock);
136+
}
137+
89138
private function createTestUser(string $username): string
90139
{
91140
$user = oxNew(UserModel::class);

tests/Unit/Authentication/OAuth2/Service/UserServiceTest.php

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)