Commit | Line | Data |
---|---|---|
16072ce1 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
16072ce1 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
16072ce1 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 | +--------------------------------------------------------------------+ | |
cbcb7579 | 26 | */ |
16072ce1 TO |
27 | |
28 | namespace Civi\Angular; | |
29 | ||
16072ce1 TO |
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, | |
1da632e0 | 66 | 'settings' => 0, |
16072ce1 TO |
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'])); | |
a2dc0f82 TO |
88 | foreach ((array) $module['partials'] as $basedir) { |
89 | $this->assertTrue(is_dir($this->res->getPath($module['ext']) . '/' . $basedir)); | |
16072ce1 TO |
90 | $counts['partials']++; |
91 | } | |
92 | } | |
1da632e0 TO |
93 | if (isset($module['settings'])) { |
94 | $this->assertTrue(is_array($module['settings'])); | |
95 | foreach ($module['settings'] as $name => $value) { | |
96 | $counts['settings']++; | |
97 | } | |
98 | } | |
16072ce1 TO |
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'); | |
a83af40b | 104 | $this->assertTrue($counts['settings'] > 0, 'Expect to find at least one setting'); |
16072ce1 TO |
105 | } |
106 | ||
107 | /** | |
108 | * Get HTML fragments from an example module. | |
109 | */ | |
110 | public function testGetPartials() { | |
111 | $partials = $this->angular->getPartials('crmMailing'); | |
3ac6e107 | 112 | $this->assertRegExp('/ng-form="crmMailing/', $partials['~/crmMailing/EditMailingCtrl/2step.html']); |
16072ce1 TO |
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 | } | |
cbcb7579 | 124 | |
16072ce1 | 125 | } |