11
11
12
12
namespace Textmaster \Unit \Model ;
13
13
14
+ use Textmaster \Model \AuthorInterface ;
14
15
use Textmaster \Model \DocumentInterface ;
15
16
use Textmaster \Model \Project ;
16
17
use Textmaster \Model \ProjectInterface ;
@@ -49,9 +50,43 @@ public function setUp()
49
50
'textmasters ' => ['55c3763e656462000b000027 ' ],
50
51
];
51
52
53
+ $ authors = [
54
+ 'total_pages ' => 1 ,
55
+ 'count ' => 1 ,
56
+ 'page ' => 1 ,
57
+ 'per_page ' => 20 ,
58
+ 'previous_page ' => null ,
59
+ 'next_page ' => null ,
60
+ 'my_authors ' => [
61
+ [
62
+ 'description ' => '' ,
63
+ 'tags ' => [],
64
+ 'status ' => 'my_textmaster ' ,
65
+ 'id ' => '5743286d28cf7f00031eb4c9 ' ,
66
+ 'author_id ' => '55c3763e656462000b000027 ' ,
67
+ 'author_ref ' => 'A-3727-TM ' ,
68
+ 'author_name ' => 'Test ' ,
69
+ 'latest_activity ' => '2017-02-06 16:42:03 UTC ' ,
70
+ 'created_at ' => [
71
+ 'day ' => 23 ,
72
+ 'month ' => 5 ,
73
+ 'year ' => 2016 ,
74
+ 'full ' => '2016-05-23 15:57:33 UTC ' ,
75
+ ],
76
+ 'updated_at ' => [
77
+ 'day ' => 6 ,
78
+ 'month ' => 2 ,
79
+ 'year ' => 2017 ,
80
+ 'full ' => '2017-02-06 14:06:41 UTC ' ,
81
+ ]
82
+ ]
83
+ ]
84
+ ];
85
+
52
86
$ clientMock = $ this ->getMockBuilder ('Textmaster\Client ' )->setMethods (['api ' ])->disableOriginalConstructor ()->getMock ();
53
- $ projectApiMock = $ this ->getMock ('Textmaster\Api\Project ' , ['show ' , 'update ' , 'launch ' ], [$ clientMock ]);
87
+ $ projectApiMock = $ this ->getMock ('Textmaster\Api\Project ' , ['show ' , 'update ' , 'launch ' , ' authors ' ], [$ clientMock ]);
54
88
$ documentApiMock = $ this ->getMock ('Textmaster\Api\FilterableApiInterface ' , ['filter ' , 'getClient ' ]);
89
+ $ projectAuthorApiMock = $ this ->getMock ('Textmaster\Api\Project\Author ' , ['all ' ], [$ clientMock , 123456 ]);
55
90
56
91
$ clientMock ->method ('api ' )
57
92
->willReturn ($ projectApiMock );
@@ -65,6 +100,12 @@ public function setUp()
65
100
$ projectApiMock ->method ('documents ' )
66
101
->willReturn ($ documentApiMock );
67
102
103
+ $ projectApiMock ->method ('authors ' )
104
+ ->willReturn ($ projectAuthorApiMock );
105
+
106
+ $ projectAuthorApiMock ->method ('all ' )
107
+ ->willReturn ($ authors );
108
+
68
109
$ this ->clientMock = $ clientMock ;
69
110
$ this ->projectApiMock = $ projectApiMock ;
70
111
}
@@ -171,6 +212,33 @@ public function shouldUpdate()
171
212
$ this ->assertSame ('Project Beta ' , $ project ->getName ());
172
213
}
173
214
215
+ /**
216
+ * @test
217
+ */
218
+ public function shouldGetPotentialAuthors ()
219
+ {
220
+ $ project = new Project ($ this ->clientMock , '123456 ' );
221
+ $ authors = $ project ->getPotentialAuthors ();
222
+
223
+ $ this ->assertInternalType ('array ' , $ authors );
224
+ $ this ->assertCount (1 , $ authors );
225
+
226
+ foreach ($ authors as $ author ) {
227
+ $ this ->assertInstanceOf (AuthorInterface::class, $ author );
228
+ $ this ->assertSame ('55c3763e656462000b000027 ' , $ author ->getAuthorId ());
229
+ }
230
+ }
231
+
232
+ /**
233
+ * @test
234
+ * @expectedException \Textmaster\Exception\BadMethodCallException
235
+ */
236
+ public function shouldNotGetPotentialAuthorsOnUnsaved ()
237
+ {
238
+ $ project = new Project ($ this ->clientMock );
239
+ $ project ->getPotentialAuthors ();
240
+ }
241
+
174
242
/**
175
243
* @test
176
244
*/
0 commit comments