Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelMemberRulesToColumnsAdapterTest.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  protected static $messageLogger;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  $super = User::getByUsername('super');
46  Yii::app()->user->userModel = $super;
47  static::$messageLogger = new MessageLogger();
48  }
49 
50  public function testResolveWithEmptyMembers()
51  {
52  // using AuditEvent everywhere as it can't have bean, neither can its parent.
53  $modelClassName = 'AuditEvent';
54  $members = array();
55  $rules = array(array('nonMember', 'required'));
56  $columns = RedBeanModelMemberRulesToColumnsAdapter::resolve($modelClassName,
57  $members,
58  $rules,
59  static::$messageLogger);
60  $this->assertEmpty($columns);
61  }
62 
68  public function testResolveWithEmptyRules()
69  {
70  $modelClassName = 'AuditEvent';
71  $members = array('memberOne');
72  $rules = array();
73  $columns = RedBeanModelMemberRulesToColumnsAdapter::resolve($modelClassName,
74  $members,
75  $rules,
76  static::$messageLogger);
77  $this->assertEmpty($columns);
78  }
79 
84  {
85  $modelClassName = 'AuditEvent';
86  $members = array();
87  $rules = array();
88  $columns = RedBeanModelMemberRulesToColumnsAdapter::resolve($modelClassName,
89  $members,
90  $rules,
91  static::$messageLogger);
92  $this->assertEmpty($columns);
93  }
94 
99  {
100  $modelClassName = 'AuditEvent';
101  $members = array('memberOne');
102  $rules = array(
103  array('memberOne', 'email'),
104  array('nonMember', 'required'),
105  array('nonMember', 'website'),
106  );
107  $columns = RedBeanModelMemberRulesToColumnsAdapter::resolve($modelClassName,
108  $members,
109  $rules,
110  static::$messageLogger);
111  $this->assertNotEmpty($columns);
112  $this->assertCount(1, $columns);
113  $this->assertCount(6, $columns[0]);
114  $this->assertArrayHasKey('name', $columns[0]);
115  $this->assertArrayHasKey('type', $columns[0]);
116  $this->assertArrayHasKey('unsigned', $columns[0]);
117  $this->assertArrayHasKey('notNull', $columns[0]);
118  $this->assertArrayHasKey('collation', $columns[0]);
119  $this->assertArrayHasKey('default', $columns[0]);
120  $this->assertEquals('memberone', $columns[0]['name']);
121  $this->assertEquals('VARCHAR(255)', $columns[0]['type']);
122  $this->assertNull($columns[0]['unsigned']);
123  $this->assertEquals('NULL', $columns[0]['notNull']); // Not Coding Standard
124  $this->assertEquals('COLLATE utf8_unicode_ci', $columns[0]['collation']);
125  $this->assertEquals('DEFAULT NULL', $columns[0]['default']); // Not Coding Standard
126  }
127 
134  {
135  $modelClassName = 'AuditEvent';
136  $members = array('memberOne');
137  $rules = array(array('memberOne', 'required'));
138  $columns = RedBeanModelMemberRulesToColumnsAdapter::resolve($modelClassName,
139  $members,
140  $rules,
141  static::$messageLogger);
142  $this->assertEmpty($columns);
143  }
144 
148  public function testResolveWithMixedRules()
149  {
150  $modelClassName = 'AuditEvent';
151  $expectedColumns = array(
152  array(
153  'name' => 'type',
154  'type' => 'INT(11)',
155  'unsigned' => null,
156  'notNull' => 'NULL', // Not Coding Standard
157  'collation' => null,
158  'default' => 'DEFAULT NULL', // Not Coding Standard
159  ),
160  array(
161  'name' => 'modelclassname',
162  'type' => 'VARCHAR(64)',
163  'unsigned' => null,
164  'notNull' => 'NULL', // Not Coding Standard
165  'collation' => 'COLLATE utf8_unicode_ci',
166  'default' => 'DEFAULT NULL', // Not Coding Standard
167  ),
168  array(
169  'name' => 'name',
170  'type' => 'VARCHAR(64)',
171  'unsigned' => null,
172  'notNull' => 'NULL', // Not Coding Standard
173  'collation' => 'COLLATE utf8_unicode_ci',
174  'default' => 'DEFAULT NULL', // Not Coding Standard
175  ),
176  array(
177  'name' => 'subject',
178  'type' => 'VARCHAR(64)',
179  'unsigned' => null,
180  'notNull' => 'NULL', // Not Coding Standard
181  'collation' => 'COLLATE utf8_unicode_ci',
182  'default' => 'DEFAULT NULL', // Not Coding Standard
183  ),
184  array(
185  'name' => 'language',
186  'type' => 'VARCHAR(2)',
187  'unsigned' => null,
188  'notNull' => 'NULL', // Not Coding Standard
189  'collation' => 'COLLATE utf8_unicode_ci',
190  'default' => 'DEFAULT NULL', // Not Coding Standard
191  ),
192  array(
193  'name' => 'htmlcontent',
194  'type' => 'TEXT',
195  'unsigned' => null,
196  'notNull' => 'NULL', // Not Coding Standard
197  'collation' => 'COLLATE utf8_unicode_ci',
198  'default' => 'DEFAULT NULL', // Not Coding Standard
199  ),
200  array(
201  'name' => 'textcontent',
202  'type' => 'TEXT',
203  'unsigned' => null,
204  'notNull' => 'NULL', // Not Coding Standard
205  'collation' => 'COLLATE utf8_unicode_ci',
206  'default' => 'DEFAULT NULL', // Not Coding Standard
207  )
208 
209  );
210  $members = array(
211  'type',
212  'modelClassName',
213  'name',
214  'subject',
215  'language',
216  'htmlContent',
217  'textContent',
218  );
219  $rules = array(
220  array('type', 'required'),
221  array('type', 'type', 'type' => 'integer'),
222  array('type', 'numerical'),
223  array('modelClassName', 'required'),
224  array('modelClassName', 'type', 'type' => 'string'),
225  array('modelClassName', 'length', 'max' => 64),
226  array('modelClassName', 'ModelExistsAndIsReadableValidator'),
227  array('name', 'required'),
228  array('name', 'type', 'type' => 'string'),
229  array('name', 'length', 'min' => 3, 'max' => 64),
230  array('subject', 'required'),
231  array('subject', 'type', 'type' => 'string'),
232  array('subject', 'length', 'min' => 3, 'max' => 64),
233  array('language', 'type', 'type' => 'string'),
234  array('language', 'length', 'min' => 2, 'max' => 2),
235  array('language', 'SetToUserDefaultLanguageValidator'),
236  array('htmlContent', 'type', 'type' => 'string'),
237  array('textContent', 'type', 'type' => 'string'),
238  array('htmlContent', 'AtLeastOneContentAreaRequiredValidator'),
239  array('textContent', 'AtLeastOneContentAreaRequiredValidator'),
240  array('htmlContent', 'EmailTemplateMergeTagsValidator'),
241  array('textContent', 'EmailTemplateMergeTagsValidator'),
242  );
243  $columns = RedBeanModelMemberRulesToColumnsAdapter::resolve($modelClassName,
244  $members,
245  $rules,
246  static::$messageLogger);
247  $this->assertNotEmpty($columns);
248  $this->assertCount(7, $columns);
249  foreach ($columns as $index => $column)
250  {
251  $this->assertCount(6, $column);
252  $this->assertArrayHasKey('name', $column);
253  $this->assertArrayHasKey('type', $column);
254  $this->assertArrayHasKey('unsigned', $column);
255  $this->assertArrayHasKey('notNull', $column);
256  $this->assertArrayHasKey('collation', $column);
257  $this->assertArrayHasKey('default', $column);
258  $this->assertEquals($expectedColumns[$index], $column);
259  }
260  }
261  }
262 ?>
static getByUsername($username)
Definition: User.php:49
static resolve($modelClassName, array $members, array $rules, &$messageLogger)
Generated on Wed Jul 8 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.