All Data Structures Functions Variables Pages
ContactStateTest.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 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  }
44 
45  public function testCreateAndGetContactState()
46  {
47  $state = new ContactState();
48  $state->name = 'First State';
49  $state->order = 0;
50  $this->assertTrue($state->save());
51  $id = $state->id;
52  unset($state);
53  $state = ContactState::getById($id);
54  $this->assertEquals('First State', $state->name);
55  $this->assertEquals(0, $state->order);
56  $state->delete();
57  }
58 
59  public function testContactStateModelAttributesAdapter()
60  {
61  Yii::app()->user->userModel = User::getByUsername('super');
62  $this->assertTrue(ContactsModule::loadStartingData());
63  $this->assertEquals(6, count(ContactState::GetAll()));
64 
65  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state');
66  $compareData = array(
67  0 => 'New',
68  1 => 'In Progress',
69  2 => 'Recycled',
70  3 => 'Dead',
71  4 => 'Qualified',
72  5 => 'Customer',
73  );
74  $this->assertEquals($compareData, $attributeForm->contactStatesData);
75  $this->assertEquals(null, $attributeForm->contactStatesLabels);
76  $this->assertEquals(4, $attributeForm->startingStateOrder);
77 
78  //Now add new values.
79  $attributeForm->contactStatesData = array(
80  0 => 'New',
81  1 => 'In Progress',
82  2 => 'Recycled',
83  3 => 'Dead',
84  4 => 'Qualified',
85  5 => 'Customer',
86  6 => 'AAA',
87  7 => 'BBB',
88  );
89  $contactStatesLabels = array(
90  'fr' => array('New', 'In ProgressFr', 'RecycledFr', 'DeadFr', 'QualifiedFr', 'CustomerFr', 'AAAFr', 'BBBFr')
91  );
92  $attributeForm->contactStatesLabels = $contactStatesLabels;
93  $attributeForm->startingStateOrder = 5;
94  $adapter = new ContactStateModelAttributesAdapter(new Contact());
95  $adapter->setAttributeMetadataFromForm($attributeForm);
96  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state');
97  $compareData = array(
98  0 => 'New',
99  1 => 'In Progress',
100  2 => 'Recycled',
101  3 => 'Dead',
102  4 => 'Qualified',
103  5 => 'Customer',
104  6 => 'AAA',
105  7 => 'BBB',
106  );
107  $this->assertEquals($compareData, $attributeForm->contactStatesData);
108  $this->assertEquals($contactStatesLabels, $attributeForm->contactStatesLabels);
109  $contactState = ContactState::getByName('Customer');
110  $this->assertEquals(5, $contactState[0]->order);
111  $this->assertEquals(5, $attributeForm->startingStateOrder);
112 
113  //Test removing existing values.
114  $attributeForm->contactStatesData = array(
115  0 => 'New',
116  1 => 'In Progress',
117  2 => 'Recycled',
118  3 => 'Customer',
119  4 => 'AAA',
120  5 => 'BBB',
121  );
122  $attributeForm->startingStateOrder = 5;
123  $adapter = new ContactStateModelAttributesAdapter(new Contact());
124  $adapter->setAttributeMetadataFromForm($attributeForm);
125  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state');
126  $compareData = array(
127  0 => 'New',
128  1 => 'In Progress',
129  2 => 'Recycled',
130  3 => 'Customer',
131  4 => 'AAA',
132  5 => 'BBB',
133  );
134  $this->assertEquals($compareData, $attributeForm->contactStatesData);
135  $this->assertEquals(5, $attributeForm->startingStateOrder);
136 
137  //Test switching order of existing values.
138  $attributeForm->contactStatesData = array(
139  0 => 'New',
140  3 => 'In Progress',
141  5 => 'Recycled',
142  1 => 'Customer',
143  4 => 'AAA',
144  2 => 'BBB',
145  );
146  $attributeForm->startingStateOrder = 2;
147  $adapter = new ContactStateModelAttributesAdapter(new Contact());
148  $adapter->setAttributeMetadataFromForm($attributeForm);
149  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state');
150  $compareData = array(
151  0 => 'New',
152  3 => 'In Progress',
153  5 => 'Recycled',
154  1 => 'Customer',
155  4 => 'AAA',
156  2 => 'BBB',
157  );
158  $this->assertEquals($compareData, $attributeForm->contactStatesData);
159  $this->assertEquals(2, $attributeForm->startingStateOrder);
160 
161  //Test switching order of existing values and adding new values mixed in.
162  $attributeForm->contactStatesData = array(
163  3 => 'New',
164  6 => 'In Progress',
165  5 => 'Recycled',
166  1 => 'Customer',
167  4 => 'AAA',
168  2 => 'BBB',
169  0 => 'CCC',
170  );
171  $attributeForm->startingStateOrder = 2;
172  $adapter = new ContactStateModelAttributesAdapter(new Contact());
173  $adapter->setAttributeMetadataFromForm($attributeForm);
174  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state');
175  $compareData = array(
176  3 => 'New',
177  6 => 'In Progress',
178  5 => 'Recycled',
179  1 => 'Customer',
180  4 => 'AAA',
181  2 => 'BBB',
182  0 => 'CCC',
183  );
184  $this->assertEquals($compareData, $attributeForm->contactStatesData);
185  $this->assertEquals(2, $attributeForm->startingStateOrder);
186 
187  //Switching name of existing state
188  $this->assertEquals(7, ContactState::getCount());
189  $attributeForm->contactStatesDataExistingValues = array(
190  3 => 'New',
191  6 => 'In Progress',
192  5 => 'Recycled',
193  1 => 'Customer',
194  4 => 'AAA',
195  2 => 'BBB',
196  0 => 'CCC',
197  );
198  $attributeForm->contactStatesData = array(
199  3 => 'New',
200  6 => 'In Progress Plastic',
201  5 => 'Recycled',
202  1 => 'Customer',
203  4 => 'AAA',
204  2 => 'BBB',
205  0 => 'CCC',
206  );
207  $attributeForm->startingStateOrder = 2;
208  $adapter = new ContactStateModelAttributesAdapter(new Contact());
209  $adapter->setAttributeMetadataFromForm($attributeForm);
210  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state');
211  $compareData = array(
212  3 => 'New',
213  6 => 'In Progress Plastic',
214  5 => 'Recycled',
215  1 => 'Customer',
216  4 => 'AAA',
217  2 => 'BBB',
218  0 => 'CCC',
219  );
220  $this->assertEquals($compareData, $attributeForm->contactStatesData);
221  $this->assertEquals(2, $attributeForm->startingStateOrder);
222  $this->assertEquals(7, ContactState::getCount());
223  }
224  }
225 ?>
static getByUsername($username)
Definition: User.php:49
static loadStartingData()
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getById($id, $modelClassName=null)
Generated on Sun May 31 2020 07:10:30