(NFC) Update version headers in `tests/`
[civicrm-core.git] / tests / phpunit / Civi / Angular / PartialSyntaxTest.php
CommitLineData
d1e4cc3f
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
d1e4cc3f 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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() {
57 $cases = array();
58
59 $cases[0] = array(
60 '<div foo="bar"></div>',
61 '<div foo="bar"></div>',
62 );
63 $cases[1] = array(
64 '<div foo="bar"/>',
65 '<div foo="bar"></div>',
66 );
67 $cases[2] = array(
68 '<div foo=\'bar\'></div>',
69 '<div foo="bar"></div>',
70 );
71 $cases[3] = array(
72 '<div foo=\'ts("Hello world")\'></div>',
73 '<div foo=\'ts("Hello world")\'></div>',
74 );
75 $cases[4] = array(
76 '<div foo="ts(\'Hello world\')\"></div>',
77 '<div foo="ts(\'Hello world\')\"></div>',
78 );
79 $cases[5] = array(
80 '<a href="{{foo}}" title="{{bar}}"></a>',
81 '<a href="{{foo}}" title="{{bar}}"></a>',
82 );
83 $cases[6] = array(
84 '<div ng-if="a && b"></div>',
85 '<div ng-if="a && b"></div>',
86 );
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();
105 $errors = array();
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}