PageRenderTime 34ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/tests/unit/notSupposedToBeHere/ModuleTest.php

https://bitbucket.org/zurmo/zurmo/
PHP | 155 lines | 99 code | 6 blank | 50 comment | 0 complexity | 69010d1dcd8c743e93cd1261770b482e MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. class ModuleTest extends BaseTest
  37. {
  38. public function testGetNestedModule()
  39. {
  40. $groupsModule = Yii::app()->getModule('zurmo')->getModule('groups');
  41. $this->assertEquals('GroupsModule', get_class($groupsModule));
  42. $zurmoModule = Yii::app()->findModule('zurmo');
  43. $groupsModule = $zurmoModule->getModule('groups');
  44. $this->assertEquals('GroupsModule', get_class($groupsModule));
  45. $groupsModule = Yii::app()->findModule('groups');
  46. $this->assertEquals('GroupsModule', get_class($groupsModule));
  47. }
  48. /**
  49. * @depends testGetNestedModule
  50. */
  51. public function testGetModuleObjects()
  52. {
  53. $modules = Module::getModuleObjects();
  54. $this->assertTrue (count($modules) > 9);
  55. $this->assertTrue (array_key_exists('zurmo', $modules));
  56. $this->assertTrue (array_key_exists('groups', $modules));
  57. $this->assertTrue (array_key_exists('roles', $modules));
  58. $this->assertTrue (array_key_exists('home', $modules));
  59. $this->assertTrue (array_key_exists('configuration', $modules));
  60. $this->assertTrue (array_key_exists('accounts', $modules));
  61. $this->assertTrue (array_key_exists('contacts', $modules));
  62. $this->assertTrue (array_key_exists('leads', $modules));
  63. $this->assertTrue (array_key_exists('opportunities', $modules));
  64. $this->assertTrue (array_key_exists('users', $modules));
  65. $this->assertTrue ($modules['zurmo'] instanceof Module);
  66. $this->assertTrue ($modules['groups'] instanceof Module);
  67. $this->assertTrue ($modules['roles'] instanceof Module);
  68. $this->assertTrue ($modules['home'] instanceof Module);
  69. $this->assertTrue ($modules['accounts'] instanceof Module);
  70. $this->assertTrue ($modules['leads'] instanceof Module);
  71. $this->assertTrue ($modules['contacts'] instanceof Module);
  72. $this->assertTrue ($modules['opportunities'] instanceof Module);
  73. $this->assertFalse($modules['zurmo'] ->canDisable());
  74. $this->assertFalse($modules['groups'] ->canDisable());
  75. $this->assertFalse($modules['roles'] ->canDisable());
  76. $this->assertFalse($modules['users'] ->canDisable());
  77. $this->assertTrue ($modules['home'] ->canDisable());
  78. $this->assertTrue ($modules['accounts'] ->canDisable());
  79. $this->assertTrue ($modules['contacts'] ->canDisable());
  80. $this->assertTrue ($modules['leads'] ->canDisable());
  81. $this->assertTrue ($modules['opportunities']->canDisable());
  82. }
  83. /**
  84. * @depends testGetModuleObjects
  85. */
  86. public function testGetModuleNameAndDisplayName()
  87. {
  88. $modules = Module::getModuleObjects();
  89. foreach ($modules as $moduleName => $module)
  90. {
  91. $this->assertEquals($moduleName, $module::getDirectoryName());
  92. $this->assertEquals($moduleName, $module->getName());
  93. }
  94. $this->assertEquals('Zurmo', $modules['zurmo'] ::getModuleLabelByTypeAndLanguage('Plural'));
  95. $this->assertEquals('Home', $modules['home'] ::getModuleLabelByTypeAndLanguage('Plural'));
  96. $this->assertEquals('Accounts', $modules['accounts'] ::getModuleLabelByTypeAndLanguage('Plural'));
  97. $this->assertEquals('Contacts', $modules['contacts'] ::getModuleLabelByTypeAndLanguage('Plural'));
  98. $this->assertEquals('Leads', $modules['leads'] ::getModuleLabelByTypeAndLanguage('Plural'));
  99. $this->assertEquals('Opportunities', $modules['opportunities']::getModuleLabelByTypeAndLanguage('Plural'));
  100. }
  101. /**
  102. * @depends testGetModuleObjects
  103. */
  104. public function testModuleDependencies()
  105. {
  106. $modules = Module::getModuleObjects();
  107. // TODO - test getting all dependencies
  108. // TODO - test getting enabled dependencies
  109. // TODO - test recursive enabling
  110. // TODO - test disabling, not recursive
  111. // TODO - test checking for satisfied dependencies all the way down
  112. }
  113. public function testGetDependenciesForModule()
  114. {
  115. $module = Yii::app()->findModule('accounts');
  116. $dependencies = Module::getDependenciesForModule($module);
  117. $this->assertEquals(
  118. array('zurmo', 'configuration', 'accounts'),
  119. $dependencies
  120. );
  121. }
  122. public function testGetModuleLabelByTypeAndLanguage()
  123. {
  124. $this->assertEquals('en', Yii::app()->languageHelper->getForCurrentUser());
  125. $this->assertEquals('Tes', TestModule::getModuleLabelByTypeAndLanguage('Singular'));
  126. $this->assertEquals('Test', TestModule::getModuleLabelByTypeAndLanguage('Plural'));
  127. $this->assertEquals('tes', TestModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
  128. $this->assertEquals('test', TestModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
  129. $metadata = TestModule::getMetadata();
  130. $metadata['global']['singularModuleLabels'] = array('en' => 'company', 'de' => 'gesellschaft');
  131. $metadata['global']['pluralModuleLabels'] = array('en' => 'companies', 'de' => 'gesellschaften');
  132. TestModule::setMetadata($metadata);
  133. $this->assertEquals('Company', TestModule::getModuleLabelByTypeAndLanguage('Singular'));
  134. $this->assertEquals('Companies', TestModule::getModuleLabelByTypeAndLanguage('Plural'));
  135. $this->assertEquals('company', TestModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
  136. $this->assertEquals('companies', TestModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
  137. Yii::app()->language = 'de';
  138. $this->assertEquals('Gesellschaft', TestModule::getModuleLabelByTypeAndLanguage('Singular'));
  139. $this->assertEquals('Gesellschaften', TestModule::getModuleLabelByTypeAndLanguage('Plural'));
  140. $this->assertEquals('gesellschaft', TestModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
  141. $this->assertEquals('gesellschaften', TestModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
  142. Yii::app()->language = 'en';
  143. //Demonstrate getSingularModuleLabel and getPluralModuleLabel and how if they are not overriden, they
  144. //will not necessarily produce desired results.
  145. $this->assertEquals('Zurmo', ZurmoModule::getModuleLabelByTypeAndLanguage('Singular'));
  146. $this->assertEquals('Zurmo', ZurmoModule::getModuleLabelByTypeAndLanguage('Plural'));
  147. }
  148. }
  149. ?>