Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ContactsSearchWithDataProviderTest.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 
41  {
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
47  $super = User::getByUsername('super');
48  Yii::app()->user->userModel = $super;
49  }
50 
51  public function testSearchOnContactState()
52  {
53  //Test member of search.
54  $_FAKEPOST['Contact'] = array();
55  $_FAKEPOST['Contact']['state']['id'] = '4';
56  $metadataAdapter = new SearchDataProviderMetadataAdapter(
57  new Contact(false),
58  1,
59  $_FAKEPOST['Contact']
60  );
61  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
62  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
64  $where = RedBeanModelDataProvider::makeWhere('Contact', $searchAttributeData, $joinTablesAdapter);
65  $compareWhere = "({$quote}contact{$quote}.{$quote}state_contactstate_id{$quote} = 4)";
66  $this->assertEquals($compareWhere, $where);
67 
68  //Now test that the joinTablesAdapter has correct information.
69  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
70  $this->assertEquals(0, $joinTablesAdapter->getLeftTableJoinCount());
71 
72  //Make sure the sql runs properly.
73  $dataProvider = new RedBeanModelDataProvider('Contact', null, false, $searchAttributeData);
74  $data = $dataProvider->getData();
75  }
76 
77  public function testFullNameOnContactsSearchFormSearch()
78  {
79  $super = User::getByUsername('super');
80  Yii::app()->user->userModel = $super;
81 
82  $_FAKEPOST['Contact'] = array();
83  $_FAKEPOST['Contact']['fullName'] = 'Jackie Tyler';
84  $metadataAdapter = new SearchDataProviderMetadataAdapter(
85  new ContactsSearchForm(new Contact(false)),
86  1,
87  $_FAKEPOST['Contact']
88  );
89  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
90  $compareData = array('clauses' => array(1 => array('attributeName' => 'firstName',
91  'operatorType' => 'startsWith',
92  'value' => 'Jackie Tyler'),
93  2 => array('attributeName' => 'lastName',
94  'operatorType' => 'startsWith',
95  'value' => 'Jackie Tyler'),
96  3 => array('concatedAttributeNames' => array('firstName', 'lastName'),
97  'operatorType' => 'startsWith',
98  'value' => 'Jackie Tyler')),
99  'structure' => '(1 or 2 or 3)');
100  $this->assertEquals($compareData, $searchAttributeData);
101 
102  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
104  $where = RedBeanModelDataProvider::makeWhere('Contact', $searchAttributeData, $joinTablesAdapter);
105  $compareWhere = "(({$quote}person{$quote}.{$quote}firstname{$quote} like 'Jackie Tyler%') or ";
106  $compareWhere .= "({$quote}person{$quote}.{$quote}lastname{$quote} like 'Jackie Tyler%') or ";
107  $compareWhere .= "(concat({$quote}person{$quote}.{$quote}firstname{$quote}, ' ', ";
108  $compareWhere .= "{$quote}person{$quote}.{$quote}lastname{$quote}) like 'Jackie Tyler%'))";
109  $this->assertEquals($compareWhere, $where);
110 
111  //Now test that the joinTablesAdapter has correct information.
112  $this->assertEquals(1, $joinTablesAdapter->getFromTableJoinCount());
113  $this->assertEquals(0, $joinTablesAdapter->getLeftTableJoinCount());
114  $fromTables = $joinTablesAdapter->getFromTablesAndAliases();
115  $this->assertEquals('person', $fromTables[0]['tableName']);
116 
117  //Make sure the sql runs properly.
118  $dataProvider = new RedBeanModelDataProvider('Contact', null, false, $searchAttributeData);
119  $data = $dataProvider->getData();
120 
121  $this->assertEquals(0, count($data));
122 
123  ContactTestHelper::createContactByNameForOwner('Dino', $super);
124 
125  $dataProvider->getTotalItemCount(true); //refreshes the total item count
126  $data = $dataProvider->getData();
127  $this->assertEquals(0, count($data));
128 
129  ContactTestHelper::createContactByNameForOwner('Jackie', $super);
130 
131  $dataProvider->getTotalItemCount(true); //refreshes the total item count
132  $data = $dataProvider->getData();
133  $this->assertEquals(0, count($data));
134 
136  $contact = new Contact();
137  $contact->firstName = 'Jackie';
138  $contact->lastName = 'Tyler';
139  $contact->owner = $super;
140  $contact->state = ContactsUtil::getStartingState();
141  $this->assertTrue($contact->save());
142 
143  $dataProvider->getTotalItemCount(true); //refreshes the total item count
144  $data = $dataProvider->getData(true);
145 
146  $this->assertEquals(1, count($data));
147  $this->assertEquals($contact->id, $data[0]->id);
148  }
149 
150  public function testDefaultFullnameOrderOnContacts()
151  {
152  $super = User::getByUsername('super');
153  Yii::app()->user->userModel = $super;
154  $contact = new Contact();
155  $contact->firstName = 'Jackie';
156  $contact->lastName = 'Bonn';
157  $contact->owner = $super;
158  $contact->state = ContactsUtil::getStartingState();
159  $this->assertTrue($contact->save());
160  $searchAttributeData = array();
161  $dataProvider = new RedBeanModelDataProvider('Contact', null, false, $searchAttributeData);
162  $data = $dataProvider->getData();
163  $contacts = array();
164  foreach ($data as $contact)
165  {
166  $contacts[] = strval($contact);
167  }
168  $sortedContacts = $contacts;
169  sort($sortedContacts);
170  $compareContacts = array('Dino Dinoson', 'Jackie Bonn', 'Jackie Jackieson', 'Jackie Tyler');
171  $this->assertEquals($compareContacts, $sortedContacts);
172  }
173  }
174 ?>
static getByUsername($username)
Definition: User.php:49
static loadStartingData()
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getStartingState()
Generated on Sat Jul 4 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.