PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/app/protected/commands/tests/unit/UpdateSchemaCommandTest.php

https://bitbucket.org/zurmo/zurmo/
PHP | 161 lines | 110 code | 10 blank | 41 comment | 1 complexity | ff34a15ddd96ce04dbbcf4b1f528eb64 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 UpdateSchemaCommandTest extends ZurmoBaseTest
  37. {
  38. public static function setUpBeforeClass()
  39. {
  40. parent::setUpBeforeClass();
  41. SecurityTestHelper::createSuperAdmin();
  42. }
  43. public function setUp()
  44. {
  45. parent::setUp();
  46. $this->assertTrue(ContactsModule::loadStartingData());
  47. }
  48. public function tearDown()
  49. {
  50. parent::tearDown();
  51. ContactState::deleteAll();
  52. }
  53. public function testRunWithoutAnyValueForOverwriteExistingReadTables()
  54. {
  55. $output = array();
  56. $this->runUpdateSchema($output);
  57. $this->assertTrue(array_search('Info - Schema generation completed', $output) !== false);
  58. $this->assertTrue(array_search('Skipping existing read Tables.', $output) !== false);
  59. $this->assertTrue(array_search('Skipping account_read', $output) !== false);
  60. $this->assertTrue(array_search('Skipping campaign_read', $output) !== false);
  61. $this->assertTrue(array_search('Skipping contact_read', $output) !== false);
  62. $this->assertTrue(array_search('Skipping conversation_read', $output) !== false);
  63. $this->assertTrue(array_search('Skipping emailmessage_read', $output) !== false);
  64. $this->assertTrue(array_search('Skipping emailtemplate_read', $output) !== false);
  65. $this->assertTrue(array_search('Skipping gamereward_read', $output) !== false);
  66. $this->assertTrue(array_search('Skipping marketinglist_read', $output) !== false);
  67. $this->assertTrue(array_search('Skipping meeting_read', $output) !== false);
  68. $this->assertTrue(array_search('Skipping mission_read', $output) !== false);
  69. $this->assertTrue(array_search('Skipping note_read', $output) !== false);
  70. $this->assertTrue(array_search('Skipping opportunity_read', $output) !== false);
  71. $this->assertTrue(array_search('Skipping savedreport_read', $output) !== false);
  72. $this->assertTrue(array_search('Skipping product_read', $output) !== false);
  73. $this->assertTrue(array_search('Skipping socialitem_read', $output) !== false);
  74. $this->assertTrue(array_search('Skipping task_read', $output) !== false);
  75. $this->assertTrue(array_search('Skipping contactwebform_read', $output) !== false);
  76. $this->assertTrue(array_search('Skipping project_read', $output) !== false);
  77. $this->assertTrue(array_search('Schema update complete.', $output) !== false);
  78. }
  79. /**
  80. * @depends testRunWithoutAnyValueForOverwriteExistingReadTables
  81. */
  82. public function testRunWithOverwriteExistingReadTablesSetToZero()
  83. {
  84. $output = array();
  85. $this->runUpdateSchema($output, 0);
  86. $this->assertTrue(array_search('Info - Schema generation completed', $output) !== false);
  87. $this->assertTrue(array_search('Skipping existing read Tables.', $output) !== false);
  88. $this->assertTrue(array_search('Skipping account_read', $output) !== false);
  89. $this->assertTrue(array_search('Skipping campaign_read', $output) !== false);
  90. $this->assertTrue(array_search('Skipping contact_read', $output) !== false);
  91. $this->assertTrue(array_search('Skipping conversation_read', $output) !== false);
  92. $this->assertTrue(array_search('Skipping emailmessage_read', $output) !== false);
  93. $this->assertTrue(array_search('Skipping emailtemplate_read', $output) !== false);
  94. $this->assertTrue(array_search('Skipping gamereward_read', $output) !== false);
  95. $this->assertTrue(array_search('Skipping marketinglist_read', $output) !== false);
  96. $this->assertTrue(array_search('Skipping meeting_read', $output) !== false);
  97. $this->assertTrue(array_search('Skipping mission_read', $output) !== false);
  98. $this->assertTrue(array_search('Skipping note_read', $output) !== false);
  99. $this->assertTrue(array_search('Skipping opportunity_read', $output) !== false);
  100. $this->assertTrue(array_search('Skipping savedreport_read', $output) !== false);
  101. $this->assertTrue(array_search('Skipping product_read', $output) !== false);
  102. $this->assertTrue(array_search('Skipping socialitem_read', $output) !== false);
  103. $this->assertTrue(array_search('Skipping task_read', $output) !== false);
  104. $this->assertTrue(array_search('Skipping contactwebform_read', $output) !== false);
  105. $this->assertTrue(array_search('Skipping project_read', $output) !== false);
  106. $this->assertTrue(array_search('Schema update complete.', $output) !== false);
  107. }
  108. /**
  109. * @depends testRunWithOverwriteExistingReadTablesSetToZero
  110. */
  111. public function testRunWithOverwriteExistingReadTablesSetToOne()
  112. {
  113. $output = array();
  114. $this->runUpdateSchema($output, 1);
  115. $this->assertTrue(array_search('Info - Schema generation completed', $output) !== false);
  116. $this->assertTrue(array_search('Overwriting any existing read Tables.', $output) !== false);
  117. $this->assertTrue(array_search('Building account_read', $output) !== false);
  118. $this->assertTrue(array_search('Building campaign_read', $output) !== false);
  119. $this->assertTrue(array_search('Building contact_read', $output) !== false);
  120. $this->assertTrue(array_search('Building conversation_read', $output) !== false);
  121. $this->assertTrue(array_search('Building emailmessage_read', $output) !== false);
  122. $this->assertTrue(array_search('Building emailtemplate_read', $output) !== false);
  123. $this->assertTrue(array_search('Building gamereward_read', $output) !== false);
  124. $this->assertTrue(array_search('Building marketinglist_read', $output) !== false);
  125. $this->assertTrue(array_search('Building meeting_read', $output) !== false);
  126. $this->assertTrue(array_search('Building mission_read', $output) !== false);
  127. $this->assertTrue(array_search('Building note_read', $output) !== false);
  128. $this->assertTrue(array_search('Building opportunity_read', $output) !== false);
  129. $this->assertTrue(array_search('Building savedreport_read', $output) !== false);
  130. $this->assertTrue(array_search('Building product_read', $output) !== false);
  131. $this->assertTrue(array_search('Building socialitem_read', $output) !== false);
  132. $this->assertTrue(array_search('Building task_read', $output) !== false);
  133. $this->assertTrue(array_search('Building contactwebform_read', $output) !== false);
  134. $this->assertTrue(array_search('Building project_read', $output) !== false);
  135. $this->assertTrue(array_search('Schema update complete.', $output) !== false);
  136. }
  137. protected function runUpdateSchema(& $output, $overwriteExistingReadTables = null)
  138. {
  139. $messageLogger = new MessageLogger();
  140. InstallUtil::autoBuildDatabase($messageLogger, true);
  141. chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
  142. $command = "php zurmocTest.php updateSchema super " . $overwriteExistingReadTables;
  143. //echo PHP_EOL . "Executing : $command" . PHP_EOL;
  144. if (!IS_WINNT)
  145. {
  146. $command .= ' 2>&1';
  147. }
  148. exec($command, $output);
  149. }
  150. }
  151. ?>