diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 4cae4c2b..ee6b1969 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -8,11 +8,35 @@ on:
pull_request: ~
jobs:
+ cs-fix:
+ name: Run code style check
+ runs-on: "ubuntu-20.04"
+ strategy:
+ matrix:
+ php:
+ - '8.0'
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Setup PHP Action
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ coverage: none
+ extensions: 'pdo_sqlite, gd'
+ tools: cs2pr
+
+ - uses: "ramsey/composer-install@v1"
+ with:
+ dependency-versions: "highest"
+
+ - name: Run code style check
+ run: composer run-script check-cs -- --format=checkstyle | cs2pr
+
tests:
name: Tests
runs-on: "ubuntu-20.04"
timeout-minutes: 10
- continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
@@ -20,8 +44,8 @@ jobs:
php:
- '7.3'
- '7.4'
- composer_options: [ "" ]
- experimental: [false]
+ - '8.0'
+ - '8.1'
steps:
- uses: actions/checkout@v2
@@ -37,14 +61,10 @@ jobs:
- uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
- composer-options: "${{ matrix.composer_options }}"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- - name: Run code style check
- run: composer run-script check-cs -- --format=checkstyle | cs2pr
-
- name: Run test suite
run: composer run-script --timeout=600 test
@@ -67,15 +87,14 @@ jobs:
--tmpfs /var/lib/postgresql/data
runs-on: "ubuntu-20.04"
timeout-minutes: 10
- continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
- experimental: [ false ]
php:
- '7.4'
- composer_options: [ "" ]
+ - '8.0'
+ - '8.1'
steps:
- uses: actions/checkout@v2
@@ -91,7 +110,6 @@ jobs:
- uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
- composer-options: "${{ matrix.composer_options }}"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
@@ -122,15 +140,14 @@ jobs:
--tmpfs=/var/lib/mysql
runs-on: "ubuntu-20.04"
timeout-minutes: 10
- continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
- experimental: [ false ]
php:
- '7.4'
- composer_options: [ "" ]
+ - '8.0'
+ - '8.1'
steps:
- uses: actions/checkout@v2
@@ -146,7 +163,6 @@ jobs:
- uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
- composer-options: "${{ matrix.composer_options }}"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
diff --git a/composer.json b/composer.json
index 8a663bb4..1c7b2c3c 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,7 @@
"license": "GPL-2.0-only",
"type": "ezplatform-bundle",
"require": {
- "php": "^7.3",
+ "php": "^7.3 || ^8.0",
"ext-xsl": "*",
"ext-dom": "*",
"ext-libxml": "*",
@@ -24,14 +24,14 @@
"symfony/translation-contracts": "^2.0",
"twig/twig": "^3.0",
"ezsystems/ezplatform-kernel": "^1.3@dev",
- "ezsystems/ezplatform-content-forms": "^1.0@dev",
- "ezsystems/ezplatform-rest": "^1.0@dev",
+ "ezsystems/ezplatform-content-forms": "^1.3@dev",
+ "ezsystems/ezplatform-rest": "^1.3@dev",
"ezsystems/ezplatform-http-cache": "^2.0@dev"
},
"require-dev": {
"ibexa/ci-scripts": "^0.1@dev",
"ezsystems/doctrine-dbal-schema": "^1.0@dev",
- "phpunit/phpunit": "^8.5",
+ "phpunit/phpunit": "^9.5",
"symfony/finder": "^5.0",
"matthiasnoback/symfony-config-test": "^4.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
diff --git a/tests/bundle/eZ/RichText/RendererTest.php b/tests/bundle/eZ/RichText/RendererTest.php
index 3d185e0a..39e943e0 100644
--- a/tests/bundle/eZ/RichText/RendererTest.php
+++ b/tests/bundle/eZ/RichText/RendererTest.php
@@ -147,14 +147,20 @@ public function testRenderTagNoTemplateFound()
);
}
- public function providerForTestRenderTagWithTemplate()
+ public function providerForTestRenderTagWithTemplate(): array
{
return [
[
$tagName = 'tag1',
[
- ['hasParameter', $namespace = "test.name.space.tag.{$tagName}", true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName1']],
+ [
+ [[$namespace = "test.name.space.tag.{$tagName}"]],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName1']],
+ ],
],
[],
$templateName,
@@ -165,8 +171,14 @@ public function providerForTestRenderTagWithTemplate()
[
$tagName = 'tag2',
[
- ['hasParameter', $namespace = "test.name.space.tag.{$tagName}", true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName2']],
+ [
+ [[$namespace = "test.name.space.tag.{$tagName}"]],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName2']],
+ ],
],
[],
$templateName,
@@ -177,12 +189,20 @@ public function providerForTestRenderTagWithTemplate()
[
$tagName = 'tag3',
[
- ['hasParameter', "test.name.space.tag.{$tagName}", false],
- ['hasParameter', $namespace = 'test.name.space.tag.default', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName3']],
+ [
+ [["test.name.space.tag.{$tagName}"], [$namespace = 'test.name.space.tag.default']],
+ [false, true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName3']],
+ ],
],
[
- ['warning', "Template tag '{$tagName}' configuration was not found"],
+ [
+ ["Template tag '{$tagName}' configuration was not found"],
+ ],
+ [],
],
$templateName,
$templateName,
@@ -192,12 +212,20 @@ public function providerForTestRenderTagWithTemplate()
[
$tagName = 'tag4',
[
- ['hasParameter', "test.name.space.tag.{$tagName}", false],
- ['hasParameter', $namespace = 'test.name.space.tag.default_inline', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName4']],
+ [
+ [["test.name.space.tag.{$tagName}"], [$namespace = 'test.name.space.tag.default_inline']],
+ [false, true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName4']],
+ ],
],
[
- ['warning', "Template tag '{$tagName}' configuration was not found"],
+ [
+ ["Template tag '{$tagName}' configuration was not found"],
+ ],
+ [],
],
$templateName,
$templateName,
@@ -207,13 +235,23 @@ public function providerForTestRenderTagWithTemplate()
[
$tagName = 'tag5',
[
- ['hasParameter', "test.name.space.tag.{$tagName}", false],
- ['hasParameter', $namespace = 'test.name.space.tag.default', false],
+ [
+ [["test.name.space.tag.{$tagName}"], ['test.name.space.tag.default']],
+ [false, false],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
- ['warning', "Template tag '{$tagName}' configuration was not found"],
- ['warning', "Template tag '{$tagName}' default configuration was not found"],
- ['error', "Could not render template tag '{$tagName}': no template configured"],
+ [
+ ["Template tag '{$tagName}' configuration was not found"],
+ ["Template tag '{$tagName}' default configuration was not found"],
+ ],
+ [
+ ["Could not render template tag '{$tagName}': no template configured"],
+ ],
],
null,
null,
@@ -223,13 +261,23 @@ public function providerForTestRenderTagWithTemplate()
[
$tagName = 'tag6',
[
- ['hasParameter', "test.name.space.tag.{$tagName}", false],
- ['hasParameter', $namespace = 'test.name.space.tag.default_inline', false],
+ [
+ [["test.name.space.tag.{$tagName}"], ['test.name.space.tag.default_inline']],
+ [false, false],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
- ['warning', "Template tag '{$tagName}' configuration was not found"],
- ['warning', "Template tag '{$tagName}' default configuration was not found"],
- ['error', "Could not render template tag '{$tagName}': no template configured"],
+ [
+ ["Template tag '{$tagName}' configuration was not found"],
+ ["Template tag '{$tagName}' default configuration was not found"],
+ ],
+ [
+ ["Could not render template tag '{$tagName}': no template configured"],
+ ],
],
null,
null,
@@ -250,7 +298,7 @@ public function testRenderTagWithTemplate(
$renderTemplate,
$isInline,
$renderResult
- ) {
+ ): void {
$renderer = $this->getMockedRenderer(['render']);
$parameters = ['parameters'];
@@ -287,17 +335,24 @@ public function testRenderTagWithTemplate(
->expects($this->never())
->method($this->anything());
} else {
- $i = 0;
- foreach ($configResolverParams as $params) {
- $method = $params[0];
- $namespace = $params[1];
- $returnValue = $params[2];
+ [$hasParameterValues, $getParameterValues] = $configResolverParams;
+ [$hasParameterArguments, $hasParameterReturnValues] = $hasParameterValues;
+ [$getParameterArguments, $getParameterReturnValues] = $getParameterValues;
+
+ if (!empty($hasParameterArguments)) {
+ $this->configResolverMock
+ ->expects($this->exactly(count($hasParameterArguments)))
+ ->method('hasParameter')
+ ->withConsecutive($hasParameterArguments[0])
+ ->willReturnOnConsecutiveCalls(...$hasParameterReturnValues);
+ }
+
+ if (!empty($getParameterArguments)) {
$this->configResolverMock
- ->expects($this->at($i))
- ->method($method)
- ->with($namespace)
- ->willReturn($returnValue);
- ++$i;
+ ->expects($this->exactly(count($getParameterArguments)))
+ ->method('getParameter')
+ ->withConsecutive($getParameterArguments[0])
+ ->willReturnOnConsecutiveCalls(...$getParameterReturnValues);
}
}
@@ -306,15 +361,20 @@ public function testRenderTagWithTemplate(
->expects($this->never())
->method($this->anything());
} else {
- $i = 0;
- foreach ($loggerParams as $params) {
- $method = $params[0];
- $message = $params[1];
+ [$warningArguments, $errorArguments] = $loggerParams;
+
+ if (!empty($warningArguments)) {
+ $this->loggerMock
+ ->expects($this->exactly(count($warningArguments)))
+ ->method('warning')
+ ->withConsecutive(...$warningArguments);
+ }
+
+ if (!empty($errorArguments)) {
$this->loggerMock
- ->expects($this->at($i))
- ->method($method)
- ->with($message);
- ++$i;
+ ->expects($this->exactly(count($errorArguments)))
+ ->method('error')
+ ->withConsecutive(...$errorArguments);
}
}
@@ -587,15 +647,15 @@ public function testRenderContentEmbedHidden()
$contentInfoMock = $this->createMock(ContentInfo::class);
$contentInfoMock
- ->expects($this->at(0))
+ ->expects($this->exactly(2))
->method('__get')
- ->with('mainLocationId')
- ->willReturn(2);
- $contentInfoMock
- ->expects($this->at(1))
- ->method('__get')
- ->with('isHidden')
- ->willReturn(true);
+ ->withConsecutive(
+ ['mainLocationId'],
+ ['isHidden'],
+ )->willReturnOnConsecutiveCalls(
+ 2,
+ true
+ );
$contentMock = $this->createMock(Content::class);
$contentMock
@@ -709,11 +769,20 @@ public function providerForTestRenderContentWithTemplate()
false,
new AccessDeniedException(),
[
- ['hasParameter', $namespace = 'test.name.space.embed.content_denied', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName1']],
+ [
+ [[$namespace = 'test.name.space.embed.content_denied']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName1']],
+ ],
],
[
- ['error', "Could not render embedded resource: access denied to embed Content #{$contentId}"],
+ [],
+ [
+ ["Could not render embedded resource: access denied to embed Content #{$contentId}"],
+ ],
],
$templateName,
$templateName,
@@ -723,11 +792,20 @@ public function providerForTestRenderContentWithTemplate()
true,
new AccessDeniedException(),
[
- ['hasParameter', $namespace = 'test.name.space.embed.content_inline_denied', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName2']],
+ [
+ [[$namespace = 'test.name.space.embed.content_inline_denied']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName2']],
+ ],
],
[
- ['error', "Could not render embedded resource: access denied to embed Content #{$contentId}"],
+ [],
+ [
+ ["Could not render embedded resource: access denied to embed Content #{$contentId}"],
+ ],
],
$templateName,
$templateName,
@@ -737,8 +815,14 @@ public function providerForTestRenderContentWithTemplate()
false,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.content', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName3']],
+ [
+ [[$namespace = 'test.name.space.embed.content']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName3']],
+ ],
],
[],
$templateName,
@@ -749,8 +833,14 @@ public function providerForTestRenderContentWithTemplate()
true,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.content_inline', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName4']],
+ [
+ [[$namespace = 'test.name.space.embed.content_inline']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName4']],
+ ],
],
[],
$templateName,
@@ -761,12 +851,21 @@ public function providerForTestRenderContentWithTemplate()
false,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.content', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default', true],
- ['getParameter', $namespace2, ['template' => $templateName = 'templateName5']],
+ [
+ [
+ [$namespace = 'test.name.space.embed.content'],
+ [$namespace2 = 'test.name.space.embed.default'],
+ ],
+ [false, true],
+ ],
+ [
+ [[$namespace2]],
+ [['template' => $templateName = 'templateName5']],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
+ [["Embed tag configuration '{$namespace}' was not found"]],
+ [],
],
$templateName,
$templateName,
@@ -776,12 +875,21 @@ public function providerForTestRenderContentWithTemplate()
true,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.content_inline', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default_inline', true],
- ['getParameter', $namespace2, ['template' => $templateName = 'templateName6']],
+ [
+ [
+ [$namespace = 'test.name.space.embed.content_inline'],
+ [$namespace2 = 'test.name.space.embed.default_inline'],
+ ],
+ [false, true],
+ ],
+ [
+ [[$namespace2]],
+ [['template' => $templateName = 'templateName6']],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
+ [["Embed tag configuration '{$namespace}' was not found"]],
+ [],
],
$templateName,
$templateName,
@@ -791,12 +899,24 @@ public function providerForTestRenderContentWithTemplate()
false,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.content', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default', false],
+ [
+ [
+ [$namespace = 'test.name.space.embed.content'],
+ [$namespace2 = 'test.name.space.embed.default'],
+ ],
+ [false, false],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
- ['warning', "Embed tag default configuration '{$namespace2}' was not found"],
+ [
+ ["Embed tag configuration '{$namespace}' was not found"],
+ ["Embed tag default configuration '{$namespace2}' was not found"],
+ ],
+ [],
],
null,
null,
@@ -806,12 +926,24 @@ public function providerForTestRenderContentWithTemplate()
true,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.content_inline', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default_inline', false],
+ [
+ [
+ [$namespace = 'test.name.space.embed.content_inline'],
+ [$namespace2 = 'test.name.space.embed.default_inline'],
+ ],
+ [false, false],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
- ['warning', "Embed tag default configuration '{$namespace2}' was not found"],
+ [
+ ["Embed tag configuration '{$namespace}' was not found"],
+ ["Embed tag default configuration '{$namespace2}' was not found"],
+ ],
+ [],
],
null,
null,
@@ -831,7 +963,7 @@ public function testRenderContentWithTemplate(
$templateEngineTemplate,
$renderTemplate,
$renderResult
- ) {
+ ): void {
$renderer = $this->getMockedRenderer(['render', 'checkContentPermissions']);
$contentId = 42;
$viewType = 'embedTest';
@@ -892,17 +1024,24 @@ public function testRenderContentWithTemplate(
->expects($this->never())
->method($this->anything());
} else {
- $i = 0;
- foreach ($configResolverParams as $params) {
- $method = $params[0];
- $namespace = $params[1];
- $returnValue = $params[2];
+ [$hasParameterValues, $getParameterValues] = $configResolverParams;
+ [$hasParameterArguments, $hasParameterReturnValues] = $hasParameterValues;
+ [$getParameterArguments, $getParameterReturnValues] = $getParameterValues;
+
+ if (!empty($hasParameterArguments)) {
+ $this->configResolverMock
+ ->expects($this->exactly(count($hasParameterArguments)))
+ ->method('hasParameter')
+ ->withConsecutive($hasParameterArguments[0])
+ ->willReturnOnConsecutiveCalls(...$hasParameterReturnValues);
+ }
+
+ if (!empty($getParameterArguments)) {
$this->configResolverMock
- ->expects($this->at($i))
- ->method($method)
- ->with($namespace)
- ->willReturn($returnValue);
- ++$i;
+ ->expects($this->exactly(count($getParameterArguments)))
+ ->method('getParameter')
+ ->withConsecutive($getParameterArguments[0])
+ ->willReturnOnConsecutiveCalls(...$getParameterReturnValues);
}
}
@@ -911,15 +1050,20 @@ public function testRenderContentWithTemplate(
->expects($this->never())
->method($this->anything());
} else {
- $i = 0;
- foreach ($loggerParams as $params) {
- $method = $params[0];
- $message = $params[1];
+ [$warningArguments, $errorArguments] = $loggerParams;
+
+ if (!empty($warningArguments)) {
+ $this->loggerMock
+ ->expects($this->exactly(count($warningArguments)))
+ ->method('warning')
+ ->withConsecutive(...$warningArguments);
+ }
+
+ if (!empty($errorArguments)) {
$this->loggerMock
- ->expects($this->at($i))
- ->method($method)
- ->with($message);
- ++$i;
+ ->expects($this->exactly(count($errorArguments)))
+ ->method('error')
+ ->withConsecutive(...$errorArguments);
}
}
@@ -1253,11 +1397,18 @@ public function providerForTestRenderLocationWithTemplate()
false,
new AccessDeniedException(),
[
- ['hasParameter', $namespace = 'test.name.space.embed.location_denied', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName1']],
+ [
+ [[$namespace = 'test.name.space.embed.location_denied']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName1']],
+ ],
],
[
- ['error', "Could not render embedded resource: access denied to embed Location #{$locationId}"],
+ [],
+ [["Could not render embedded resource: access denied to embed Location #{$locationId}"]],
],
$templateName,
$templateName,
@@ -1267,11 +1418,18 @@ public function providerForTestRenderLocationWithTemplate()
true,
new AccessDeniedException(),
[
- ['hasParameter', $namespace = 'test.name.space.embed.location_inline_denied', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName2']],
+ [
+ [[$namespace = 'test.name.space.embed.location_inline_denied']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName2']],
+ ],
],
[
- ['error', "Could not render embedded resource: access denied to embed Location #{$locationId}"],
+ [],
+ [["Could not render embedded resource: access denied to embed Location #{$locationId}"]],
],
$templateName,
$templateName,
@@ -1281,8 +1439,14 @@ public function providerForTestRenderLocationWithTemplate()
false,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.location', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName3']],
+ [
+ [[$namespace = 'test.name.space.embed.location']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName3']],
+ ],
],
[],
$templateName,
@@ -1293,8 +1457,14 @@ public function providerForTestRenderLocationWithTemplate()
true,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.location_inline', true],
- ['getParameter', $namespace, ['template' => $templateName = 'templateName4']],
+ [
+ [[$namespace = 'test.name.space.embed.location_inline']],
+ [true],
+ ],
+ [
+ [[$namespace]],
+ [['template' => $templateName = 'templateName4']],
+ ],
],
[],
$templateName,
@@ -1305,12 +1475,21 @@ public function providerForTestRenderLocationWithTemplate()
false,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.location', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default', true],
- ['getParameter', $namespace2, ['template' => $templateName = 'templateName5']],
+ [
+ [
+ [$namespace = 'test.name.space.embed.location'],
+ [$namespace2 = 'test.name.space.embed.default'],
+ ],
+ [false, true],
+ ],
+ [
+ [[$namespace2]],
+ [['template' => $templateName = 'templateName5']],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
+ [["Embed tag configuration '{$namespace}' was not found"]],
+ [],
],
$templateName,
$templateName,
@@ -1320,12 +1499,21 @@ public function providerForTestRenderLocationWithTemplate()
true,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.location_inline', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default_inline', true],
- ['getParameter', $namespace2, ['template' => $templateName = 'templateName6']],
+ [
+ [
+ [$namespace = 'test.name.space.embed.location_inline'],
+ [$namespace2 = 'test.name.space.embed.default_inline'],
+ ],
+ [false, true],
+ ],
+ [
+ [[$namespace2]],
+ [['template' => $templateName = 'templateName6']],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
+ [["Embed tag configuration '{$namespace}' was not found"]],
+ [],
],
$templateName,
$templateName,
@@ -1335,12 +1523,24 @@ public function providerForTestRenderLocationWithTemplate()
false,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.location', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default', false],
+ [
+ [
+ [$namespace = 'test.name.space.embed.location'],
+ [$namespace2 = 'test.name.space.embed.default'],
+ ],
+ [false, false],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
- ['warning', "Embed tag default configuration '{$namespace2}' was not found"],
+ [
+ ["Embed tag configuration '{$namespace}' was not found"],
+ ["Embed tag default configuration '{$namespace2}' was not found"],
+ ],
+ [],
],
null,
null,
@@ -1350,12 +1550,24 @@ public function providerForTestRenderLocationWithTemplate()
true,
null,
[
- ['hasParameter', $namespace = 'test.name.space.embed.location_inline', false],
- ['hasParameter', $namespace2 = 'test.name.space.embed.default_inline', false],
+ [
+ [
+ [$namespace = 'test.name.space.embed.location_inline'],
+ [$namespace2 = 'test.name.space.embed.default_inline'],
+ ],
+ [false, false],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
- ['warning', "Embed tag configuration '{$namespace}' was not found"],
- ['warning', "Embed tag default configuration '{$namespace2}' was not found"],
+ [
+ ["Embed tag configuration '{$namespace}' was not found"],
+ ["Embed tag default configuration '{$namespace2}' was not found"],
+ ],
+ [],
],
null,
null,
@@ -1435,17 +1647,24 @@ public function testRenderLocationWithTemplate(
->expects($this->never())
->method($this->anything());
} else {
- $i = 0;
- foreach ($configResolverParams as $params) {
- $method = $params[0];
- $namespace = $params[1];
- $returnValue = $params[2];
+ [$hasParameterValues, $getParameterValues] = $configResolverParams;
+ [$hasParameterArguments, $hasParameterReturnValues] = $hasParameterValues;
+ [$getParameterArguments, $getParameterReturnValues] = $getParameterValues;
+
+ if (!empty($hasParameterArguments)) {
+ $this->configResolverMock
+ ->expects($this->exactly(count($hasParameterArguments)))
+ ->method('hasParameter')
+ ->withConsecutive($hasParameterArguments[0])
+ ->willReturnOnConsecutiveCalls(...$hasParameterReturnValues);
+ }
+
+ if (!empty($getParameterArguments)) {
$this->configResolverMock
- ->expects($this->at($i))
- ->method($method)
- ->with($namespace)
- ->willReturn($returnValue);
- ++$i;
+ ->expects($this->exactly(count($getParameterArguments)))
+ ->method('getParameter')
+ ->withConsecutive($getParameterArguments[0])
+ ->willReturnOnConsecutiveCalls(...$getParameterReturnValues);
}
}
@@ -1454,15 +1673,20 @@ public function testRenderLocationWithTemplate(
->expects($this->never())
->method($this->anything());
} else {
- $i = 0;
- foreach ($loggerParams as $params) {
- $method = $params[0];
- $message = $params[1];
+ [$warningArguments, $errorArguments] = $loggerParams;
+
+ if (!empty($warningArguments)) {
+ $this->loggerMock
+ ->expects($this->exactly(count($warningArguments)))
+ ->method('warning')
+ ->withConsecutive(...$warningArguments);
+ }
+
+ if (!empty($errorArguments)) {
$this->loggerMock
- ->expects($this->at($i))
- ->method($method)
- ->with($message);
- ++$i;
+ ->expects($this->exactly(count($errorArguments)))
+ ->method('error')
+ ->withConsecutive(...$errorArguments);
}
}
@@ -1578,15 +1802,15 @@ protected function getContentMock($mainLocationId)
{
$contentInfoMock = $this->createMock(ContentInfo::class);
$contentInfoMock
- ->expects($this->at(0))
+ ->expects($this->exactly(2))
->method('__get')
- ->with('mainLocationId')
- ->willReturn($mainLocationId);
- $contentInfoMock
- ->expects($this->at(1))
- ->method('__get')
- ->with('isHidden')
- ->willReturn(false);
+ ->withConsecutive(
+ ['mainLocationId'],
+ ['isHidden'],
+ )->willReturnOnConsecutiveCalls(
+ $mainLocationId,
+ false
+ );
$contentMock = $this->createMock(Content::class);
$contentMock
diff --git a/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php b/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php
index 845fa838..af6e087b 100644
--- a/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php
+++ b/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php
@@ -568,7 +568,7 @@ public function providerForTestConvertRemoteObjectIdToObjectId()
*
* @dataProvider providerForTestConvertRemoteObjectIdToObjectId
*/
- public function testConvertRemoteObjectIdToObjectId($test, $expected)
+ public function testConvertRemoteObjectIdToObjectId($test, $expected): void
{
$repository = $this->getRepository();
@@ -630,7 +630,7 @@ public function testConvertRemoteObjectIdToObjectId($test, $expected)
);
$this->assertEquals(
- str_replace('[ObjectId]', $objectId, $expected),
+ str_replace('[ObjectId]', (string)$objectId, $expected),
$test->getField('description')->value->xml->saveXML()
);
}
diff --git a/tests/lib/Form/DataTransformer/RichTextTransformerTest.php b/tests/lib/Form/DataTransformer/RichTextTransformerTest.php
index d7d9fbd6..c12a356a 100644
--- a/tests/lib/Form/DataTransformer/RichTextTransformerTest.php
+++ b/tests/lib/Form/DataTransformer/RichTextTransformerTest.php
@@ -62,7 +62,7 @@ public function testTransform(): void
->expects($this->once())
->method('convert')
->willReturnCallback(function (DOMDocument $doc) use ($inputXML, $outputDocument) {
- $this->assertXmlStringEqualsXmlString($inputXML, $doc);
+ $this->assertXmlStringEqualsXmlString($inputXML, $doc->saveXML());
return $outputDocument;
});
diff --git a/tests/lib/Validator/Constraints/RichTextValidatorTest.php b/tests/lib/Validator/Constraints/RichTextValidatorTest.php
index c5d28efe..26060bb7 100644
--- a/tests/lib/Validator/Constraints/RichTextValidatorTest.php
+++ b/tests/lib/Validator/Constraints/RichTextValidatorTest.php
@@ -60,12 +60,9 @@ public function testValidateInvalidXMLString(): void
->with($xml)
->willThrowException($this->createInvalidXmlExceptionMock($expectedErrors));
- foreach ($expectedErrors as $i => $error) {
- $this->executionContext
- ->expects($this->at($i))
- ->method('addViolation')
- ->with($error->message);
- }
+ $this->executionContext
+ ->method('addViolation')
+ ->willReturnOnConsecutiveCalls($this->fetchErrorMessages($expectedErrors));
$this->inputHandler
->expects($this->never())
@@ -112,12 +109,10 @@ public function testValidateDOMDocument(): void
->with($doc)
->willReturn($expectedErrors);
- foreach ($expectedErrors as $i => $error) {
- $this->executionContext
- ->expects($this->at($i))
- ->method('addViolation')
- ->with($error);
- }
+ $this->executionContext
+ ->expects($this->exactly(count($expectedErrors)))
+ ->method('addViolation')
+ ->willReturnOnConsecutiveCalls($expectedErrors);
$this->validator->validate($doc, new RichText());
}
@@ -139,4 +134,11 @@ private function createLibXMLError(string $message): LibXMLError
return $error;
}
+
+ private function fetchErrorMessages(array $errors): array
+ {
+ return array_map(static function (LibXMLError $error) {
+ return $error->message;
+ }, $errors);
+ }
}
diff --git a/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php b/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php
index 01e338ee..4c9cd1e9 100644
--- a/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php
+++ b/tests/lib/eZ/FieldType/RichText/RichTextStorageTest.php
@@ -35,7 +35,7 @@ public function providerForTestGetFieldData()
'
- Existing external link
+ Existing external link
Non-existing external link
@@ -43,7 +43,7 @@ public function providerForTestGetFieldData()
',
[123, 456],
- [123 => 'http://www.ez.no'],
+ [123 => 'https://www.ibexa.co'],
],
[
'
@@ -64,7 +64,7 @@ public function providerForTestGetFieldData()
/**
* @dataProvider providerForTestGetFieldData
*/
- public function testGetFieldData($xmlString, $updatedXmlString, $linkIds, $linkUrls)
+ public function testGetFieldData($xmlString, $updatedXmlString, $linkIds, $linkUrls): void
{
$gateway = $this->getGatewayMock();
$gateway
@@ -72,26 +72,21 @@ public function testGetFieldData($xmlString, $updatedXmlString, $linkIds, $linkU
->method('getIdUrlMap')
->with($this->equalTo($linkIds))
->willReturn($linkUrls);
+
$gateway->expects($this->never())->method('getUrlIdMap');
$gateway->expects($this->never())->method('getContentIds');
$gateway->expects($this->never())->method('insertUrl');
$logger = $this->getLoggerMock();
+ $missingIds = array_diff($linkIds, array_keys($linkUrls));
+ $errorMessages = array_map(static function (int $missingId) {
+ return "URL with ID {$missingId} not found";
+ }, $missingIds);
- if (count($linkIds) !== count($linkUrls)) {
- $loggerInvocationCount = 0;
-
- foreach ($linkIds as $linkId) {
- if (!isset($linkUrls[$linkId])) {
- $logger
- ->expects($this->at($loggerInvocationCount))
- ->method('error')
- ->with("URL with ID {$linkId} not found");
- }
- }
- } else {
- $logger->expects($this->never())->method($this->anything());
- }
+ $logger
+ ->expects($this->exactly(count($missingIds)))
+ ->method('error')
+ ->withConsecutive($errorMessages);
$versionInfo = new VersionInfo();
$value = new FieldValue(['data' => $xmlString]);
@@ -120,16 +115,16 @@ public function providerForTestStoreFieldData()
Content link
- Existing external link
+ Existing external link
- Existing external link repeated
+ Existing external link repeated
- New external link
+ New external link
- New external link repeated
+ New external link repeated
',
'
@@ -151,9 +146,9 @@ public function providerForTestStoreFieldData()
',
- ['http://www.ez.no', 'http://share.ez.no'],
- ['http://www.ez.no' => 123],
- ['http://share.ez.no' => 456],
+ ['https://www.ibexa.co', 'https://developers.ibexa.co'],
+ ['https://www.ibexa.co' => 123],
+ ['https://developers.ibexa.co' => 456],
['abcdef789'],
['abcdef789' => 7575],
true,
@@ -190,55 +185,55 @@ public function testStoreFieldData(
$remoteIds,
$contentIds,
$isUpdated
- ) {
- $gatewayCallIndex = 0;
+ ): void {
$versionInfo = new VersionInfo(['versionNo' => 24]);
$value = new FieldValue(['data' => $xmlString]);
$field = new Field(['id' => 42, 'value' => $value]);
$gateway = $this->getGatewayMock();
+
$gateway
- ->expects($this->at($gatewayCallIndex++))
+ ->expects($this->once())
->method('getUrlIdMap')
->with($this->equalTo($linkUrls))
->willReturn($linkIds);
+
$gateway
- ->expects($this->at($gatewayCallIndex++))
+ ->expects($this->once())
->method('getContentIds')
->with($this->equalTo($remoteIds))
->willReturn($contentIds);
- $gateway->expects($this->never())->method('getIdUrlMap');
- if (empty($insertLinks)) {
- $gateway->expects($this->never())->method('insertUrl');
- }
- foreach ($linkUrls as $url) {
- if (isset($insertLinks[$url])) {
- $id = $insertLinks[$url];
- $gateway
- ->expects($this->at($gatewayCallIndex++))
- ->method('insertUrl')
- ->with($this->equalTo($url))
- ->willReturn($id);
- $linkIds[$url] = $id;
- } else {
- $id = $linkIds[$url];
- }
+ $gateway
+ ->expects($this->never())
+ ->method('getIdUrlMap');
+ if (empty($insertLinks)) {
$gateway
- ->expects($this->at($gatewayCallIndex++))
- ->method('linkUrl')
- ->with($id, 42, 24);
+ ->expects($this->never())
+ ->method('insertUrl');
}
+
+ [$urlAssertions, $insertedIds, $idsToLink] = $this->groupLinksData($linkUrls, $insertLinks, $linkIds);
+
+ $gateway
+ ->expects($this->exactly(count($urlAssertions)))
+ ->method('insertUrl')
+ ->withConsecutive($urlAssertions)
+ ->willReturnOnConsecutiveCalls(...$insertedIds);
+
+ $linkUrlsArguments = array_map(static function (int $id) {
+ return [$id, 42, 24];
+ }, $idsToLink);
+
$gateway
- ->expects($this->at($gatewayCallIndex))
+ ->expects($this->exactly(count($idsToLink)))
+ ->method('linkUrl')
+ ->withConsecutive(...$linkUrlsArguments);
+
+ $gateway
+ ->expects($this->once())
->method('unlinkUrl')
- ->with(
- 42,
- 24,
- array_values(
- $linkIds
- )
- );
+ ->with(42, 24, $idsToLink);
$storage = $this->getPartlyMockedStorage($gateway);
$result = $storage->storeFieldData(
@@ -257,7 +252,36 @@ public function testStoreFieldData(
);
}
- public function providerForTestStoreFieldDataThrowsNotFoundException()
+ /**
+ * @param string[] $linkUrls
+ * @param array $insertLinks
+ * @param array $linkIds
+ */
+ private function groupLinksData(array $linkUrls, array $insertLinks, array $linkIds): array
+ {
+ $urlAssertions = [];
+ $insertedIds = [];
+ $idsToLink = [];
+
+ foreach ($linkUrls as $url) {
+ if (isset($insertLinks[$url])) {
+ $id = $insertLinks[$url];
+ $urlAssertions[] = $this->equalTo($url);
+ $insertedIds[] = $id;
+ $idsToLink[] = $id;
+ } else {
+ $idsToLink[] = $linkIds[$url];
+ }
+ }
+
+ return [
+ $urlAssertions,
+ $insertedIds,
+ $idsToLink,
+ ];
+ }
+
+ public function providerForTestStoreFieldDataThrowsNotFoundException(): array
{
return [
[
@@ -287,7 +311,7 @@ public function testStoreFieldDataThrowsNotFoundException(
$insertLinks,
$remoteIds,
$contentIds
- ) {
+ ): void {
$this->expectException(NotFoundException::class);
$gateway = $this->getGatewayMock();
@@ -326,21 +350,19 @@ public function testStoreFieldDataThrowsNotFoundException(
);
}
- public function testDeleteFieldData()
+ public function testDeleteFieldData(): void
{
$versionInfo = new VersionInfo(['versionNo' => 42]);
$fieldIds = [12, 23];
$gateway = $this->getGatewayMock();
$storage = $this->getPartlyMockedStorage($gateway);
$gateway
- ->expects($this->at(0))
+ ->expects($this->exactly(2))
->method('unlinkUrl')
- ->with(12, 42);
-
- $gateway
- ->expects($this->at(1))
- ->method('unlinkUrl')
- ->with(23, 42);
+ ->withConsecutive(
+ [12, 42],
+ [23, 42],
+ );
$storage->deleteFieldData(
$versionInfo,
diff --git a/tests/lib/eZ/RichText/Converter/Render/EmbedTest.php b/tests/lib/eZ/RichText/Converter/Render/EmbedTest.php
index 798c15b0..4b1615b9 100644
--- a/tests/lib/eZ/RichText/Converter/Render/EmbedTest.php
+++ b/tests/lib/eZ/RichText/Converter/Render/EmbedTest.php
@@ -50,15 +50,23 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed',
+ ],
+ ],
+ 'is_inline' => false,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -78,28 +86,36 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed',
- 'link' => [
- 'href' => 'RESOLVED',
- 'resourceType' => 'URL',
- 'resourceId' => null,
- 'wrapped' => false,
- 'target' => '_blank',
- 'title' => 'Link title',
- 'id' => 'link-id-1',
- 'class' => 'link-class',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed',
+ 'link' => [
+ 'href' => 'RESOLVED',
+ 'resourceType' => 'URL',
+ 'resourceId' => null,
+ 'wrapped' => false,
+ 'target' => '_blank',
+ 'title' => 'Link title',
+ 'id' => 'link-id-1',
+ 'class' => 'link-class',
+ ],
+ 'class' => 'embed-class',
+ 'align' => 'left',
+ 'anchor' => 'embed-id-1',
+ ],
],
- 'class' => 'embed-class',
- 'align' => 'left',
- 'anchor' => 'embed-id-1',
+ 'is_inline' => false,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -143,31 +159,39 @@ public function providerForTestConvert(): array
',
[],
+ [
+ [],
+ [],
+ ],
[
[
- 'method' => 'renderLocationEmbed',
- 'id' => '601',
- 'viewType' => 'embed-inline',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '601',
'viewType' => 'embed-inline',
- 'config' => [
- 'size' => 'medium',
- 'offset' => 10,
- 'limit' => 5,
- 'hey' => [
- 'look' => [
- 'at' => [
- 'this' => 'wohoo',
- 'that' => 'weeee',
+ [
+ 'embedParams' => [
+ 'id' => '601',
+ 'viewType' => 'embed-inline',
+ 'config' => [
+ 'size' => 'medium',
+ 'offset' => 10,
+ 'limit' => 5,
+ 'hey' => [
+ 'look' => [
+ 'at' => [
+ 'this' => 'wohoo',
+ 'that' => 'weeee',
+ ],
+ ],
+ 'what' => 'get to the chopper',
],
],
- 'what' => 'get to the chopper',
],
],
+ 'is_inline' => false,
],
],
+ ['601'],
],
],
[
@@ -213,39 +237,47 @@ public function providerForTestConvert(): array
',
[],
+ [
+ [],
+ [],
+ ],
[
[
- 'method' => 'renderLocationEmbed',
- 'id' => '601',
- 'viewType' => 'embed-inline',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '601',
'viewType' => 'embed-inline',
- 'config' => [
- 'size' => 'medium',
- 'offset' => 10,
- 'limit' => 5,
- 'hey' => [
- 'look' => [
- 'at' => [
- 'this' => 'wohoo',
- 'that' => 'weeee',
+ [
+ 'embedParams' => [
+ 'id' => '601',
+ 'viewType' => 'embed-inline',
+ 'config' => [
+ 'size' => 'medium',
+ 'offset' => 10,
+ 'limit' => 5,
+ 'hey' => [
+ 'look' => [
+ 'at' => [
+ 'this' => 'wohoo',
+ 'that' => 'weeee',
+ ],
+ ],
+ 'what' => 'get to the chopper',
],
],
- 'what' => 'get to the chopper',
+ 'link' => [
+ 'href' => 'RESOLVED',
+ 'resourceType' => 'CONTENT',
+ 'resourceId' => '95',
+ 'resourceFragmentIdentifier' => 'fragment1',
+ 'wrapped' => false,
+ 'target' => '_self',
+ ],
],
],
- 'link' => [
- 'href' => 'RESOLVED',
- 'resourceType' => 'CONTENT',
- 'resourceId' => '95',
- 'resourceFragmentIdentifier' => 'fragment1',
- 'wrapped' => false,
- 'target' => '_self',
- ],
+ 'is_inline' => false,
],
],
+ ['601'],
],
],
[
@@ -266,25 +298,35 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderLocationEmbed',
- 'id' => '601',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
- 'id' => '601',
- 'viewType' => 'embed',
+ [
+ 'id' => '106',
+ 'viewType' => 'full',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'full',
+ ],
+ ],
+ 'is_inline' => true,
],
],
+ ['106'],
+ ],
+ [
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'full',
- 'is_inline' => true,
- 'embedParams' => [
- 'id' => '106',
- 'viewType' => 'full',
+ [
+ 'id' => '601',
+ 'viewType' => 'embed',
+ [
+ 'embedParams' => [
+ 'id' => '601',
+ 'viewType' => 'embed',
+ ],
+ ],
+ 'is_inline' => false,
],
],
+ ['601'],
],
],
[
@@ -323,44 +365,54 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderLocationEmbed',
- 'id' => '601',
- 'viewType' => 'embed',
- 'is_inline' => true,
- 'embedParams' => [
- 'id' => '601',
- 'viewType' => 'embed',
- 'config' => [
- 'size' => 'medium',
- ],
- 'link' => [
- 'href' => 'RESOLVED',
- 'resourceType' => 'CONTENT',
- 'resourceId' => '95',
- 'wrapped' => false,
+ [
+ 'id' => '106',
+ 'viewType' => 'full',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'full',
+ 'config' => [
+ 'size' => 'small',
+ ],
+ 'link' => [
+ 'href' => 'RESOLVED2',
+ 'resourceType' => 'LOCATION',
+ 'resourceId' => '59',
+ 'resourceFragmentIdentifier' => 'fragment',
+ 'wrapped' => true,
+ ],
+ ],
],
+ 'is_inline' => true,
],
],
+ ['106'],
+ ],
+ [
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'full',
- 'is_inline' => true,
- 'embedParams' => [
- 'id' => '106',
- 'viewType' => 'full',
- 'config' => [
- 'size' => 'small',
- ],
- 'link' => [
- 'href' => 'RESOLVED2',
- 'resourceType' => 'LOCATION',
- 'resourceId' => '59',
- 'resourceFragmentIdentifier' => 'fragment',
- 'wrapped' => true,
+ [
+ 'id' => '601',
+ 'viewType' => 'embed',
+ [
+ 'embedParams' => [
+ 'id' => '601',
+ 'viewType' => 'embed',
+ 'config' => [
+ 'size' => 'medium',
+ ],
+ 'link' => [
+ 'href' => 'RESOLVED',
+ 'resourceType' => 'CONTENT',
+ 'resourceId' => '95',
+ 'wrapped' => false,
+ ],
+ ],
],
+ 'is_inline' => true,
],
],
+ ['601'],
],
],
[
@@ -375,7 +427,14 @@ public function providerForTestConvert(): array
[
"Could not embed resource: empty 'xlink:href' attribute",
],
- [],
+ [
+ [],
+ [],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
'
@@ -389,7 +448,14 @@ public function providerForTestConvert(): array
[
"Could not embed resource: unhandled resource reference 'eznodeassignment://106'",
],
- [],
+ [
+ [],
+ [],
+ ],
+ [
+ [],
+ [],
+ ],
],
[
'
@@ -410,15 +476,23 @@ public function providerForTestConvert(): array
],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed',
+ ],
+ ],
+ 'is_inline' => false,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -435,15 +509,23 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed',
+ ],
+ ],
+ 'is_inline' => false,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -460,15 +542,23 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed-inline',
- 'is_inline' => true,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed-inline',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed-inline',
+ ],
+ ],
+ 'is_inline' => true,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -504,19 +594,27 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed-inline',
- 'is_inline' => true,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed-inline',
- 'dataAttributes' => [
- 'inline-choice-attr' => 'choice1',
- 'inline-choice-mul-attr' => 'choice2,choice3',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed-inline',
+ 'dataAttributes' => [
+ 'inline-choice-attr' => 'choice1',
+ 'inline-choice-mul-attr' => 'choice2,choice3',
+ ],
+ ],
],
+ 'is_inline' => true,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -542,19 +640,27 @@ public function providerForTestConvert(): array
[],
[
[
- 'method' => 'renderContentEmbed',
- 'id' => '106',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '106',
'viewType' => 'embed',
- 'dataAttributes' => [
- 'inline-choice-attr' => 'choice1',
- 'inline-choice-mul-attr' => 'choice2,choice3',
+ [
+ 'embedParams' => [
+ 'id' => '106',
+ 'viewType' => 'embed',
+ 'dataAttributes' => [
+ 'inline-choice-attr' => 'choice1',
+ 'inline-choice-mul-attr' => 'choice2,choice3',
+ ],
+ ],
],
+ 'is_inline' => false,
],
],
+ ['106'],
+ ],
+ [
+ [],
+ [],
],
],
[
@@ -584,6 +690,7 @@ public function providerForTestConvert(): array
value2
+
value1
@@ -596,20 +703,42 @@ public function providerForTestConvert(): array
',
[],
+ [
+ [],
+ [],
+ ],
[
[
- 'method' => 'renderLocationEmbed',
- 'id' => '601',
- 'viewType' => 'embed',
- 'is_inline' => false,
- 'embedParams' => [
+ [
'id' => '601',
'viewType' => 'embed',
- 'config' => [
- 'parent' => 'value1',
+ [
+ 'embedParams' => [
+ 'id' => '601',
+ 'viewType' => 'embed',
+ 'config' => [
+ 'parent' => 'value1',
+ ],
+ ],
+ ],
+ 'is_inline' => false,
+ ],
+ [
+ 'id' => '602',
+ 'viewType' => 'embed',
+ [
+ 'embedParams' => [
+ 'id' => 602,
+ 'viewType' => 'embed',
+ 'config' => [
+ 'nested' => 'value2',
+ ],
+ ],
],
+ 'is_inline' => false,
],
],
+ ['601', '602'],
],
],
];
@@ -621,45 +750,40 @@ public function providerForTestConvert(): array
* @param string $xmlString
* @param string $expectedXmlString
* @param array $errors
- * @param array $renderParams
+ * @param array $renderContentEmbedParams
+ * @param array $renderLocationEmbedParams
*/
public function testConvert(
string $xmlString,
string $expectedXmlString,
array $errors,
- array $renderParams
- ) {
- if (isset($errors)) {
- foreach ($errors as $index => $error) {
- $this->loggerMock
- ->expects($this->at($index))
- ->method('error')
- ->with($error);
- }
- } else {
- $this->loggerMock->expects($this->never())->method('error');
- }
+ array $renderContentEmbedParams,
+ array $renderLocationEmbedParams
+ ): void {
+ $this->loggerMock
+ ->expects($this->exactly(count($errors)))
+ ->method('error')
+ ->withConsecutive($errors);
$this->rendererMock->expects($this->never())->method('renderTemplate');
- if (!empty($renderParams)) {
- foreach ($renderParams as $index => $params) {
- $this->rendererMock
- ->expects($this->at($index))
- ->method($params['method'])
- ->with(
- $params['id'],
- $params['viewType'],
- [
- 'embedParams' => $params['embedParams'],
- ],
- $params['is_inline']
- )
- ->willReturn($params['id']);
- }
- } else {
- $this->rendererMock->expects($this->never())->method('renderContentEmbed');
- $this->rendererMock->expects($this->never())->method('renderLocationEmbed');
+ [$embedContentParams, $embedContentReturnValues] = $renderContentEmbedParams;
+ [$embedLocationParams, $embedLocationReturnValues] = $renderLocationEmbedParams;
+
+ if (!empty($embedContentParams)) {
+ $this->rendererMock
+ ->expects($this->exactly(count($embedContentParams)))
+ ->method('renderContentEmbed')
+ ->withConsecutive(...$embedContentParams)
+ ->willReturnOnConsecutiveCalls(...$embedContentReturnValues);
+ }
+
+ if (!empty($embedLocationParams)) {
+ $this->rendererMock
+ ->expects($this->exactly(count($embedLocationParams)))
+ ->method('renderLocationEmbed')
+ ->withConsecutive(...$embedLocationParams)
+ ->willReturnOnConsecutiveCalls(...$embedLocationReturnValues);
}
$document = new DOMDocument();
diff --git a/tests/lib/eZ/RichText/Converter/Render/TemplateTest.php b/tests/lib/eZ/RichText/Converter/Render/TemplateTest.php
index bfa2b190..21e71dc1 100644
--- a/tests/lib/eZ/RichText/Converter/Render/TemplateTest.php
+++ b/tests/lib/eZ/RichText/Converter/Render/TemplateTest.php
@@ -76,58 +76,84 @@ public function providerForTestConvert()
/**
* @dataProvider providerForTestConvert
*/
- public function testConvert(DOMDocument $inputDocument, DOMDocument $expectedOutputDocument, array $expectedRenderParams)
- {
+ public function testConvert(
+ DOMDocument $inputDocument,
+ DOMDocument $expectedOutputDocument,
+ array $expectedRenderParams
+ ): void {
$this->rendererMock->expects($this->never())->method('renderContentEmbed');
$this->rendererMock->expects($this->never())->method('renderLocationEmbed');
- if (!empty($expectedRenderParams)) {
- $convertIndex = 0;
- foreach ($expectedRenderParams as $index => $params) {
- if (!empty($params['params']['content'])) {
- // mock simple converter
- $contentDoc = new DOMDocument();
-
- $xml = '';
- $xml .= $params['params']['content'];
- $xml .= '';
-
- $params['params']['content'] = $xml;
-
- $fragment = $contentDoc->createDocumentFragment();
- $fragment->appendXML($xml);
-
- $contentDoc->appendChild($fragment);
-
- $this->converterMock
- ->expects($this->at($convertIndex++))
- ->method('convert')
- ->with($contentDoc)
- ->willReturn($contentDoc);
- } else {
- $params['params']['content'] = null;
- }
-
- $this->rendererMock
- ->expects($this->at($index))
- ->method('renderTemplate')
- ->with(
- $params['name'],
- isset($params['type']) ? $params['type'] : 'tag',
- $params['params'],
- $params['is_inline']
- )
- ->willReturn($params['name']);
- }
- } else {
- $this->rendererMock->expects($this->never())->method('renderTemplate');
- }
+ [
+ $convertParameters,
+ $convertReturnValues,
+ $renderParameters,
+ $renderReturnValues
+ ] = $this->provideConvertRenderValues($expectedRenderParams);
+
+ $this->converterMock
+ ->expects($this->exactly(count($convertReturnValues)))
+ ->method('convert')
+ ->withConsecutive(...$convertParameters)
+ ->willReturnOnConsecutiveCalls(...$convertReturnValues);
+
+ $this->rendererMock
+ ->expects($this->exactly(count($renderReturnValues)))
+ ->method('renderTemplate')
+ ->withConsecutive(...$renderParameters)
+ ->willReturnOnConsecutiveCalls(...$renderReturnValues);
$outputDocument = $this->getConverter()->convert($inputDocument);
$this->assertEquals($expectedOutputDocument, $outputDocument);
}
+ private function provideConvertRenderValues(array $expectedValues): array
+ {
+ $convertParameters = [];
+ $convertReturnValues = [];
+ $renderParameters = [];
+ $renderReturnValues = [];
+
+ foreach ($expectedValues as $values) {
+ if (!empty($values['params']['content'])) {
+ $contentDoc = new DOMDocument();
+
+ $xml = '';
+ $xml .= $values['params']['content'];
+ $xml .= '';
+
+ $values['params']['content'] = $xml;
+
+ $fragment = $contentDoc->createDocumentFragment();
+ $fragment->appendXML($xml);
+
+ $contentDoc->appendChild($fragment);
+
+ $convertParameters[] = [$contentDoc];
+ $convertReturnValues[] = $contentDoc;
+ } else {
+ $values['params']['content'] = null;
+ }
+
+ $renderParameters[] = [
+ $values['name'],
+ $values['type'] ?? 'tag',
+ $values['params'],
+ $values['is_inline'],
+ ];
+
+ $renderReturnValues[] = $values['name'];
+ }
+
+ return [
+ $convertParameters,
+ $convertReturnValues,
+ $renderParameters,
+ $renderReturnValues,
+ ];
+ }
+
protected function getConverter()
{
return new Template(
@@ -158,7 +184,7 @@ protected function getConverterMock()
/**
* Expected Template parameters for each test fixture (key is a fixture name).
*/
- const FIXTURES_PARAMETERS = [
+ public const FIXTURES_PARAMETERS = [
'00-block' => [
[
'name' => 'template1',