commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / tests / phpunit / Civi / Angular / ManagerTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
31
32 /**
33 * Test the Angular base page.
34 */
35 class ManagerTest extends \CiviUnitTestCase {
36
37 /**
38 * @var Manager
39 */
40 protected $angular;
41
42 /**
43 * @var \CRM_Core_Resources
44 */
45 protected $res;
46
47 /**
48 * @inheritDoc
49 */
50 protected function setUp() {
51 $this->useTransaction(TRUE);
52 parent::setUp();
53 $this->createLoggedInUser();
54 $this->res = \CRM_Core_Resources::singleton();
55 $this->angular = new Manager($this->res);
56 }
57
58 /**
59 * Modules appear to be well-defined.
60 */
61 public function testGetModules() {
62 $modules = $this->angular->getModules();
63
64 $counts = array(
65 'js' => 0,
66 'css' => 0,
67 'partials' => 0,
68 'settings' => 0,
69 );
70
71 foreach ($modules as $module) {
72 $this->assertTrue(is_array($module));
73 $this->assertTrue(is_string($module['ext']));
74 if (isset($module['js'])) {
75 $this->assertTrue(is_array($module['js']));
76 foreach ($module['js'] as $file) {
77 $this->assertTrue(file_exists($this->res->getPath($module['ext'], $file)));
78 $counts['js']++;
79 }
80 }
81 if (isset($module['css'])) {
82 $this->assertTrue(is_array($module['css']));
83 foreach ($module['css'] as $file) {
84 $this->assertTrue(file_exists($this->res->getPath($module['ext'], $file)));
85 $counts['css']++;
86 }
87 }
88 if (isset($module['partials'])) {
89 $this->assertTrue(is_array($module['partials']));
90 foreach ((array) $module['partials'] as $basedir) {
91 $this->assertTrue(is_dir($this->res->getPath($module['ext']) . '/' . $basedir));
92 $counts['partials']++;
93 }
94 }
95 if (isset($module['settings'])) {
96 $this->assertTrue(is_array($module['settings']));
97 foreach ($module['settings'] as $name => $value) {
98 $counts['settings']++;
99 }
100 }
101 }
102
103 $this->assertTrue($counts['js'] > 0, 'Expect to find at least one JS file');
104 $this->assertTrue($counts['css'] > 0, 'Expect to find at least one CSS file');
105 $this->assertTrue($counts['partials'] > 0, 'Expect to find at least one partial HTML file');
106 $this->assertTrue($counts['settings'] > 1, 'Expect to find at least one setting');
107 }
108
109 /**
110 * Get HTML fragments from an example module.
111 */
112 public function testGetPartials() {
113 $partials = $this->angular->getPartials('crmMailing');
114 $this->assertRegExp('/\<form.*name="crmMailing"/', $partials['~/crmMailing/EditMailingCtrl/2step.html']);
115 // If crmMailing changes, feel free to use a different example.
116 }
117
118 /**
119 * Get a translatable string from an example module.
120 */
121 public function testGetStrings() {
122 $strings = $this->angular->getStrings('crmMailing');
123 $this->assertTrue(in_array('Save Draft', $strings));
124 // If crmMailing changes, feel free to use a different example.
125 }
126
127 }