Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
PortletTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 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. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  class PortletTest extends BaseTest
38  {
39  public function testSavePortlet()
40  {
41  $user = UserTestHelper::createBasicUser('Billy');
42  $portlet = new Portlet();
43  $portlet->column = 2;
44  $portlet->position = 5;
45  $portlet->layoutId = 'Test';
46  $portlet->collapsed = true;
47  $portlet->viewType = 'RssReader';
48  $portlet->serializedViewData = serialize(array('a' => 'apple', 'b' => 'bannana'));
49  $portlet->user = $user;
50  $this->assertTrue($portlet->save());
51  $portlet = Portlet::getById($portlet->id);
52  $this->assertEquals(2, $portlet->column);
53  $this->assertEquals(5, $portlet->position);
54  $this->assertEquals('Test', $portlet->layoutId);
55  //$this->assertEquals(true, $portlet->collapsed); //reenable once working
56  $this->assertEquals('RssReader', $portlet->viewType);
57  $this->assertEquals($user->id, $portlet->user->id);
58  $this->assertNotEquals(array('a' => 'apple', 'b' => 'bannana'), $portlet->serializedViewData);
59  $this->assertEquals (array('a' => 'apple', 'b' => 'bannana'), unserialize($portlet->serializedViewData));
60  }
61 
66  {
67  $user = User::getByUserName('billy');
68  $params = array('test' => 'test');
69  $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('abc', $user->id, $params);
70  $this->assertEmpty($portlets);
71 
72  $defaultMetadata = array(
73  'global' => array(
74  'columns' => array(
75  array(
76  'rows' => array(
77  array(
78  'type' => 'RssReader',
79  ),
80  array(
81  'type' => 'RssReader',
82  ),
83  )
84  ),
85  array(
86  'rows' => array(
87  array(
88  'type' => 'RssReader',
89  ),
90  array(
91  'type' => 'RssReader',
92  ),
93  )
94  )
95  )
96  )
97  );
98 
99  $portletCollection = Portlet::makePortletsUsingMetadataSortedByColumnIdAndPosition('abc', $defaultMetadata, $user, $params);
100  $this->assertNotEmpty($portletCollection);
101  $testCount = 0;
102  foreach ($portletCollection as $column => $columns)
103  {
104  foreach ($columns as $position => $portlet)
105  {
106  $testCount++;
107  }
108  }
109  $this->assertEquals($testCount, 4);
110  Portlet::savePortlets($portletCollection);
111 
112  $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('abc', $user->id, $params);
113  $this->assertNotEmpty($portletCollection);
114  $testCount = 0;
115  foreach ($portletCollection as $column => $columns)
116  {
117  foreach ($columns as $position => $portlet)
118  {
119  $this->assertEquals($portlet->params, $params);
120  $testCount++;
121  }
122  }
123  $this->assertEquals($testCount, 4);
124  }
125 
126  public function testShiftPositionsBasedOnColumnReduction()
127  {
128  $user = User::getByUserName('billy');
129  for ($i = 1; $i <= 3; $i++)
130  {
131  $portlet = new Portlet();
132  $portlet->column = 1;
133  $portlet->position = $i;
134  $portlet->layoutId = 'shiftTest';
135  $portlet->collapsed = true;
136  $portlet->viewType = 'RssReader';
137  $portlet->user = $user;
138  $this->assertTrue($portlet->save());
139  }
140  for ($i = 1; $i <= 5; $i++)
141  {
142  $portlet = new Portlet();
143  $portlet->column = 2;
144  $portlet->position = $i;
145  $portlet->layoutId = 'shiftTest';
146  $portlet->collapsed = true;
147  $portlet->viewType = 'RssReader';
148  $portlet->user = $user;
149  $this->assertTrue($portlet->save());
150  }
151  for ($i = 1; $i <= 4; $i++)
152  {
153  $portlet = new Portlet();
154  $portlet->column = 3;
155  $portlet->position = $i;
156  $portlet->layoutId = 'shiftTest';
157  $portlet->collapsed = true;
158  $portlet->viewType = 'RssReader';
159  $portlet->user = $user;
160  $this->assertTrue($portlet->save());
161  }
162 
163  $this->assertEquals(count(Portlet::getByLayoutIdAndUserSortedById('shiftTest', $user->id)), 12);
164  $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('shiftTest', $user->id, array());
165  Portlet::shiftPositionsBasedOnColumnReduction($portletCollection, 2);
166  $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('shiftTest', $user->id, array());
167  $this->assertEquals(count($portletCollection), 2);
168  $this->assertEquals(count($portletCollection[1]), 7);
169  Portlet::shiftPositionsBasedOnColumnReduction($portletCollection, 1);
170  $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('shiftTest', $user->id, array());
171  $this->assertEquals(count($portletCollection), 1);
172  $this->assertEquals(count($portletCollection[1]), 12);
173  }
174 
179  {
180  $user = User::getByUserName('billy');
181  $portlet = new Portlet();
182  $portlet->column = 1;
183  $portlet->position = 1;
184  $portlet->layoutId = 'Test';
185  $portlet->collapsed = true;
186  $portlet->viewType = 'RssReader';
187  $portlet->user = $user;
188  $this->assertTrue($portlet->save());
189  $portlet = Portlet::getById($portlet->id);
190  $this->assertEquals(1, $portlet->collapsed);
191  }
192 
193  public function testPortletRulesFactory()
194  {
195  $viewClassName = 'DetailsView';
196  $portletRules = PortletRulesFactory::createPortletRulesByView($viewClassName);
197  $this->assertNull($portletRules);
198  $viewClassName = 'RelatedListView';
199  $portletRules = PortletRulesFactory::createPortletRulesByView($viewClassName);
200  $this->assertTrue($portletRules instanceof PortletRules);
201  $this->assertTrue($portletRules->allowOnRelationView());
202  $this->assertFalse($portletRules->allowOnDashboard());
203  }
204  }
205 ?>
static createPortletRulesByView($viewClassName)
testSaveCollectionUsingDefaultMetadata()
Definition: PortletTest.php:65
static getById($id, $modelClassName=null)
testBooleanSaveValueMatchesBooleanRetrieveValue()
Generated on Sat Jul 11 2020 07:10:25
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.