From f5ec72d3245836edf4c3873eea8131ff2a7e68bf Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 11 Sep 2019 18:27:38 -0400 Subject: [PATCH] AfformTest - Test two example documents thoroughly for consistent conversions --- .../mock/tests/phpunit/api/v4/AfformTest.php | 44 ++++++------------- .../phpunit/api/v4/formatExamples/apple.php | 7 +++ .../phpunit/api/v4/formatExamples/banana.php | 19 ++++++++ 3 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php create mode 100644 ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php index 05cf0a3b73..7869a44818 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php @@ -63,34 +63,16 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { public function getFormatExamples() { $es = []; - $asHtml = '
New text!
'; - $asShallow = [ - '#tag' => 'div', - '#children' => [ - ['#tag' => 'strong', '#children' => ['New text!']], - ['#tag' => 'af-field', 'field-name' => 'do_not_sms', 'field-defn' => "{label: 'Do not do any of the emailing'}"], - ], - ]; - $asDeep = [ - '#tag' => 'div', - '#children' => [ - ['#tag' => 'strong', '#children' => ['New text!']], - ['#tag' => 'af-field', 'field-name' => 'do_not_sms', 'field-defn' => ['label' => 'Do not do any of the emailing']], - ], - ]; - - $es[] = ['fakelibBareFile', 'html', $asHtml, 'html', $asHtml]; - - $es[] = ['fakelibBareFile', 'html', $asHtml, 'shallow', $asShallow]; - $es[] = ['fakelibBareFile', 'shallow', $asShallow, 'html', $asHtml]; - $es[] = ['fakelibBareFile', 'shallow', $asShallow, 'shallow', $asShallow]; - - $es[] = ['fakelibBareFile', 'html', $asHtml, 'deep', $asDeep]; - $es[] = ['fakelibBareFile', 'deep', $asDeep, 'html', $asHtml]; - $es[] = ['fakelibBareFile', 'deep', $asDeep, 'deep', $asDeep]; - - $es[] = ['fakelibBareFile', 'shallow', $asShallow, 'deep', $asDeep]; - $es[] = ['fakelibBareFile', 'deep', $asDeep, 'shallow', $asShallow]; + foreach (['apple', 'banana'] as $exampleName) { + $exampleFile = '/formatExamples/' . $exampleName . '.php'; + $example = require __DIR__ . $exampleFile; + $formats = ['html', 'shallow', 'deep']; + foreach ($formats as $updateFormat) { + foreach ($formats as $readFormat) { + $es[] = ['fakelibBareFile', $updateFormat, $example[$updateFormat], $readFormat, $example[$readFormat], $exampleFile]; + } + } + } return $es; } @@ -110,9 +92,11 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { * 'html' or 'array' * @param mixed $readLayout * The value that we expect to read. + * @param string $exampleName + * (For debug messages) A symbolic name of the example data-set being tested. * @dataProvider getFormatExamples */ - public function testUpdateAndGetFormat($directiveName, $updateFormat, $updateLayout, $readFormat, $readLayout) { + public function testUpdateAndGetFormat($directiveName, $updateFormat, $updateLayout, $readFormat, $readLayout, $exampleName) { Civi\Api4\Afform::revert()->addWhere('name', '=', $directiveName)->execute(); Civi\Api4\Afform::update() @@ -126,7 +110,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { ->setLayoutFormat($readFormat) ->execute(); - $this->assertEquals($readLayout, $result[0]['layout']); + $this->assertEquals($readLayout, $result[0]['layout'], "Based on \"$exampleName\", writing content as \"$updateFormat\" and reading back as \"$readFormat\"."); Civi\Api4\Afform::revert()->addWhere('name', '=', $directiveName)->execute(); } diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php new file mode 100644 index 0000000000..e5e41acd24 --- /dev/null +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php @@ -0,0 +1,7 @@ + 'New text!', + 'shallow' => ['#tag' => 'strong', '#children' => ['New text!']], + 'deep' => ['#tag' => 'strong', '#children' => ['New text!']], +]; diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php new file mode 100644 index 0000000000..7b75b8b9af --- /dev/null +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php @@ -0,0 +1,19 @@ + '
New text!
', + 'shallow' => [ + '#tag' => 'div', + '#children' => [ + ['#tag' => 'strong', '#children' => ['New text!']], + ['#tag' => 'af-field', 'field-name' => 'do_not_sms', 'field-defn' => "{label: 'Do not do any of the emailing'}"], + ], + ], + 'deep' => [ + '#tag' => 'div', + '#children' => [ + ['#tag' => 'strong', '#children' => ['New text!']], + ['#tag' => 'af-field', 'field-name' => 'do_not_sms', 'field-defn' => ['label' => 'Do not do any of the emailing']], + ], + ], +]; -- 2.25.1