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
|
<?php
namespace Psecio\Gatekeeper;
class UserGroupCollectionTest extends \Psecio\Gatekeeper\Base
{
/**
* Test the location of groups a member is a part of
*/
public function testFindGroupsByUserId()
{
$userId = 1;
$return = array(
array('name' => 'group1', 'description' => 'Group #1'),
array('name' => 'group2', 'description' => 'Group #2')
);
$ds = $this->buildMock($return, 'fetch');
$groups = new UserGroupCollection($ds);
$groups->findByUserId($userId);
$this->assertCount(2, $groups);
}
/**
* Test the creation of new collection items based on data given
*/
public function testCreateRecordsFromModelDataById()
{
$ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
->disableOriginalConstructor()
->setMethods(array('save', 'fetch'))
->getMock();
$ds->method('save')->willReturn(true);
$userModel = new UserModel($ds, array('id' => 1));
$data = array(array('id' => 1, 'name' => 'Group #1'));
$ds->method('fetch')->willReturn($data);
$groupIdList = array(1, 2, 3);
$groups = new UserGroupCollection($ds);
$groups->create($userModel, $groupIdList);
$this->assertEquals(
count($groups->toArray()), count($groupIdList)
);
}
/**
* Test the creation of new collection items based on data given
*/
public function testCreateRecordsFromModelDataByName()
{
$ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
->disableOriginalConstructor()
->setMethods(array('save', 'fetch'))
->getMock();
$ds->method('save')->willReturn(true);
$userModel = new UserModel($ds, array('id' => 1));
$data = array(array('id' => 1, 'name' => 'Group #1'));
$ds->method('fetch')->willReturn($data);
$groupNameList = array('group1', 'group2', 'group3');
$groups = new UserGroupCollection($ds);
$groups->create($userModel, $groupNameList);
$this->assertEquals(
count($groups->toArray()), count($groupNameList)
);
}
}
|