Merge pull request #16541 from bhahumanists/subtype-issue-991
[civicrm-core.git] / tests / phpunit / CRM / Core / PageTest.php
1 <?php
2
3 /**
4 * Class CRM_Core_PageTest
5 * @group headless
6 */
7 class CRM_Core_PageTest extends CiviUnitTestCase {
8
9 /**
10 * Test data for testMakeIcons
11 *
12 * @return array
13 */
14 public function iconTestData() {
15 // first item is icon, text, condition, and attribs, second is expected markup
16 return [
17 [
18 '<i aria-hidden="true" title="We have a winner" class="crm-i fa-trophy"></i><span class="sr-only">We have a winner</span>',
19 ['fa-trophy', 'We have a winner', TRUE, []],
20 '{icon icon="fa-trophy"}We have a winner{/icon}',
21 ],
22 [
23 '',
24 ['fa-trophy', 'We have a winner', 0, []],
25 '{icon icon="fa-trophy" condition=0}We have a winner{/icon}',
26 ],
27 [
28 '<i aria-hidden="true" title="Favorite" class="action-icon test-icon crm-i fa-heart"></i><span class="sr-only">Favorite</span>',
29 ['fa-heart', 'Favorite', TRUE, ['class' => 'action-icon test-icon']],
30 '{icon icon="fa-heart" class="action-icon test-icon"}Favorite{/icon}',
31 ],
32 [
33 '<i aria-hidden="true" title="I &quot;choo-choo&quot; choose you" class="crm-i fa-train"></i><span class="sr-only">I "choo-choo" choose you</span>',
34 ['fa-train', 'I "choo-choo" choose you', TRUE, []],
35 '{icon icon="fa-train"}I "choo-choo" choose you{/icon}',
36 ],
37 [
38 '<i aria-hidden="true" class="crm-i fa-trash"></i><span class="sr-only">Trash</span>',
39 ['fa-trash', 'Trash', TRUE, ['title' => '']],
40 '{icon icon="fa-trash" title=""}Trash{/icon}',
41 ],
42 [
43 '<i title="It\'s bedtime" class="crm-i fa-bed"></i><span class="sr-only">It\'s bedtime</span>',
44 ['fa-bed', "It's bedtime", TRUE, ['aria-hidden' => '']],
45 // Ye olde Smarty 2 doesn't support hyphenated function parameters
46 ],
47 [
48 '<i aria-hidden="true" class="crm-i fa-snowflake-o"></i>',
49 ['fa-snowflake-o', NULL, TRUE, []],
50 '{icon icon="fa-snowflake-o"}{/icon}',
51 ],
52 ];
53 }
54
55 /**
56 * Test that icons are formed properly
57 *
58 * @param string $expectedMarkup
59 * @param array $params
60 * @param string $smartyFunc
61 * @dataProvider iconTestData
62 */
63 public function testMakeIcons($expectedMarkup, $params, $smartyFunc = '') {
64 list($icon, $text, $condition, $attribs) = $params;
65 $this->assertEquals($expectedMarkup, CRM_Core_Page::crmIcon($icon, $text, $condition, $attribs));
66 if (!empty($smartyFunc)) {
67 $smarty = CRM_Core_Smarty::singleton();
68 $actual = $smarty->fetch('string:' . $smartyFunc);
69 $this->assertEquals($expectedMarkup, $actual, "Process input=[$smartyFunc]");
70 }
71 }
72
73 }