X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FCore%2FRegionTest.php;h=3c1ef2f4c9d339fb522238864b9510dd87759421;hb=c67a59391d975837bfe40d1d6014b1ed91b72b73;hp=b4ed3894edef8d826ac0c3fd3562303c84203464;hpb=850d8c7cf555cdb11176418b2d1ecd035eddcb14;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Core/RegionTest.php b/tests/phpunit/CRM/Core/RegionTest.php index b4ed3894ed..3c1ef2f4c9 100644 --- a/tests/phpunit/CRM/Core/RegionTest.php +++ b/tests/phpunit/CRM/Core/RegionTest.php @@ -8,12 +8,12 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - require_once 'CRM/Core/Smarty.php'; - require_once 'CRM/Core/Region.php'; // Templates injected into regions should normally be file names, but for unit-testing it's handy to use "string:" notation require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); + + $this->useTransaction(); } /** @@ -42,12 +42,12 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Disable the normal content of a {crmRegion} and apply different content from a snippet */ public function testOverride() { - CRM_Core_Region::instance('testOverride')->update('default', array( + CRM_Core_Region::instance('testOverride')->update('default', [ 'disabled' => TRUE, - )); - CRM_Core_Region::instance('testOverride')->add(array( + ]); + CRM_Core_Region::instance('testOverride')->add([ 'markup' => 'override
', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testOverride}default
{/crmRegion}'); @@ -59,46 +59,46 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Test that each of the major content formats are correctly evaluated. */ public function testAllTypes() { - CRM_Core_Region::instance('testAllTypes')->add(array( + CRM_Core_Region::instance('testAllTypes')->add([ 'markup' => 'some-markup
', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: 'template' would normally be a file name 'template' => 'string:smarty-is-{$snippet.extrainfo}
', 'extrainfo' => 'dynamic', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: returns a value which gets appended to the region 'callback' => 'implode', - 'arguments' => array('-', array('callback', 'with', 'specific', 'args
')), - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + 'arguments' => ['-', ['callback', 'with', 'specific', 'args
']], + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: returns a value which gets appended to the region 'callback' => function(&$spec, &$html) { return "callback-return
"; }, - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ // note: returns void; directly modifies region's $html 'callback' => function(&$spec, &$html) { $html = "callback-ref
" . $html; }, - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'scriptUrl' => '/foo%20bar.js', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'script' => 'alert("hi");', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'jquery' => '$("div");', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'styleUrl' => '/foo%20bar.css', - )); - CRM_Core_Region::instance('testAllTypes')->add(array( + ]); + CRM_Core_Region::instance('testAllTypes')->add([ 'style' => 'body { background: black; }', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testAllTypes}default
{/crmRegion}'); @@ -120,23 +120,23 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Test of nested arrangement in which one {crmRegion} directly includes another {crmRegion} */ public function testDirectNest() { - CRM_Core_Region::instance('testDirectNestOuter')->add(array( + CRM_Core_Region::instance('testDirectNestOuter')->add([ 'template' => 'string:O={$snippet.weight} ', 'weight' => -5, - )); - CRM_Core_Region::instance('testDirectNestOuter')->add(array( + ]); + CRM_Core_Region::instance('testDirectNestOuter')->add([ 'template' => 'string:O={$snippet.weight} ', 'weight' => 5, - )); + ]); - CRM_Core_Region::instance('testDirectNestInner')->add(array( + CRM_Core_Region::instance('testDirectNestInner')->add([ 'template' => 'string:I={$snippet.weight} ', 'weight' => -5, - )); - CRM_Core_Region::instance('testDirectNestInner')->add(array( + ]); + CRM_Core_Region::instance('testDirectNestInner')->add([ 'template' => 'string:I={$snippet.weight} ', 'weight' => 5, - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testDirectNestOuter}left {crmRegion name=testDirectNestInner}middle {/crmRegion}right {/crmRegion}'); @@ -148,15 +148,15 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Test of nested arrangement in which one {crmRegion} is enhanced with a snippet which, in turn, includes another {crmRegion} */ public function testIndirectNest() { - CRM_Core_Region::instance('testIndirectNestOuter')->add(array( + CRM_Core_Region::instance('testIndirectNestOuter')->add([ // Note: all three $snippet references are bound to the $snippet which caused this template to be included, // regardless of any nested {crmRegion}s 'template' => 'string: O={$snippet.region}{crmRegion name=testIndirectNestInner} O={$snippet.region}{/crmRegion} O={$snippet.region}', - )); + ]); - CRM_Core_Region::instance('testIndirectNestInner')->add(array( + CRM_Core_Region::instance('testIndirectNestInner')->add([ 'template' => 'string: I={$snippet.region}', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testIndirectNestOuter}default{/crmRegion}'); @@ -168,14 +168,14 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { * Output from an inner-region should not be executed verbatim; this is obvious but good to verify */ public function testNoInjection() { - CRM_Core_Region::instance('testNoInjectionOuter')->add(array( + CRM_Core_Region::instance('testNoInjectionOuter')->add([ 'template' => 'string:{$snippet.scarystuff} ', 'scarystuff' => '{$is_outer_scary}', - )); - CRM_Core_Region::instance('testNoInjectionInner')->add(array( + ]); + CRM_Core_Region::instance('testNoInjectionInner')->add([ 'template' => 'string:{$snippet.scarystuff} ', 'scarystuff' => '{$is_inner_scary}', - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('is_outer_scary', 'egad'); @@ -193,14 +193,14 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { public function testSmartyVars() { $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('extrainfo', 'one'); - CRM_Core_Region::instance('testSmartyVars')->add(array( + CRM_Core_Region::instance('testSmartyVars')->add([ 'template' => 'string:var-style-{$extrainfo}
', - )); + ]); - CRM_Core_Region::instance('testSmartyVars')->add(array( + CRM_Core_Region::instance('testSmartyVars')->add([ 'template' => 'string:var-style-{$snippet.extrainfo}
', 'extrainfo' => 'two', - )); + ]); $actual = $smarty->fetch('string:{crmRegion name=testSmartyVars}default
{/crmRegion}'); $expected = 'default
var-style-one
var-style-two
'; @@ -208,22 +208,22 @@ class CRM_Core_RegionTest extends CiviUnitTestCase { } public function testWeight() { - CRM_Core_Region::instance('testWeight')->add(array( + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'prepend-5
', 'weight' => -5, - )); - CRM_Core_Region::instance('testWeight')->add(array( + ]); + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'append+3
', 'weight' => 3, - )); - CRM_Core_Region::instance('testWeight')->add(array( + ]); + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'prepend-3
', 'weight' => -3, - )); - CRM_Core_Region::instance('testWeight')->add(array( + ]); + CRM_Core_Region::instance('testWeight')->add([ 'markup' => 'append+5
', 'weight' => 5, - )); + ]); $smarty = CRM_Core_Smarty::singleton(); $actual = $smarty->fetch('string:{crmRegion name=testWeight}default
{/crmRegion}');