-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-2324: Added configuration parameter and RepositoryConfigResolver …
…to allow use content remote id (#103) * Added repository.content.use_remote_id parameter * Added Ibexa\Personalization namespace * Added RepositoryConfigResolver * Update src/bundle/DependencyInjection/ConfigurationMapper.php Co-authored-by: Konrad Oboza <[email protected]> Co-authored-by: Konrad Oboza <[email protected]>
- Loading branch information
Showing
10 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
EzSystems\EzRecommendationClient\Config\CredentialsResolver: ~ | ||
|
||
EzSystems\EzRecommendationClient\Config\EzRecommendationClientCredentialsResolver: ~ | ||
|
||
EzSystems\EzRecommendationClient\Config\ExportCredentialsResolver: ~ | ||
|
||
Ibexa\Personalization\Config\Repository\RepositoryConfigResolver: ~ | ||
|
||
Ibexa\Personalization\Config\Repository\RepositoryConfigResolverInterface: | ||
'@Ibexa\Personalization\Config\Repository\RepositoryConfigResolver' |
8 changes: 0 additions & 8 deletions
8
src/bundle/Resources/config/services/credentials_checker.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Personalization\Config\Repository; | ||
|
||
use eZ\Publish\Core\MVC\ConfigResolverInterface; | ||
use EzSystems\EzRecommendationClient\Value\Parameters; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class RepositoryConfigResolver implements RepositoryConfigResolverInterface | ||
{ | ||
private const USE_CONTENT_REMOTE_ID_PARAMETER = 'repository.content.use_remote_id'; | ||
|
||
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */ | ||
private $configResolver; | ||
|
||
public function __construct(ConfigResolverInterface $configResolver) | ||
{ | ||
$this->configResolver = $configResolver; | ||
} | ||
|
||
public function useRemoteId(): bool | ||
{ | ||
if ( | ||
!$this->configResolver->hasParameter( | ||
self::USE_CONTENT_REMOTE_ID_PARAMETER, | ||
Parameters::NAMESPACE | ||
) | ||
) { | ||
return false; | ||
} | ||
|
||
return $this->configResolver->getParameter( | ||
self::USE_CONTENT_REMOTE_ID_PARAMETER, | ||
Parameters::NAMESPACE | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/lib/Config/Repository/RepositoryConfigResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Personalization\Config\Repository; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface RepositoryConfigResolverInterface | ||
{ | ||
public function useRemoteId(): bool; | ||
} |
73 changes: 73 additions & 0 deletions
73
tests/lib/Config/Repository/RepositoryConfigResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Personalization\Config\Repository; | ||
|
||
use eZ\Publish\Core\MVC\ConfigResolverInterface; | ||
use Ibexa\Personalization\Config\Repository\RepositoryConfigResolver; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \Ibexa\Personalization\Config\Repository\RepositoryConfigResolver | ||
*/ | ||
final class RepositoryConfigResolverTest extends TestCase | ||
{ | ||
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */ | ||
private $configResolver; | ||
|
||
/** @var \Ibexa\Personalization\Config\Repository\RepositoryConfigResolverInterface */ | ||
private $repositoryConfigResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->configResolver = $this->createMock(ConfigResolverInterface::class); | ||
$this->repositoryConfigResolver = new RepositoryConfigResolver($this->configResolver); | ||
} | ||
|
||
public function testUseRemoteId(): void | ||
{ | ||
$this->mockConfigResolverHasParameter(true); | ||
$this->mockConfigResolverGetParameter(true); | ||
|
||
self::assertTrue($this->repositoryConfigResolver->useRemoteId()); | ||
} | ||
|
||
public function testDoNotUseRemoteIdWhenParameterIsNotDefined(): void | ||
{ | ||
$this->mockConfigResolverHasParameter(false); | ||
$this->mockConfigResolverGetParameter(false); | ||
|
||
self::assertFalse($this->repositoryConfigResolver->useRemoteId()); | ||
} | ||
|
||
public function testDoNotUseRemoteIdWhenParameterValueIsFalse(): void | ||
{ | ||
$this->mockConfigResolverHasParameter(true); | ||
$this->mockConfigResolverGetParameter(false); | ||
|
||
self::assertFalse($this->repositoryConfigResolver->useRemoteId()); | ||
} | ||
|
||
private function mockConfigResolverHasParameter(bool $hasParameter): void | ||
{ | ||
$this->configResolver | ||
->expects(self::once()) | ||
->method('hasParameter') | ||
->with('repository.content.use_remote_id', 'ezrecommendation') | ||
->willReturn($hasParameter); | ||
} | ||
|
||
private function mockConfigResolverGetParameter(bool $useRemoteId): void | ||
{ | ||
$this->configResolver | ||
->expects(self::once()) | ||
->method('getParameter') | ||
->with('repository.content.use_remote_id', 'ezrecommendation') | ||
->willReturn($useRemoteId); | ||
} | ||
} |