PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/app/protected/extensions/zurmoinc/framework/tests/unit/PortletTest.php

https://bitbucket.org/zurmo/zurmo/
PHP | 195 lines | 155 code | 9 blank | 31 comment | 3 complexity | 8b95a3374a3e28d08f45fa9cf642e8f9 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) 2012 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU 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 General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU 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 113 McHenry Road Suite 207,
  24. * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
  25. ********************************************************************************/
  26. class PortletTest extends BaseTest
  27. {
  28. public function testSavePortlet()
  29. {
  30. $user = UserTestHelper::createBasicUser('Billy');
  31. $portlet = new Portlet();
  32. $portlet->column = 2;
  33. $portlet->position = 5;
  34. $portlet->layoutId = 'Test';
  35. $portlet->collapsed = true;
  36. $portlet->viewType = 'RssReader';
  37. $portlet->serializedViewData = serialize(array('a' => 'apple', 'b' => 'bannana'));
  38. $portlet->user = $user;
  39. $this->assertTrue($portlet->save());
  40. $portlet = Portlet::getById($portlet->id);
  41. $this->assertEquals(2, $portlet->column);
  42. $this->assertEquals(5, $portlet->position);
  43. $this->assertEquals('Test', $portlet->layoutId);
  44. //$this->assertEquals(true, $portlet->collapsed); //reenable once working
  45. $this->assertEquals('RssReader', $portlet->viewType);
  46. $this->assertEquals($user->id, $portlet->user->id);
  47. $this->assertNotEquals(array('a' => 'apple', 'b' => 'bannana'), $portlet->serializedViewData);
  48. $this->assertEquals (array('a' => 'apple', 'b' => 'bannana'), unserialize($portlet->serializedViewData));
  49. }
  50. /**
  51. * @depends testSavePortlet
  52. */
  53. public function testSaveCollectionUsingDefaultMetadata()
  54. {
  55. $user = User::getByUserName('billy');
  56. $params = array('test' => 'test');
  57. $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('abc', $user->id, $params);
  58. $this->assertEmpty($portlets);
  59. $defaultMetadata = array(
  60. 'global' => array(
  61. 'columns' => array(
  62. array(
  63. 'rows' => array(
  64. array(
  65. 'type' => 'RssReader',
  66. ),
  67. array(
  68. 'type' => 'RssReader',
  69. ),
  70. )
  71. ),
  72. array(
  73. 'rows' => array(
  74. array(
  75. 'type' => 'RssReader',
  76. ),
  77. array(
  78. 'type' => 'RssReader',
  79. ),
  80. )
  81. )
  82. )
  83. )
  84. );
  85. $portletCollection = Portlet::makePortletsUsingMetadataSortedByColumnIdAndPosition('abc', $defaultMetadata, $user, $params);
  86. $this->assertNotEmpty($portletCollection);
  87. $testCount = 0;
  88. foreach ($portletCollection as $column => $columns)
  89. {
  90. foreach ($columns as $position => $portlet)
  91. {
  92. $testCount++;
  93. }
  94. }
  95. $this->assertEquals($testCount, 4);
  96. Portlet::savePortlets($portletCollection);
  97. $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('abc', $user->id, $params);
  98. $this->assertNotEmpty($portletCollection);
  99. $testCount = 0;
  100. foreach ($portletCollection as $column => $columns)
  101. {
  102. foreach ($columns as $position => $portlet)
  103. {
  104. $this->assertEquals($portlet->params, $params);
  105. $testCount++;
  106. }
  107. }
  108. $this->assertEquals($testCount, 4);
  109. }
  110. public function testShiftPositionsBasedOnColumnReduction()
  111. {
  112. $user = User::getByUserName('billy');
  113. for ($i = 1; $i <= 3; $i++)
  114. {
  115. $portlet = new Portlet();
  116. $portlet->column = 1;
  117. $portlet->position = $i;
  118. $portlet->layoutId = 'shiftTest';
  119. $portlet->collapsed = true;
  120. $portlet->viewType = 'RssReader';
  121. $portlet->user = $user;
  122. $this->assertTrue($portlet->save());
  123. }
  124. for ($i = 1; $i <= 5; $i++)
  125. {
  126. $portlet = new Portlet();
  127. $portlet->column = 2;
  128. $portlet->position = $i;
  129. $portlet->layoutId = 'shiftTest';
  130. $portlet->collapsed = true;
  131. $portlet->viewType = 'RssReader';
  132. $portlet->user = $user;
  133. $this->assertTrue($portlet->save());
  134. }
  135. for ($i = 1; $i <= 4; $i++)
  136. {
  137. $portlet = new Portlet();
  138. $portlet->column = 3;
  139. $portlet->position = $i;
  140. $portlet->layoutId = 'shiftTest';
  141. $portlet->collapsed = true;
  142. $portlet->viewType = 'RssReader';
  143. $portlet->user = $user;
  144. $this->assertTrue($portlet->save());
  145. }
  146. $this->assertEquals(count(Portlet::getByLayoutIdAndUserSortedById('shiftTest', $user->id)), 12);
  147. $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('shiftTest', $user->id, array());
  148. Portlet::shiftPositionsBasedOnColumnReduction($portletCollection, 2);
  149. $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('shiftTest', $user->id, array());
  150. $this->assertEquals(count($portletCollection), 2);
  151. $this->assertEquals(count($portletCollection[1]), 7);
  152. Portlet::shiftPositionsBasedOnColumnReduction($portletCollection, 1);
  153. $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('shiftTest', $user->id, array());
  154. $this->assertEquals(count($portletCollection), 1);
  155. $this->assertEquals(count($portletCollection[1]), 12);
  156. }
  157. /**
  158. * @depends testSavePortlet
  159. */
  160. public function testBooleanSaveValueMatchesBooleanRetrieveValue()
  161. {
  162. $user = User::getByUserName('billy');
  163. $portlet = new Portlet();
  164. $portlet->column = 1;
  165. $portlet->position = 1;
  166. $portlet->layoutId = 'Test';
  167. $portlet->collapsed = true;
  168. $portlet->viewType = 'RssReader';
  169. $portlet->user = $user;
  170. $this->assertTrue($portlet->save());
  171. $portlet = Portlet::getById($portlet->id);
  172. $this->assertEquals(1, $portlet->collapsed);
  173. }
  174. public function testPortletRulesFactory()
  175. {
  176. $viewClassName = 'DetailsView';
  177. $portletRules = PortletRulesFactory::createPortletRulesByView($viewClassName);
  178. $this->assertNull($portletRules);
  179. $viewClassName = 'RelatedListView';
  180. $portletRules = PortletRulesFactory::createPortletRulesByView($viewClassName);
  181. $this->assertTrue($portletRules instanceof PortletRules);
  182. $this->assertTrue($portletRules->allowOnRelationView());
  183. $this->assertFalse($portletRules->allowOnDashboard());
  184. }
  185. }
  186. ?>