1
+ <?php namespace Gitlab \Tests \Api ;
2
+
3
+ use Gitlab \Api \AbstractApi ;
4
+
5
+ class GroupsTest extends TestCase
6
+ {
7
+ /**
8
+ * @test
9
+ */
10
+ public function shouldGetAllProjects ()
11
+ {
12
+ $ expectedArray = array (
13
+ array ('id ' => 1 , 'name ' => 'A group ' ),
14
+ array ('id ' => 2 , 'name ' => 'Another group ' ),
15
+ );
16
+
17
+ $ api = $ this ->getApiMock ();
18
+ $ api ->expects ($ this ->once ())
19
+ ->method ('get ' )
20
+ ->with ('groups ' , array ('page ' => 1 , 'per_page ' => 10 ))
21
+ ->will ($ this ->returnValue ($ expectedArray ))
22
+ ;
23
+
24
+ $ this ->assertEquals ($ expectedArray , $ api ->all (1 , 10 ));
25
+ }
26
+
27
+ /**
28
+ * @test
29
+ */
30
+ public function shouldNotNeedPaginationWhenGettingGroups ()
31
+ {
32
+ $ expectedArray = array (
33
+ array ('id ' => 1 , 'name ' => 'A group ' ),
34
+ array ('id ' => 2 , 'name ' => 'Another group ' ),
35
+ );
36
+
37
+ $ api = $ this ->getApiMock ();
38
+ $ api ->expects ($ this ->once ())
39
+ ->method ('get ' )
40
+ ->with ('groups ' , array ('page ' => 1 , 'per_page ' => AbstractApi::PER_PAGE ))
41
+ ->will ($ this ->returnValue ($ expectedArray ))
42
+ ;
43
+
44
+ $ this ->assertEquals ($ expectedArray , $ api ->all ());
45
+ }
46
+
47
+ /**
48
+ * @test
49
+ */
50
+ public function shouldShowGroup ()
51
+ {
52
+ $ expectedArray = array ('id ' => 1 , 'name ' => 'A group ' );
53
+
54
+ $ api = $ this ->getApiMock ();
55
+ $ api ->expects ($ this ->once ())
56
+ ->method ('get ' )
57
+ ->with ('groups/1 ' )
58
+ ->will ($ this ->returnValue ($ expectedArray ))
59
+ ;
60
+
61
+ $ this ->assertEquals ($ expectedArray , $ api ->show (1 ));
62
+ }
63
+
64
+ /**
65
+ * @test
66
+ */
67
+ public function shouldCreateGroup ()
68
+ {
69
+ $ expectedArray = array ('id ' => 1 , 'name ' => 'A new group ' );
70
+
71
+ $ api = $ this ->getApiMock ();
72
+ $ api ->expects ($ this ->once ())
73
+ ->method ('post ' )
74
+ ->with ('groups ' , array ('name ' => 'A new group ' , 'path ' => 'a-new-group ' ))
75
+ ->will ($ this ->returnValue ($ expectedArray ))
76
+ ;
77
+
78
+ $ this ->assertEquals ($ expectedArray , $ api ->create ('A new group ' , 'a-new-group ' ));
79
+ }
80
+
81
+ /**
82
+ * @test
83
+ */
84
+ public function shouldTransferProjectToGroup ()
85
+ {
86
+ $ expectedBool = true ;
87
+
88
+ $ api = $ this ->getApiMock ();
89
+ $ api ->expects ($ this ->once ())
90
+ ->method ('post ' )
91
+ ->with ('groups/1/projects/2 ' )
92
+ ->will ($ this ->returnValue ($ expectedBool ))
93
+ ;
94
+
95
+ $ this ->assertEquals ($ expectedBool , $ api ->transfer (1 , 2 ));
96
+ }
97
+
98
+ /**
99
+ * @test
100
+ */
101
+ public function shouldGetMembers ()
102
+ {
103
+ $ expectedArray = array (
104
+ array ('id ' => 1 , 'name ' => 'Matt ' ),
105
+ array ('id ' => 2 , 'name ' => 'Bob ' )
106
+ );
107
+
108
+ $ api = $ this ->getApiMock ();
109
+ $ api ->expects ($ this ->once ())
110
+ ->method ('get ' )
111
+ ->with ('groups/1/members ' )
112
+ ->will ($ this ->returnValue ($ expectedArray ))
113
+ ;
114
+
115
+ $ this ->assertEquals ($ expectedArray , $ api ->members (1 ));
116
+ }
117
+
118
+ /**
119
+ * @test
120
+ */
121
+ public function shouldAddMember ()
122
+ {
123
+ $ expectedArray = array ('id ' => 1 , 'name ' => 'Matt ' );
124
+
125
+ $ api = $ this ->getApiMock ();
126
+ $ api ->expects ($ this ->once ())
127
+ ->method ('post ' )
128
+ ->with ('groups/1/members ' , array ('user_id ' => 2 , 'access_level ' => 3 ))
129
+ ->will ($ this ->returnValue ($ expectedArray ))
130
+ ;
131
+
132
+ $ this ->assertEquals ($ expectedArray , $ api ->addMember (1 , 2 , 3 ));
133
+ }
134
+
135
+ /**
136
+ * @test
137
+ */
138
+ public function shouldRemoveMember ()
139
+ {
140
+ $ expectedBool = true ;
141
+
142
+ $ api = $ this ->getApiMock ();
143
+ $ api ->expects ($ this ->once ())
144
+ ->method ('delete ' )
145
+ ->with ('groups/1/members/2 ' )
146
+ ->will ($ this ->returnValue ($ expectedBool ))
147
+ ;
148
+
149
+ $ this ->assertEquals ($ expectedBool , $ api ->removeMember (1 , 2 ));
150
+ }
151
+
152
+ protected function getApiClass ()
153
+ {
154
+ return 'Gitlab\Api\Groups ' ;
155
+ }
156
+ }
0 commit comments