forked from mapasculturais/mapasculturais
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityTest.php
More file actions
133 lines (89 loc) · 4.47 KB
/
Copy pathEntityTest.php
File metadata and controls
133 lines (89 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require_once 'bootstrap.php';
require 'Entity.inc.TestEntities.php';
class EntityTests extends MapasCulturais_TestCase {
function testValidations() {
$entity = new TestEntity;
$this->assertArrayHasKey('requiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$this->assertArrayNotHasKey('notRequiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$entity->notRequiredBrPhone = 'Invalid Phone';
$this->assertArrayHasKey('requiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$this->assertArrayHasKey('notRequiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$entity->notRequiredBrPhone = '(11) 3333-3333';
$this->assertArrayHasKey('requiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$this->assertArrayNotHasKey('notRequiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$entity->notRequiredBrPhone = '(11) 3333-3333';
$this->assertArrayHasKey('requiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$this->assertArrayNotHasKey('notRequiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$entity->notRequiredBrPhone = null;
$this->assertArrayHasKey('requiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$this->assertArrayNotHasKey('notRequiredBrPhone', $entity->validationErrors, print_r($entity->validationErrors, true));
$entity->requiredBrPhone = '(11) 3333-3333';
$this->assertEmpty($entity->validationErrors, print_r($entity->validationErrors, true));
}
function testDirectCircularReference() {
$entities = ['Agent', 'Space', 'Project'];
foreach ($entities as $class) {
$this->user = 'normal';
$e1 = $this->getNewEntity($class);
$e1->save(true);
$e2 = $this->getNewEntity($class);
$e2->parent = $e1;
$e2->save(true);
$e1->parent = $e2;
$errors = $e1->validationErrors;
$this->assertArrayHasKey('parent', $errors, 'Asserting that direct (2 objects) circular references is not allowed.');
}
}
function testIndirectCircularReference() {
$entities = ['Agent', 'Space', 'Project'];
foreach ($entities as $class) {
$this->user = 'normal';
$e1 = $this->getNewEntity($class);
$e1->save(true);
$e2 = $this->getNewEntity($class);
$e2->parent = $e1;
$e2->save(true);
$e3 = $this->getNewEntity($class);
$e3->parent = $e2;
$e3->save(true);
$e1->parent = $e3;
$errors = $e1->validationErrors;
$this->assertArrayHasKey('parent', $errors, 'Asserting that indirect (more then 2 object) circular references is not allowed.');
}
}
function testParentType() {
$entities = ['Space', 'Project'];
foreach ($entities as $class) {
$this->user = 'normal';
$e1 = $this->getNewEntity($class);
$e1->parent = $this->getNewEntity('Agent');
$errors = $e1->validationErrors;
$this->assertArrayHasKey('parent', $errors, 'Asserting that the type of parent entity must be of the same type of the child entity.');
}
}
function testParentIsNotChild() {
$entities = ['Space', 'Project'];
foreach ($entities as $class) {
$this->user = 'normal';
$e1 = $this->getNewEntity($class);
$e1->parent = $e1;
$errors = $e1->validationErrors;
$this->assertArrayHasKey('parent', $errors, 'Asserting that the parent could not be the child.');
}
}
function testUpdateTimestamp(){
$classes = ['Space', 'Project', 'Event', 'Agent'];
$this->user = 'admin';
foreach($classes as $class){
$entities = $this->app->repo($class)->findAll();
foreach($entities as $entity){
$timestamp = $entity->updateTimestamp;
$entity->name = $entity->name . ' changed';
$entity->save(true);
$entity->refresh();
$this->assertGreaterThan($timestamp, $entity->updateTimestamp);
}
}
}
}