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 * Test the reading-writing of HTML snippets.
33 class ChangeSetTest
extends \CiviUnitTestCase
{
36 * Insert content using after().
38 public function testInsertAfter() {
39 $changeSet = ChangeSet
::create(__FUNCTION__
);
40 $counts = ['~/foo.html' => 0];
42 $changeSet->alterHtml('~/foo.html', function (\phpQueryObject
$doc, $file) use (&$counts) {
44 $doc->find('.foo')->after('<p ng-if="alpha.beta() && true">world</p>');
46 $changeSet->alterHtml('~/f*.html', function (\phpQueryObject
$doc, $file) use (&$counts) {
48 $doc->find('.bar')->after('<p>cruel world</p>');
50 $changeSet->alterHtml('/path/does/not/exist.html', function(\phpQueryObject
$doc) {
51 throw new \
Exception("This should not be called. The file does not exist!");
54 $results = ChangeSet
::applyResourceFilters([$changeSet], 'partials', [
55 '~/foo.html' => '<span><p class="foo">Hello</p><p class="bar">Goodbye</p></span>',
58 $this->assertHtmlEquals(
59 '<span><p class="foo">Hello</p><p ng-if="alpha.beta() && true">world</p><p class="bar">Goodbye</p><p>cruel world</p></span>',
60 $results['~/foo.html']
62 $this->assertEquals(2, $counts['~/foo.html']);
66 * Insert content using append() and prepend().
68 public function testAppendPrepend() {
69 $changeSet = ChangeSet
::create(__FUNCTION__
);
70 $counts = ['~/foo.html' => 0];
72 $changeSet->alterHtml('~/foo.html', function (\phpQueryObject
$doc, $file) use (&$counts) {
74 $doc->find('.foo')->append('<p ng-if="!!gamma()">world</p>');
76 $changeSet->alterHtml('~/*.html', function (\phpQueryObject
$doc, $file) use (&$counts) {
78 $doc->find('.bar')->prepend('<span>Cruel world,</span>');
80 $changeSet->alterHtml('/path/does/not/exist.html', function(\phpQueryObject
$doc) {
81 throw new \
Exception("This should not be called. The file does not exist!");
85 '~/foo.html' => '<span><p class="foo">Hello</p><p class="bar">Goodbye</p></span>',
87 $results = ChangeSet
::applyResourceFilters([$changeSet], 'partials', $originals);
89 $this->assertHtmlEquals(
90 '<span><p class="foo">Hello<p ng-if="!!gamma()">world</p></p><p class="bar"><span>Cruel world,</span>Goodbye</p></span>',
91 $results['~/foo.html']
93 $this->assertEquals(2, $counts['~/foo.html']);
96 protected function assertHtmlEquals($expected, $actual, $message = '') {
97 $expected = preg_replace(';>[ \r\n\t]+;', '>', $expected);
98 $actual = preg_replace(';>[ \r\n\t]+;', '>', $actual);
99 $this->assertEquals($expected, $actual, $message);