]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/EntityTest.php
Finished refactor of entity repos
[bookstack] / tests / Entity / EntityTest.php
index 30858f8d986f6fcb45c5203da666c788beb13485..9fd4eb9ad299bcee4528cbf97e9e581744fd14fe 100644 (file)
@@ -88,8 +88,11 @@ class EntityTest extends TestCase
         $this->asAdmin()
             // Navigate to page create form
             ->visit($chapter->getUrl())
-            ->click('New Page')
-            ->seePageIs($chapter->getUrl() . '/create-page')
+            ->click('New Page');
+
+        $draftPage = \BookStack\Page::where('draft', '=', true)->orderBy('created_at', 'desc')->first();
+
+        $this->seePageIs($draftPage->getUrl())
             // Fill out form
             ->type($page->name, '#name')
             ->type($page->html, '#html')
@@ -133,7 +136,7 @@ class EntityTest extends TestCase
         $this->asAdmin()
             ->visit('/books')
             // Choose to create a book
-            ->click('Add new book')
+            ->click('Create New Book')
             ->seePageIs('/books/create')
             // Fill out form & save
             ->type($book->name, '#name')
@@ -148,8 +151,10 @@ class EntityTest extends TestCase
             ->visit('/books/create')
             ->type($book->name, '#name')
             ->type($book->description, '#description')
-            ->press('Save Book')
-            ->seePageIs('/books/my-first-book-2');
+            ->press('Save Book');
+        
+        $expectedPattern = '/\/books\/my-first-book-[0-9a-zA-Z]{3}/';
+        $this->assertRegExp($expectedPattern, $this->currentUri, "Did not land on expected page [$expectedPattern].\n");
 
         $book = \BookStack\Book::where('slug', '=', 'my-first-book')->first();
         return $book;
@@ -158,12 +163,12 @@ class EntityTest extends TestCase
     public function test_entities_viewable_after_creator_deletion()
     {
         // Create required assets and revisions
-        $creator = $this->getNewUser();
-        $updater = $this->getNewUser();
+        $creator = $this->getEditor();
+        $updater = $this->getEditor();
         $entities = $this->createEntityChainBelongingToUser($creator, $updater);
         $this->actingAs($creator);
         app('BookStack\Repos\UserRepo')->destroy($creator);
-        app('BookStack\Repos\PageRepo')->saveRevision($entities['page']);
+        app('BookStack\Repos\EntityRepo')->savePageRevision($entities['page']);
 
         $this->checkEntitiesViewable($entities);
     }
@@ -171,12 +176,12 @@ class EntityTest extends TestCase
     public function test_entities_viewable_after_updater_deletion()
     {
         // Create required assets and revisions
-        $creator = $this->getNewUser();
-        $updater = $this->getNewUser();
+        $creator = $this->getEditor();
+        $updater = $this->getEditor();
         $entities = $this->createEntityChainBelongingToUser($creator, $updater);
         $this->actingAs($updater);
         app('BookStack\Repos\UserRepo')->destroy($updater);
-        app('BookStack\Repos\PageRepo')->saveRevision($entities['page']);
+        app('BookStack\Repos\EntityRepo')->savePageRevision($entities['page']);
 
         $this->checkEntitiesViewable($entities);
     }
@@ -195,7 +200,7 @@ class EntityTest extends TestCase
 
     public function test_recently_created_pages_view()
     {
-        $user = $this->getNewUser();
+        $user = $this->getEditor();
         $content = $this->createEntityChainBelongingToUser($user);
 
         $this->asAdmin()->visit('/pages/recently-created')
@@ -204,7 +209,7 @@ class EntityTest extends TestCase
 
     public function test_recently_updated_pages_view()
     {
-        $user = $this->getNewUser();
+        $user = $this->getEditor();
         $content = $this->createEntityChainBelongingToUser($user);
 
         $this->asAdmin()->visit('/pages/recently-updated')
@@ -213,15 +218,27 @@ class EntityTest extends TestCase
 
     public function test_old_page_slugs_redirect_to_new_pages()
     {
-        $page = \BookStack\Page::all()->first();
+        $page = \BookStack\Page::first();
         $pageUrl = $page->getUrl();
         $newPageUrl = '/books/' . $page->book->slug . '/page/super-test-page';
+        // Need to save twice since revisions are not generated in seeder.
         $this->asAdmin()->visit($pageUrl)
+            ->clickInElement('#content', 'Edit')
+            ->type('super test', '#name')
+            ->press('Save Page');
+
+        $page = \BookStack\Page::first();
+        $pageUrl = $page->getUrl();
+
+        // Second Save
+        $this->visit($pageUrl)
             ->clickInElement('#content', 'Edit')
             ->type('super test page', '#name')
             ->press('Save Page')
-            ->seePageIs($newPageUrl)
-            ->visit($pageUrl)
+            // Check redirect
+            ->seePageIs($newPageUrl);
+
+        $this->visit($pageUrl)
             ->seePageIs($newPageUrl);
     }
 
@@ -238,7 +255,7 @@ class EntityTest extends TestCase
 
     public function test_recently_created_pages_on_home()
     {
-        $entityChain = $this->createEntityChainBelongingToUser($this->getNewUser());
+        $entityChain = $this->createEntityChainBelongingToUser($this->getEditor());
         $this->asAdmin()->visit('/')
             ->seeInElement('#recently-created-pages', $entityChain['page']->name);
     }