1111
1212namespace Textmaster \Unit \Model ;
1313
14+ use Textmaster \Model \AuthorInterface ;
1415use Textmaster \Model \DocumentInterface ;
1516use Textmaster \Model \Project ;
1617use Textmaster \Model \ProjectInterface ;
@@ -49,9 +50,43 @@ public function setUp()
4950 'textmasters ' => ['55c3763e656462000b000027 ' ],
5051 ];
5152
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+
5286 $ 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 ]);
5488 $ documentApiMock = $ this ->getMock ('Textmaster\Api\FilterableApiInterface ' , ['filter ' , 'getClient ' ]);
89+ $ projectAuthorApiMock = $ this ->getMock ('Textmaster\Api\Project\Author ' , ['all ' ], [$ clientMock , 123456 ]);
5590
5691 $ clientMock ->method ('api ' )
5792 ->willReturn ($ projectApiMock );
@@ -65,6 +100,12 @@ public function setUp()
65100 $ projectApiMock ->method ('documents ' )
66101 ->willReturn ($ documentApiMock );
67102
103+ $ projectApiMock ->method ('authors ' )
104+ ->willReturn ($ projectAuthorApiMock );
105+
106+ $ projectAuthorApiMock ->method ('all ' )
107+ ->willReturn ($ authors );
108+
68109 $ this ->clientMock = $ clientMock ;
69110 $ this ->projectApiMock = $ projectApiMock ;
70111 }
@@ -171,6 +212,33 @@ public function shouldUpdate()
171212 $ this ->assertSame ('Project Beta ' , $ project ->getName ());
172213 }
173214
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+
174242 /**
175243 * @test
176244 */
0 commit comments