CollectionTest.php
2.29 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
<?php
namespace PhalconRest\Test\Unit\Api;
use App\Constants\AclRoles;
use Phalcon\Acl;
use PhalconRest\Api\Collection;
use PhalconRest\Api\Endpoint;
use PhalconRest\Constants\PostedDataMethods;
class CollectionTest extends \Codeception\TestCase\Test {
/** @var Collection */
protected $collection;
protected function _before() {
$this->collection = Collection::factory('/books')
->name('Books')
->description('a short description');
}
public function testName() {
$this->assertEquals($this->collection->getName(), 'Books');
}
public function testPrefix() {
$this->assertEquals($this->collection->getPrefix(), '/books');
}
public function testIdentifier() {
$this->assertEquals($this->collection->getIdentifier(), '/books');
}
public function testDescription() {
$this->assertEquals($this->collection->getDescription(), 'a short description');
}
public function testGetEndpoints() {
$endpoints = [
Endpoint::get('/all', 'all'),
Endpoint::get('/find/:id', 'find')
];
foreach($endpoints as $endpoint) {
$this->collection->endpoint($endpoint);
}
$this->assertEquals($this->collection->getEndpoints(), $endpoints);
}
public function testGetDefaultPostedDataMethod() {
$this->assertEquals($this->collection->getPostedDataMethod(), PostedDataMethods::AUTO);
}
public function testExpectsJsonData() {
$this->collection->expectsJsonData();
$this->assertEquals($this->collection->getPostedDataMethod(), PostedDataMethods::JSON_BODY);
}
public function testExpectsPostData() {
$this->collection->expectsPostData();
$this->assertEquals($this->collection->getPostedDataMethod(), PostedDataMethods::POST);
}
public function testAllowedRoles() {
$this->collection->allow(AclRoles::ADMINISTRATOR, AclRoles::ADMINISTRATOR);
$this->assertEquals($this->collection->getAllowedRoles(), [AclRoles::ADMINISTRATOR]);
}
public function testDeniedRoles() {
$this->collection->deny(AclRoles::MANAGER, AclRoles::MANAGER, AclRoles::USER);
$this->assertEquals($this->collection->getDeniedRoles(), [AclRoles::MANAGER, AclRoles::USER]);
}
}