Merge pull request #14925 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / Civi / Angular / PartialSyntaxTest.php
CommitLineData
d1e4cc3f
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
d1e4cc3f 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
d1e4cc3f
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28namespace Civi\Angular;
29
30/**
31 * Ensure that all Angular *.html partials are well-formed.
32 */
33class PartialSyntaxTest extends \CiviUnitTestCase {
34
35 /**
36 * @var Manager
37 */
38 protected $angular;
39
40 /**
41 * @var \CRM_Core_Resources
42 */
43 protected $res;
44
45 /**
46 * @inheritDoc
47 */
48 protected function setUp() {
49 $this->useTransaction(TRUE);
50 parent::setUp();
51 $this->createLoggedInUser();
52 $this->res = \CRM_Core_Resources::singleton();
53 $this->angular = new Manager($this->res);
54 }
55
56 public function basicConsistencyExamples() {
9099cab3 57 $cases = [];
d1e4cc3f 58
9099cab3 59 $cases[0] = [
d1e4cc3f
TO
60 '<div foo="bar"></div>',
61 '<div foo="bar"></div>',
9099cab3
CW
62 ];
63 $cases[1] = [
d1e4cc3f
TO
64 '<div foo="bar"/>',
65 '<div foo="bar"></div>',
9099cab3
CW
66 ];
67 $cases[2] = [
d1e4cc3f
TO
68 '<div foo=\'bar\'></div>',
69 '<div foo="bar"></div>',
9099cab3
CW
70 ];
71 $cases[3] = [
d1e4cc3f
TO
72 '<div foo=\'ts("Hello world")\'></div>',
73 '<div foo=\'ts("Hello world")\'></div>',
9099cab3
CW
74 ];
75 $cases[4] = [
d1e4cc3f
TO
76 '<div foo="ts(\'Hello world\')\"></div>',
77 '<div foo="ts(\'Hello world\')\"></div>',
9099cab3
CW
78 ];
79 $cases[5] = [
d1e4cc3f
TO
80 '<a href="{{foo}}" title="{{bar}}"></a>',
81 '<a href="{{foo}}" title="{{bar}}"></a>',
9099cab3
CW
82 ];
83 $cases[6] = [
d1e4cc3f
TO
84 '<div ng-if="a && b"></div>',
85 '<div ng-if="a && b"></div>',
9099cab3 86 ];
d1e4cc3f
TO
87
88 return $cases;
89 }
90
91 /**
92 * @param string $inputHtml
93 * @param string $expectHtml
94 * @dataProvider basicConsistencyExamples
95 */
96 public function testConsistencyExamples($inputHtml, $expectHtml) {
97 $coder = new Coder();
98 $this->assertEquals($expectHtml, $coder->recode($inputHtml));
99 }
100
101 /**
102 */
103 public function testAllPartials() {
104 $coder = new \Civi\Angular\Coder();
9099cab3 105 $errors = [];
d1e4cc3f
TO
106 $count = 0;
107 foreach ($this->angular->getModules() as $module => $moduleDefn) {
108 $partials = $this->angular->getPartials($module);
109 foreach ($partials as $path => $html) {
110 $count++;
111 if (!$coder->checkConsistentHtml($html)) {
112 $recodedHtml = $coder->recode($html);
113 $this->assertEquals($html, $recodedHtml, "File $path has inconsistent HTML. Use tools/scripts/check-angular.php to debug. ");
114 }
115 }
116 }
117
118 $this->assertTrue($count > 0);
119 }
120
121}