1: <?php
2:
3:
4: if(!class_exists('Person')){
5: require_once __INCLUDES__ .'/model/Person.class.php';
6:
7: }
8: if(!class_exists('Project')){
9: require_once __INCLUDES__ . '/model/Project.class.php';
10: }
11: 12: 13: 14: 15:
16: class QQAliasTests extends QUnitTestCaseBase {
17: public function testAlias1() {
18: $objPersonArray = Person::QueryArray(
19: QQ::AndCondition(
20: QQ::Equal(QQ::Alias(QQN::Person()->ProjectAsTeamMember, 'pm1')->ProjectId, 1),
21: QQ::Equal(QQ::Alias(QQN::Person()->ProjectAsTeamMember, 'pm2')->ProjectId, 2)
22: )
23: );
24:
25: $this->assertEquals(3, sizeof($objPersonArray));
26: $this->verifyObjectPropertyHelper($objPersonArray, 'FirstName', 'Kendall');
27: $this->verifyObjectPropertyHelper($objPersonArray, 'LastName', 'Wolfe');
28: $this->verifyObjectPropertyHelper($objPersonArray, 'LastName', 'Smith');
29: }
30:
31: public function testAlias2() {
32: $objProjectArray = Project::QueryArray(
33: QQ::AndCondition(
34: QQ::Equal(QQ::Alias(QQN::Project()->ProjectAsRelated, 'related1')->Project->Name, 'Blueman Industrial Site Architecture'),
35: QQ::Equal(QQ::Alias(QQN::Project()->ProjectAsRelated, 'related2')->Project->Name, 'ACME Payment System')
36: )
37: );
38:
39: $this->assertEquals(1, sizeof($objProjectArray));
40: $this->verifyObjectPropertyHelper($objProjectArray, 'Name', 'ACME Website Redesign');
41:
42: }
43:
44: public function testAlias3() {
45: $emptySelect = QQ::Select();
46: $emptySelect->SetSkipPrimaryKey(true);
47: $nVoyel = QQ::Alias(QQN::Person()->ProjectAsManager->Milestone, 'voyel');
48: $nConson = QQ::Alias(QQN::Person()->ProjectAsManager->Milestone, 'conson');
49: $objPersonArray = Person::QueryArray(
50: QQ::IsNotNull($nConson->Id),
51: QQ::Clause(
52: QQ::Expand($nVoyel, QQ::In($nVoyel->Name, array('Milestone A', 'Milestone E', 'Milestone I')), $emptySelect),
53: QQ::Expand($nConson, QQ::NotIn($nConson->Name, array('Milestone A', 'Milestone E', 'Milestone I')), $emptySelect),
54: QQ::GroupBy(QQN::Person()->Id),
55: QQ::Minimum($nVoyel->Name, 'min_voyel'),
56: QQ::Minimum($nConson->Name, 'min_conson'),
57:
58:
59:
60: QQ::Expand(QQN::Person()->ProjectAsManager, null, $emptySelect),
61: QQ::Minimum(QQN::Person()->ProjectAsManager->Id, 'dummy'),
62:
63: QQ::Select(
64: QQN::Person()->FirstName,
65: QQN::Person()->LastName
66: )
67: )
68: );
69: $this->assertEquals(3, sizeof($objPersonArray));
70: $obj = $this->verifyObjectPropertyHelper($objPersonArray, 'LastName', 'Doe');
71: $this->assertNull($obj->GetVirtualAttribute('min_voyel'));
72: $this->assertEquals('Milestone F', $obj->GetVirtualAttribute('min_conson'));
73:
74: $obj = $this->verifyObjectPropertyHelper($objPersonArray, 'LastName', 'Ho');
75: $this->assertEquals('Milestone E', $obj->GetVirtualAttribute('min_voyel'));
76: $this->assertEquals('Milestone D', $obj->GetVirtualAttribute('min_conson'));
77:
78: $obj = $this->verifyObjectPropertyHelper($objPersonArray, 'LastName', 'Wolfe');
79: $this->assertEquals('Milestone A', $obj->GetVirtualAttribute('min_voyel'));
80: $this->assertEquals('Milestone B', $obj->GetVirtualAttribute('min_conson'));
81: }
82: }