CRM-19690 - crmMailing - Pick editor layout using template_type
[civicrm-core.git] / tests / phpunit / Civi / Angular / ManagerTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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
28 namespace Civi\Angular;
29
30 /**
31 * Test the Angular base page.
32 */
33 class ManagerTest 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 /**
57 * Modules appear to be well-defined.
58 */
59 public function testGetModules() {
60 $modules = $this->angular->getModules();
61
62 $counts = array(
63 'js' => 0,
64 'css' => 0,
65 'partials' => 0,
66 'settings' => 0,
67 );
68
69 foreach ($modules as $module) {
70 $this->assertTrue(is_array($module));
71 $this->assertTrue(is_string($module['ext']));
72 if (isset($module['js'])) {
73 $this->assertTrue(is_array($module['js']));
74 foreach ($module['js'] as $file) {
75 $this->assertTrue(file_exists($this->res->getPath($module['ext'], $file)));
76 $counts['js']++;
77 }
78 }
79 if (isset($module['css'])) {
80 $this->assertTrue(is_array($module['css']));
81 foreach ($module['css'] as $file) {
82 $this->assertTrue(file_exists($this->res->getPath($module['ext'], $file)));
83 $counts['css']++;
84 }
85 }
86 if (isset($module['partials'])) {
87 $this->assertTrue(is_array($module['partials']));
88 foreach ((array) $module['partials'] as $basedir) {
89 $this->assertTrue(is_dir($this->res->getPath($module['ext']) . '/' . $basedir));
90 $counts['partials']++;
91 }
92 }
93 if (isset($module['settings'])) {
94 $this->assertTrue(is_array($module['settings']));
95 foreach ($module['settings'] as $name => $value) {
96 $counts['settings']++;
97 }
98 }
99 }
100
101 $this->assertTrue($counts['js'] > 0, 'Expect to find at least one JS file');
102 $this->assertTrue($counts['css'] > 0, 'Expect to find at least one CSS file');
103 $this->assertTrue($counts['partials'] > 0, 'Expect to find at least one partial HTML file');
104 $this->assertTrue($counts['settings'] > 0, 'Expect to find at least one setting');
105 }
106
107 /**
108 * Get HTML fragments from an example module.
109 */
110 public function testGetPartials() {
111 $partials = $this->angular->getPartials('crmMailing');
112 $this->assertRegExp('/ng-form="crmMailing/', $partials['~/crmMailing/EditMailingCtrl/2step.html']);
113 // If crmMailing changes, feel free to use a different example.
114 }
115
116 /**
117 * Get a translatable string from an example module.
118 */
119 public function testGetStrings() {
120 $strings = $this->angular->getStrings('crmMailing');
121 $this->assertTrue(in_array('Save Draft', $strings));
122 // If crmMailing changes, feel free to use a different example.
123 }
124
125 }