3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 namespace Civi\Angular
;
31 * Ensure that all Angular *.html partials are well-formed.
33 class PartialSyntaxTest
extends \CiviUnitTestCase
{
41 * @var \CRM_Core_Resources
48 protected function setUp() {
49 $this->useTransaction(TRUE);
51 $this->createLoggedInUser();
52 $this->res
= \CRM_Core_Resources
::singleton();
53 $this->angular
= new Manager($this->res
);
56 public function basicConsistencyExamples() {
60 '<div foo="bar"></div>',
61 '<div foo="bar"></div>',
65 '<div foo="bar"></div>',
68 '<div foo=\'bar\'></div>',
69 '<div foo="bar"></div>',
72 '<div foo=\'ts("Hello world")\'></div>',
73 '<div foo=\'ts("Hello world")\'></div>',
76 '<div foo="ts(\'Hello world\')\"></div>',
77 '<div foo="ts(\'Hello world\')\"></div>',
80 '<a href="{{foo}}" title="{{bar}}"></a>',
81 '<a href="{{foo}}" title="{{bar}}"></a>',
84 '<div ng-if="a && b"></div>',
85 '<div ng-if="a && b"></div>',
92 * @param string $inputHtml
93 * @param string $expectHtml
94 * @dataProvider basicConsistencyExamples
96 public function testConsistencyExamples($inputHtml, $expectHtml) {
98 $this->assertEquals($expectHtml, $coder->recode($inputHtml));
103 public function testAllPartials() {
104 $coder = new \Civi\Angular\
Coder();
107 foreach ($this->angular
->getModules() as $module => $moduleDefn) {
108 $partials = $this->angular
->getPartials($module);
109 foreach ($partials as $path => $html) {
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. ");
118 $this->assertTrue($count > 0);