@@ -264,108 +264,4 @@ public function test_show_view_displays_description_if_no_description_html_set()
264264 $ resp = $ this ->asEditor ()->get ($ book ->getUrl ());
265265 $ resp ->assertSee ("<p>My great<br> \ndescription<br> \n<br> \nwith newlines</p> " , false );
266266 }
267-
268- public function test_show_view_has_copy_button ()
269- {
270- $ book = $ this ->entities ->book ();
271- $ resp = $ this ->asEditor ()->get ($ book ->getUrl ());
272-
273- $ this ->withHtml ($ resp )->assertElementContains ("a[href= \"{$ book ->getUrl ('/copy ' )}\"] " , 'Copy ' );
274- }
275-
276- public function test_copy_view ()
277- {
278- $ book = $ this ->entities ->book ();
279- $ resp = $ this ->asEditor ()->get ($ book ->getUrl ('/copy ' ));
280-
281- $ resp ->assertOk ();
282- $ resp ->assertSee ('Copy Book ' );
283- $ this ->withHtml ($ resp )->assertElementExists ("input[name= \"name \"][value= \"{$ book ->name }\"] " );
284- }
285-
286- public function test_copy ()
287- {
288- /** @var Book $book */
289- $ book = Book::query ()->whereHas ('chapters ' )->whereHas ('pages ' )->first ();
290- $ resp = $ this ->asEditor ()->post ($ book ->getUrl ('/copy ' ), ['name ' => 'My copy book ' ]);
291-
292- /** @var Book $copy */
293- $ copy = Book::query ()->where ('name ' , '= ' , 'My copy book ' )->first ();
294-
295- $ resp ->assertRedirect ($ copy ->getUrl ());
296- $ this ->assertEquals ($ book ->getDirectVisibleChildren ()->count (), $ copy ->getDirectVisibleChildren ()->count ());
297-
298- $ this ->get ($ copy ->getUrl ())->assertSee ($ book ->description_html , false );
299- }
300-
301- public function test_copy_does_not_copy_non_visible_content ()
302- {
303- /** @var Book $book */
304- $ book = Book::query ()->whereHas ('chapters ' )->whereHas ('pages ' )->first ();
305-
306- // Hide child content
307- /** @var BookChild $page */
308- foreach ($ book ->getDirectVisibleChildren () as $ child ) {
309- $ this ->permissions ->setEntityPermissions ($ child , [], []);
310- }
311-
312- $ this ->asEditor ()->post ($ book ->getUrl ('/copy ' ), ['name ' => 'My copy book ' ]);
313- /** @var Book $copy */
314- $ copy = Book::query ()->where ('name ' , '= ' , 'My copy book ' )->first ();
315-
316- $ this ->assertEquals (0 , $ copy ->getDirectVisibleChildren ()->count ());
317- }
318-
319- public function test_copy_does_not_copy_pages_or_chapters_if_user_cant_create ()
320- {
321- /** @var Book $book */
322- $ book = Book::query ()->whereHas ('chapters ' )->whereHas ('directPages ' )->whereHas ('chapters ' )->first ();
323- $ viewer = $ this ->users ->viewer ();
324- $ this ->permissions ->grantUserRolePermissions ($ viewer , ['book-create-all ' ]);
325-
326- $ this ->actingAs ($ viewer )->post ($ book ->getUrl ('/copy ' ), ['name ' => 'My copy book ' ]);
327- /** @var Book $copy */
328- $ copy = Book::query ()->where ('name ' , '= ' , 'My copy book ' )->first ();
329-
330- $ this ->assertEquals (0 , $ copy ->pages ()->count ());
331- $ this ->assertEquals (0 , $ copy ->chapters ()->count ());
332- }
333-
334- public function test_copy_clones_cover_image_if_existing ()
335- {
336- $ book = $ this ->entities ->book ();
337- $ bookRepo = $ this ->app ->make (BookRepo::class);
338- $ coverImageFile = $ this ->files ->uploadedImage ('cover.png ' );
339- $ bookRepo ->updateCoverImage ($ book , $ coverImageFile );
340-
341- $ this ->asEditor ()->post ($ book ->getUrl ('/copy ' ), ['name ' => 'My copy book ' ])->assertRedirect ();
342- /** @var Book $copy */
343- $ copy = Book::query ()->where ('name ' , '= ' , 'My copy book ' )->first ();
344-
345- $ this ->assertNotNull ($ copy ->coverInfo ()->getImage ());
346- $ this ->assertNotEquals ($ book ->coverInfo ()->getImage ()->id , $ copy ->coverInfo ()->getImage ()->id );
347- }
348-
349- public function test_copy_adds_book_to_shelves_if_edit_permissions_allows ()
350- {
351- /** @var Bookshelf $shelfA */
352- /** @var Bookshelf $shelfB */
353- [$ shelfA , $ shelfB ] = Bookshelf::query ()->take (2 )->get ();
354- $ book = $ this ->entities ->book ();
355-
356- $ shelfA ->appendBook ($ book );
357- $ shelfB ->appendBook ($ book );
358-
359- $ viewer = $ this ->users ->viewer ();
360- $ this ->permissions ->grantUserRolePermissions ($ viewer , ['book-update-all ' , 'book-create-all ' , 'bookshelf-update-all ' ]);
361- $ this ->permissions ->setEntityPermissions ($ shelfB );
362-
363-
364- $ this ->asEditor ()->post ($ book ->getUrl ('/copy ' ), ['name ' => 'My copy book ' ]);
365- /** @var Book $copy */
366- $ copy = Book::query ()->where ('name ' , '= ' , 'My copy book ' )->first ();
367-
368- $ this ->assertTrue ($ copy ->shelves ()->where ('id ' , '= ' , $ shelfA ->id )->exists ());
369- $ this ->assertFalse ($ copy ->shelves ()->where ('id ' , '= ' , $ shelfB ->id )->exists ());
370- }
371267}
0 commit comments