forked from parse-community/parse-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseSchemaTest.php
More file actions
266 lines (225 loc) · 8.04 KB
/
Copy pathParseSchemaTest.php
File metadata and controls
266 lines (225 loc) · 8.04 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/**
* ParseSchema Tests.
*
* @see https://parse.com/docs/rest/guide#schemas
*
* @author Júlio César Gonçalves de Oliveira <julio@pinguineras.com.br>
*/
namespace Parse\Test;
use Parse\ParseSchema;
class ParseSchemaTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ParseSchema
*/
private static $schema;
public static function setUpBeforeClass()
{
Helper::setUp();
}
public function setUp()
{
self::$schema = new ParseSchema('SchemaTest');
}
public function tearDown()
{
Helper::tearDown();
self::$schema->delete();
}
public function testSaveSchema()
{
$schema = self::$schema;
$schema->save();
$this->assertEquals('SchemaTest', $schema->get()['className']);
}
public function testGetFieldsSchema()
{
self::createFieldsOfSchema();
// get schema
$getSchema = new ParseSchema('SchemaTest');
$result = $getSchema->get();
$this->assertEquals(ParseSchema::$STRING, $result['fields']['defaultFieldString']['type']);
$this->assertEquals(ParseSchema::$STRING, $result['fields']['stringField']['type']);
$this->assertEquals(ParseSchema::$NUMBER, $result['fields']['numberField']['type']);
$this->assertEquals(ParseSchema::$BOOLEAN, $result['fields']['booleanField']['type']);
$this->assertEquals(ParseSchema::$DATE, $result['fields']['dateField']['type']);
$this->assertEquals(ParseSchema::$FILE, $result['fields']['fileField']['type']);
$this->assertEquals(ParseSchema::$GEO_POINT, $result['fields']['geoPointField']['type']);
$this->assertEquals(ParseSchema::$ARRAY, $result['fields']['arrayField']['type']);
$this->assertEquals(ParseSchema::$OBJECT, $result['fields']['objectField']['type']);
$this->assertEquals(ParseSchema::$POINTER, $result['fields']['pointerField']['type']);
$this->assertEquals(ParseSchema::$RELATION, $result['fields']['relationField']['type']);
}
private static function createFieldsOfSchema()
{
$schema = self::$schema;
// add fields
$schema
->addField('defaultFieldString')
->addString('stringField')
->addNumber('numberField')
->addBoolean('booleanField')
->addDate('dateField')
->addFile('fileField')
->addGeoPoint('geoPointField')
->addArray('arrayField')
->addObject('objectField')
->addPointer('pointerField', '_User')
->addRelation('relationField', '_User');
// save schema
$schema->save();
}
public function testAllSchema()
{
$schema_1 = new ParseSchema('SchemaTest_1');
$schema_2 = new ParseSchema('SchemaTest_2');
$schema_1->save();
$schema_2->save();
$schemas = new ParseSchema();
$results = $schemas->all();
$this->assertGreaterThanOrEqual(2, count($results));
$schema_1->delete();
$schema_2->delete();
}
public function testUpdateSchema()
{
// create
$schema = self::$schema;
$schema->addString('name');
$schema->save();
// update
$schema->deleteField('name');
$schema->addNumber('quantity');
$schema->addField('status', 'Boolean');
$schema->update();
// get
$getSchema = new ParseSchema('SchemaTest');
$result = $getSchema->get();
if (isset($result['fields']['name'])) {
$this->fail('Field not deleted in update action');
}
$this->assertNotNull($result['fields']['quantity']);
$this->assertNotNull($result['fields']['status']);
}
public function testUpdateWrongFieldType()
{
$schema = new ParseSchema();
$this->setExpectedException('Exception', 'WrongType is not a valid type.');
$schema->addField('NewTestField', 'WrongType');
$result = $schema->update();
}
public function testDeleteSchema()
{
$createSchema = new ParseSchema('SchemaDeleteTest');
$createSchema->addField('newField01');
$createSchema->save();
$deleteSchema = new ParseSchema('SchemaDeleteTest');
$deleteSchema->delete();
$getSchema = new ParseSchema('SchemaDeleteTest');
$this->setExpectedException('Parse\ParseException', 'class SchemaDeleteTest does not exist');
$getSchema->get();
}
public function testAssertClassName()
{
$schema = new ParseSchema();
$this->setExpectedException('\Exception', 'You must set a Class Name before make any request.');
$schema->assertClassName();
}
public function testFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addField(null, '_Type');
}
public function testStringFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addString();
}
public function testNumberFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addNumber();
}
public function testBooleanFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addBoolean();
}
public function testDateFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addDate();
}
public function testFileFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addFile();
}
public function testGeoPointFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addGeoPoint();
}
public function testArrayFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addArray();
}
public function testObjectFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addObject();
}
public function testPointFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addPointer(null, '_Type');
}
public function testRelationFieldNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'field name may not be null.');
$schema->addRelation(null, '_Type');
}
public function testPointerTargetClassException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'You need set the targetClass of the Pointer.');
$schema->addPointer('field', null);
}
public function testRelationTargetClassException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'You need set the targetClass of the Relation.');
$schema->addRelation('field', null);
}
public function testTypeNameException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'Type name may not be null.');
$schema->addField('field', null);
}
public function testSchemaNotExistException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'class SchemaTest does not exist');
$schema->get();
}
public function testInvalidTypeException()
{
$schema = self::$schema;
$this->setExpectedException('\Exception', 'StringFormatter is not a valid type.');
$schema->assertTypes('StringFormatter');
}
}