Commit | Line | Data |
---|---|---|
d1e4cc3f TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
d1e4cc3f | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
d1e4cc3f TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | namespace Civi\Angular; | |
13 | ||
14 | /** | |
15 | * Ensure that all Angular *.html partials are well-formed. | |
16 | */ | |
17 | class PartialSyntaxTest extends \CiviUnitTestCase { | |
18 | ||
19 | /** | |
20 | * @var Manager | |
21 | */ | |
22 | protected $angular; | |
23 | ||
24 | /** | |
25 | * @var \CRM_Core_Resources | |
26 | */ | |
27 | protected $res; | |
28 | ||
29 | /** | |
30 | * @inheritDoc | |
31 | */ | |
32 | protected function setUp() { | |
33 | $this->useTransaction(TRUE); | |
34 | parent::setUp(); | |
35 | $this->createLoggedInUser(); | |
36 | $this->res = \CRM_Core_Resources::singleton(); | |
37 | $this->angular = new Manager($this->res); | |
38 | } | |
39 | ||
40 | public function basicConsistencyExamples() { | |
9099cab3 | 41 | $cases = []; |
d1e4cc3f | 42 | |
9099cab3 | 43 | $cases[0] = [ |
d1e4cc3f TO |
44 | '<div foo="bar"></div>', |
45 | '<div foo="bar"></div>', | |
9099cab3 CW |
46 | ]; |
47 | $cases[1] = [ | |
d1e4cc3f TO |
48 | '<div foo="bar"/>', |
49 | '<div foo="bar"></div>', | |
9099cab3 CW |
50 | ]; |
51 | $cases[2] = [ | |
d1e4cc3f TO |
52 | '<div foo=\'bar\'></div>', |
53 | '<div foo="bar"></div>', | |
9099cab3 CW |
54 | ]; |
55 | $cases[3] = [ | |
d1e4cc3f TO |
56 | '<div foo=\'ts("Hello world")\'></div>', |
57 | '<div foo=\'ts("Hello world")\'></div>', | |
9099cab3 CW |
58 | ]; |
59 | $cases[4] = [ | |
d1e4cc3f TO |
60 | '<div foo="ts(\'Hello world\')\"></div>', |
61 | '<div foo="ts(\'Hello world\')\"></div>', | |
9099cab3 CW |
62 | ]; |
63 | $cases[5] = [ | |
d1e4cc3f TO |
64 | '<a href="{{foo}}" title="{{bar}}"></a>', |
65 | '<a href="{{foo}}" title="{{bar}}"></a>', | |
9099cab3 CW |
66 | ]; |
67 | $cases[6] = [ | |
d1e4cc3f TO |
68 | '<div ng-if="a && b"></div>', |
69 | '<div ng-if="a && b"></div>', | |
9099cab3 | 70 | ]; |
d1e4cc3f TO |
71 | |
72 | return $cases; | |
73 | } | |
74 | ||
75 | /** | |
76 | * @param string $inputHtml | |
77 | * @param string $expectHtml | |
78 | * @dataProvider basicConsistencyExamples | |
79 | */ | |
80 | public function testConsistencyExamples($inputHtml, $expectHtml) { | |
81 | $coder = new Coder(); | |
82 | $this->assertEquals($expectHtml, $coder->recode($inputHtml)); | |
83 | } | |
84 | ||
85 | /** | |
86 | */ | |
87 | public function testAllPartials() { | |
88 | $coder = new \Civi\Angular\Coder(); | |
9099cab3 | 89 | $errors = []; |
d1e4cc3f TO |
90 | $count = 0; |
91 | foreach ($this->angular->getModules() as $module => $moduleDefn) { | |
92 | $partials = $this->angular->getPartials($module); | |
93 | foreach ($partials as $path => $html) { | |
94 | $count++; | |
95 | if (!$coder->checkConsistentHtml($html)) { | |
96 | $recodedHtml = $coder->recode($html); | |
97 | $this->assertEquals($html, $recodedHtml, "File $path has inconsistent HTML. Use tools/scripts/check-angular.php to debug. "); | |
98 | } | |
99 | } | |
100 | } | |
101 | ||
102 | $this->assertTrue($count > 0); | |
103 | } | |
104 | ||
105 | } |