From a0f38c15b42e1d1ea0c4dfb8608b45606661eb17 Mon Sep 17 00:00:00 2001 From: Adrien DUPUIS Date: Mon, 27 Jul 2020 11:45:09 +0200 Subject: [PATCH 1/2] Add a single unit test checking siteaccess and repository `docker-compose exec apache bin/phpunit tests/SiteAccessAwareTest.php;` TODO: make it siteaccess aware --- phpunit.xml | 11 +++++++++++ tests/SiteAccessAwareTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 phpunit.xml create mode 100644 tests/SiteAccessAwareTest.php diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..8a1f81ca --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/tests/SiteAccessAwareTest.php b/tests/SiteAccessAwareTest.php new file mode 100644 index 00000000..a56cf687 --- /dev/null +++ b/tests/SiteAccessAwareTest.php @@ -0,0 +1,28 @@ +getContainer()->get('ezpublish.siteaccess')); // Weird “uninitialized” siteaccess named “default” instead of named after the default siteaccess “site” + + /** @var Repository $repository */ + $repository = self::$kernel->getContainer()->get('ezpublish.api.repository'); + + // Shows that the default connection is used + $rootLocation = $repository->getLocationService()->loadLocation(2); + self::assertNotNull($rootLocation); + self::assertEquals(2, $rootLocation->id); + self::assertEquals('Home', $rootLocation->getContentInfo()->name); + } +} From cdf724de8599f07624e111e2739727658b809c62 Mon Sep 17 00:00:00 2001 From: Adrien DUPUIS Date: Mon, 27 Jul 2020 13:33:58 +0200 Subject: [PATCH 2/2] SiteAccessAwareTest: Change siteaccess and test config resolver --- app/config/ezplatform_test.yml | 5 +++++ tests/SiteAccessAwareTest.php | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/config/ezplatform_test.yml b/app/config/ezplatform_test.yml index 967ac2e9..2c0455c2 100644 --- a/app/config/ezplatform_test.yml +++ b/app/config/ezplatform_test.yml @@ -1,2 +1,7 @@ imports: - { resource: ezplatform.yml } + +parameters: + ezsettings.default.unit_test: 'default value' + ezsettings.site.unit_test: 'site value' + ezsettings.admin_group.unit_test: 'admin value' \ No newline at end of file diff --git a/tests/SiteAccessAwareTest.php b/tests/SiteAccessAwareTest.php index a56cf687..0f4157e8 100644 --- a/tests/SiteAccessAwareTest.php +++ b/tests/SiteAccessAwareTest.php @@ -2,19 +2,30 @@ namespace App\Tests; +use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver; +use eZ\Publish\Core\MVC\Symfony\SiteAccess; use eZ\Publish\Core\Repository\SiteAccessAware\Repository; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; class SiteAccessAwareTest extends KernelTestCase { + /** @var ConfigResolver */ + private $configResolver; + public function setup(): void { self::bootKernel(); + $this->configResolver = self::$kernel->getContainer()->get('ezpublish.config.resolver'); } public function testSiteAccess() { - var_dump(self::$kernel->getContainer()->get('ezpublish.siteaccess')); // Weird “uninitialized” siteaccess named “default” instead of named after the default siteaccess “site” + //$wantedSiteAccess = 'site'; + $wantedSiteAccess = 'admin'; + + self::$kernel->getContainer()->set('ezpublish.siteaccess', new SiteAccess($wantedSiteAccess, 'phpunit')); + + self::assertEquals("$wantedSiteAccess value", $this->configResolver->getParameter('unit_test')); /** @var Repository $repository */ $repository = self::$kernel->getContainer()->get('ezpublish.api.repository');