Skip to content

Commit f073994

Browse files
committed
Testing: Extracted copy tests to their own class
1 parent 0f40aeb commit f073994

File tree

4 files changed

+294
-278
lines changed

4 files changed

+294
-278
lines changed

tests/Entity/BookTest.php

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/Entity/ChapterTest.php

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -66,90 +66,7 @@ public function test_delete()
6666
$this->assertNotificationContains($redirectReq, 'Chapter Successfully Deleted');
6767
}
6868

69-
public function test_show_view_has_copy_button()
70-
{
71-
$chapter = $this->entities->chapter();
72-
73-
$resp = $this->asEditor()->get($chapter->getUrl());
74-
$this->withHtml($resp)->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy');
75-
}
76-
77-
public function test_copy_view()
78-
{
79-
$chapter = $this->entities->chapter();
80-
81-
$resp = $this->asEditor()->get($chapter->getUrl('/copy'));
82-
$resp->assertOk();
83-
$resp->assertSee('Copy Chapter');
84-
$this->withHtml($resp)->assertElementExists("input[name=\"name\"][value=\"{$chapter->name}\"]");
85-
$this->withHtml($resp)->assertElementExists('input[name="entity_selection"]');
86-
}
87-
88-
public function test_copy()
89-
{
90-
/** @var Chapter $chapter */
91-
$chapter = Chapter::query()->whereHas('pages')->first();
92-
/** @var Book $otherBook */
93-
$otherBook = Book::query()->where('id', '!=', $chapter->book_id)->first();
94-
95-
$resp = $this->asEditor()->post($chapter->getUrl('/copy'), [
96-
'name' => 'My copied chapter',
97-
'entity_selection' => 'book:' . $otherBook->id,
98-
]);
99-
100-
/** @var Chapter $newChapter */
101-
$newChapter = Chapter::query()->where('name', '=', 'My copied chapter')->first();
102-
103-
$resp->assertRedirect($newChapter->getUrl());
104-
$this->assertEquals($otherBook->id, $newChapter->book_id);
105-
$this->assertEquals($chapter->pages->count(), $newChapter->pages->count());
106-
}
107-
108-
public function test_copy_does_not_copy_non_visible_pages()
109-
{
110-
$chapter = $this->entities->chapterHasPages();
11169

112-
// Hide pages to all non-admin roles
113-
/** @var Page $page */
114-
foreach ($chapter->pages as $page) {
115-
$this->permissions->setEntityPermissions($page, [], []);
116-
}
117-
118-
$this->asEditor()->post($chapter->getUrl('/copy'), [
119-
'name' => 'My copied chapter',
120-
]);
121-
122-
/** @var Chapter $newChapter */
123-
$newChapter = Chapter::query()->where('name', '=', 'My copied chapter')->first();
124-
$this->assertEquals(0, $newChapter->pages()->count());
125-
}
126-
127-
public function test_copy_does_not_copy_pages_if_user_cant_page_create()
128-
{
129-
$chapter = $this->entities->chapterHasPages();
130-
$viewer = $this->users->viewer();
131-
$this->permissions->grantUserRolePermissions($viewer, ['chapter-create-all']);
132-
133-
// Lacking permission results in no copied pages
134-
$this->actingAs($viewer)->post($chapter->getUrl('/copy'), [
135-
'name' => 'My copied chapter',
136-
]);
137-
138-
/** @var Chapter $newChapter */
139-
$newChapter = Chapter::query()->where('name', '=', 'My copied chapter')->first();
140-
$this->assertEquals(0, $newChapter->pages()->count());
141-
142-
$this->permissions->grantUserRolePermissions($viewer, ['page-create-all']);
143-
144-
// Having permission rules in copied pages
145-
$this->actingAs($viewer)->post($chapter->getUrl('/copy'), [
146-
'name' => 'My copied again chapter',
147-
]);
148-
149-
/** @var Chapter $newChapter2 */
150-
$newChapter2 = Chapter::query()->where('name', '=', 'My copied again chapter')->first();
151-
$this->assertEquals($chapter->pages()->count(), $newChapter2->pages()->count());
152-
}
15370

15471
public function test_sort_book_action_visible_if_permissions_allow()
15572
{

0 commit comments

Comments
 (0)