1: <?php
2: 3: 4: 5:
6:
7: require_once (__INCLUDES__ .'/connector/TypeTestConnector.class.php');
8: require_once (__INCLUDES__ .'/connector/ProjectConnector.class.php');
9: require_once (__INCLUDES__ .'/connector/AddressConnector.class.php');
10: require_once (__INCLUDES__ .'/connector/PersonConnector.class.php');
11:
12:
13: class ModelConnectorTests extends QUnitTestCaseBase {
14: protected static $frmTest;
15:
16: 17: 18:
19: public static function setUpClass()
20: {
21: global $_FORM;
22: self::$frmTest = $_FORM;
23: }
24:
25: public function testBasicControls() {
26: $mctTypeTest = TypeTestConnector::Create(self::$frmTest);
27:
28: $mctTypeTest->DateControl->DateTime = new QDateTime ('10/10/2010');
29: $mctTypeTest->DateTimeControl->DateTime = new QDateTime ('11/11/2011');
30: $mctTypeTest->TestIntControl->Value = 5;
31: $mctTypeTest->TestFloatControl->Value = 3.5;
32: $mctTypeTest->TestVarcharControl->Text = 'abcde';
33: $mctTypeTest->TestTextControl->Text = 'ABCDE';
34: $mctTypeTest->TestBitControl->Checked = true;
35:
36: $id = $mctTypeTest->SaveTypeTest();
37:
38: $mctTypeTest2 = TypeTestConnector::Create(self::$frmTest, $id);
39: $dt = $mctTypeTest2->DateControl->DateTime;
40: $this->assertTrue ($dt->IsEqualTo (new QDateTime ('10/10/2010', null, QDateTime::DateOnlyType)), 'Date only type saved correctly through connector.');
41: $dt = $mctTypeTest2->DateTimeControl->DateTime;
42: $this->assertTrue ($dt->IsEqualTo (new QDateTime ('11/11/2011')), 'Date time type saved correctly through connector.');
43: $this->assertEquals(5, $mctTypeTest2->TestIntControl->Value, 'Integer control saved correctly.');
44: $this->assertEquals(3.5, $mctTypeTest2->TestFloatControl->Value, 'Float type saved correctly.');
45: $this->assertEquals('abcde', $mctTypeTest2->TestVarcharControl->Text, 'Varchar control type saved correctly through connector.');
46: $this->assertEquals('ABCDE', $mctTypeTest2->TestTextControl->Text, 'Text type saved correctly through connector.');
47: $this->assertEquals(true, $mctTypeTest2->TestBitControl->Checked, 'Bit saved correctly through connector.');
48:
49: $mctTypeTest2->DeleteTypeTest();
50: }
51:
52: public function testReference() {
53:
54: $mctProject = ProjectConnector::Create (self::$frmTest, 1);
55: $lstControl = $mctProject->ManagerPersonIdControl;
56: $this->assertTrue ($lstControl instanceof QListBox);
57: $this->assertEquals ($lstControl->SelectedValue, 7, "Read manager as person value.");
58: $lstControl->SelectedValue = 6;
59: $mctProject->SaveProject();
60:
61: $mctProject2 = ProjectConnector::Create (self::$frmTest, 1);
62: $objPerson = $mctProject2->Project->ManagerPerson;
63: $this->assertEquals(6, $objPerson->Id, "Forward reference saved correctly through connector.");
64: $mctProject2->Project->ManagerPersonId = 7;
65: $mctProject2->Project->Save();
66:
67:
68: $mctProject->Load (2);
69: $this->assertEquals(4, $mctProject->ManagerPersonIdControl->SelectedValue, "Reloaded forward reference connector");
70:
71:
72:
73: $mctAddress = AddressConnector::Create (self::$frmTest);
74: $lstControl = $mctAddress->PersonIdControl;
75: $this->assertTrue ($lstControl instanceof QAutocomplete);
76: $lstControl->SelectedValue = 2;
77: $mctAddress->StreetControl->Text = 'Test Street';
78: $mctAddress->CityControl->Text = 'Test City';
79: $id = $mctAddress->SaveAddress();
80:
81: $mctAddress2 = AddressConnector::Create (self::$frmTest, $id);
82: $objPerson = $mctAddress2->Address->Person;
83: $this->assertEquals('Kendall', $objPerson->FirstName, "Forward reference saved correctly through connector.");
84: $mctAddress->DeleteAddress();
85:
86:
87: $mctAddress->Load (3);
88: $this->assertEquals('New York', $mctAddress->CityControl->Text);
89: }
90:
91: public function testReverseReference() {
92: $mctPerson = PersonConnector::Create (self::$frmTest, 7);
93: $lstControl = $mctPerson->LoginControl;
94: $this->assertTrue ($lstControl instanceof QListControl);
95: $this->assertEquals ($lstControl->SelectedValue, 4);
96: $this->assertEquals ($mctPerson->Person->Login->Username, 'kwolfe');
97:
98:
99: $lstControl->SelectedValue = 5;
100: $mctPerson->SavePerson();
101: $this->assertEquals ($mctPerson->Person->Login->Id, 5);
102:
103: $lstControl->SelectedValue = 4;
104: $mctPerson->SavePerson();
105: $this->assertEquals ($mctPerson->Person->Login->Id, 4);
106:
107:
108: $mctPerson->Load(3);
109: $this->assertEquals ($lstControl->SelectedValue, 2);
110: $this->assertEquals ($mctPerson->Person->Login->Username, 'brobinson');
111: }
112:
113: public function testManyToMany() {
114: $clauses = array(QQ::ExpandAsArray(QQN::Person()->ProjectAsTeamMember));
115: $objPerson = Person::Load (2, $clauses);
116: $mctPerson = new PersonConnector (self::$frmTest, $objPerson);
117: $lstControl = $mctPerson->ProjectAsTeamMemberControl;
118: $this->assertTrue ($lstControl instanceof QListControl);
119: $values = $lstControl->SelectedValues;
120: sort ($values);
121: $this->assertEquals ($values[0], 1);
122: $this->assertEquals ($values[1], 2);
123: $this->assertEquals ($values[2], 4);
124:
125:
126: $mctPerson->Load (3, $clauses);
127: $values = $lstControl->SelectedValues;
128: sort ($values);
129: $this->assertEquals ($values[0], 4);
130: $this->assertEquals (count($values), 1);
131:
132:
133: $lstControl->SelectedValues = [2,4];
134: $mctPerson->SavePerson();
135: $a = Project::LoadArrayByPersonAsTeamMember(3);
136: $this->assertEquals(2, $a[0]->Id);
137: $this->assertEquals(4, $a[1]->Id);
138:
139: $lstControl->SelectedValues = [4];
140: $mctPerson->SavePerson();
141: $a = Project::LoadArrayByPersonAsTeamMember(3);
142: $this->assertEquals(4, $a[0]->Id);
143:
144: }
145:
146: public function testType1() {
147: $mctProject = ProjectConnector::Create(self::$frmTest,3);
148: $this->assertEquals ($mctProject->ProjectStatusTypeIdControl->SelectedValue, 1);
149:
150: $mctProject->ProjectStatusTypeIdControl->SelectedValue = ProjectStatusType::Cancelled;
151: $mctProject->SaveProject();
152: $this->assertEquals(ProjectStatusType::Cancelled, $mctProject->Project->ProjectStatusTypeId);
153:
154:
155: $mctProject->ProjectStatusTypeIdControl->SelectedValue = ProjectStatusType::Open;
156: $mctProject->SaveProject();
157: $this->assertEquals(ProjectStatusType::Open, $mctProject->Project->ProjectStatusTypeId);
158:
159: $mctProject->Load (1);
160: $this->assertEquals ($mctProject->ProjectStatusTypeIdControl->SelectedValue, 3);
161:
162: }
163:
164: public function testTypeMulti() {
165: $mctPerson = PersonConnector::Create (self::$frmTest, 3);
166: $values = $mctPerson->PersonTypeControl->SelectedValues;
167: $this->assertEquals(3, count ($values));
168:
169: $values2 = $values;
170: $values2[] = 5;
171:
172: $mctPerson->PersonTypeControl->SelectedValues = $values2;
173: $mctPerson->SavePerson();
174: $values3 = $mctPerson->Person->GetPersonTypeArray();
175: $this->assertEquals(4, count ($values3));
176: $mctPerson->PersonTypeControl->SelectedValues = $values;
177: $mctPerson->SavePerson();
178: $values3 = $mctPerson->Person->GetPersonTypeArray();
179: $this->assertEquals(3, count ($values3));
180: }
181:
182: 183: 184:
185: public function testOverrides() {
186:
187: $mctAddress = AddressConnector::Create (self::$frmTest);
188:
189: $blnError = false;
190: try {
191: $mctAddress->StreetLabel;
192: }
193: catch (QUndefinedPropertyException $e) {
194: $blnError = true;
195: }
196: $this->assertTrue($blnError, 'Street Label was removed by override.');
197:
198: $this->assertEquals('100px', $mctAddress->CityControl->Width);
199:
200:
201: $mctProject = ProjectConnector::Create (self::$frmTest);
202: $this->assertEquals(3, $mctProject->PersonAsTeamMemberControl->RepeatColumns);
203: $this->assertEquals('Team Members', $mctProject->PersonAsTeamMemberControl->Name);
204:
205:
206: $mctPerson = PersonConnector::Create (self::$frmTest);
207: $this->assertTrue ($mctPerson->LoginControl->Required, 'Reverse reference was marked required by override file.');
208:
209: $objItem = $mctPerson->LoginControl->GetItem(0);
210: $this->assertEquals ($objItem->Name, '- Select One -', 'Required value was detected by list control.');
211:
212: }
213:
214: }