Skip to content

Commit

Permalink
WIP - PartialSyntaxTest - Ensure that Angular partials are well-formed
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Apr 1, 2017
1 parent 513023e commit 3e16e50
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/phpunit/Civi/Angular/PartialSyntaxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

namespace Civi\Angular;

/**
* Ensure that all Angular *.html partials are well-formed.
*/
class PartialSyntaxTest extends \CiviUnitTestCase {

/**
* @var Manager
*/
protected $angular;

/**
* @var \CRM_Core_Resources
*/
protected $res;

/**
* @inheritDoc
*/
protected function setUp() {
$this->useTransaction(TRUE);
parent::setUp();
$this->createLoggedInUser();
$this->res = \CRM_Core_Resources::singleton();
$this->angular = new Manager($this->res);
}

/**
*/
public function testPartial() {
$errors = array();
$count = 0;
foreach ($this->angular->getModules() as $module => $moduleDefn) {
$partials = $this->angular->getPartials($module);
foreach ($partials as $path => $html) {
$count++;
try {
$doc = \phpQuery::newDocument("$html", 'text/html');
} catch (\Exception $e) {
$errors[$path] = $e->getMessage();
}
// $this->assertEquals(
// preg_replace('/[ \t\r\n\/]/', '', $html),
// preg_replace('/[ \t\r\n\/]/', '', (string)$doc)
// );
}
}

$this->assertTrue($count > 0);
$this->assertEquals(array(), $errors,
sprintf(
"Found %s files with errors: %s",
count($errors),
implode(', ', array_keys($errors))
));
}

}

0 comments on commit 3e16e50

Please sign in to comment.