Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelAttributeToDataProviderAdapterTest.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 testAllMethodsOnAttributeOnSameModel()
46  {
47  $adapter = new RedBeanModelAttributeToDataProviderAdapter('A', 'a');
48  $this->assertEquals('A', $adapter->getModelClassName());
49  $this->assertEquals('a', $adapter->getAttribute());
50  $this->assertEquals(null, $adapter->getRelatedAttribute());
51  $this->assertEquals('a', $adapter->getModelTableName());
52  $this->assertEquals('A', $adapter->getAttributeModelClassName());
53  $this->assertEquals('a', $adapter->getAttributeTableName());
54  $this->assertEquals('a', $adapter->getColumnName());
55  $this->assertFalse( $adapter->isRelation());
56  $this->assertFalse( $adapter->hasRelatedAttribute());
57  }
58 
59  public function testAllMethodsOnAttributeOnCastedUpModel()
60  {
61  $adapter = new RedBeanModelAttributeToDataProviderAdapter('B', 'a');
62  $this->assertEquals('B', $adapter->getModelClassName());
63  $this->assertEquals('a', $adapter->getAttribute());
64  $this->assertEquals(null, $adapter->getRelatedAttribute());
65  $this->assertEquals('b', $adapter->getModelTableName());
66  $this->assertEquals('A', $adapter->getAttributeModelClassName());
67  $this->assertEquals('a', $adapter->getAttributeTableName());
68  $this->assertEquals('a', $adapter->getColumnName());
69  $this->assertFalse( $adapter->isRelation());
70  $this->assertFalse( $adapter->hasRelatedAttribute());
71  }
72 
73  public function testAllMethodsOnAttributeOnSameModelAndRelatedAttribute()
74  {
75  $adapter = new RedBeanModelAttributeToDataProviderAdapter('I', 'j', 'jMember');
76  $this->assertEquals('I', $adapter->getModelClassName());
77  $this->assertEquals('j', $adapter->getAttribute());
78  $this->assertEquals('jMember', $adapter->getRelatedAttribute());
79  $this->assertEquals('i', $adapter->getModelTableName());
80  $this->assertEquals('I', $adapter->getAttributeModelClassName());
81  $this->assertEquals('i', $adapter->getAttributeTableName());
82  $this->assertEquals('j_id', $adapter->getColumnName());
83  $this->assertTrue( $adapter->isRelation());
84  $this->assertTrue( $adapter->hasRelatedAttribute());
85  $this->assertEquals('J', $adapter->getRelationModelClassName());
86  $this->assertEquals('J', $adapter->getRelatedAttributeModelClassName());
87  $this->assertEquals('j', $adapter->getRelationTableName());
88  $this->assertEquals('j', $adapter->getRelatedAttributeTableName());
89  $this->assertEquals('jmember', $adapter-> getRelatedAttributeColumnName());
90  $this->assertFalse( $adapter->isRelatedAttributeRelation());
91  }
92 
93  public function testRelatedAttributesSortUsesTwoAttributes()
94  {
95  $adapter = new RedBeanModelAttributeToDataProviderAdapter('A', 'a');
96  $this->assertFalse( $adapter->sortUsesTwoAttributes());
97  $this->assertEquals('a', $adapter->getColumnNameByPosition(0));
98  try
99  {
100  $adapter->getColumnNameByPosition(1);
101  }
102  catch (InvalidArgumentException $exception)
103  {
104  $this->assertEquals('Attribute position is not valid', $exception->getMessage());
105  }
106 
107  $adapter = new RedBeanModelAttributeToDataProviderAdapter('Q', 'a');
108  $this->assertTrue( $adapter->sortUsesTwoAttributes());
109  $this->assertEquals('a', $adapter->getColumnNameByPosition(0));
110  $this->assertEquals('junk', $adapter->getColumnNameByPosition(1));
111  $this->assertEquals('uniquerequiredemail', $adapter->getColumnNameByPosition(2));
112  try
113  {
114  $adapter->getColumnNameByPosition(3);
115  }
116  catch (InvalidArgumentException $exception)
117  {
118  $this->assertEquals('Attribute position is not valid', $exception->getMessage());
119  }
120 
121  $adapter = new RedBeanModelAttributeToDataProviderAdapter('QQ', 'q');
122  $this->assertTrue( $adapter->relatedAttributesSortUsesTwoAttributes());
123  $this->assertEquals('q_id', $adapter->getColumnNameByPosition(0));
124  $this->assertEquals('junk', $adapter->getColumnNameByPosition(1));
125  $this->assertEquals('uniquerequiredemail', $adapter->getColumnNameByPosition(2));
126 
127  $adapter = new RedBeanModelAttributeToDataProviderAdapter('QQ', 'qRequired');
128  $this->assertTrue( $adapter->relatedAttributesSortUsesTwoAttributes());
129  $this->assertEquals('erequired_q_id', $adapter->getColumnNameByPosition(0));
130  $this->assertEquals('junk', $adapter->getColumnNameByPosition(1));
131  $this->assertEquals('uniquerequiredemail', $adapter->getColumnNameByPosition(2));
132 
133  $adapter = new RedBeanModelAttributeToDataProviderAdapter('QQ', 'qUnique');
134  $this->assertTrue( $adapter->relatedAttributesSortUsesTwoAttributes());
135  $this->assertEquals('eunique_q_id', $adapter->getColumnNameByPosition(0));
136  $this->assertEquals('junk', $adapter->getColumnNameByPosition(1));
137  $this->assertEquals('uniquerequiredemail', $adapter->getColumnNameByPosition(2));
138 
139  $adapter = new RedBeanModelAttributeToDataProviderAdapter('QQ', 'qMany');
140  $this->assertTrue( $adapter->relatedAttributesSortUsesTwoAttributes());
141  $this->assertEquals('qq_id', $adapter->getColumnNameByPosition(0));
142  $this->assertEquals('junk', $adapter->getColumnNameByPosition(1));
143  $this->assertEquals('uniquerequiredemail', $adapter->getColumnNameByPosition(2));
144  }
145  }
146 ?>
Generated on Sat Jul 4 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.