]> BookStack Code Mirror - bookstack/blobdiff - tests/CommandsTest.php
Rolled tri-layout to page edit and book-create
[bookstack] / tests / CommandsTest.php
index 5df82ee513aeef49c2bc6d5f837539f5bc46c37c..a884809696d32cd4e4126f7c7c68121738ee905f 100644 (file)
@@ -1,8 +1,10 @@
 <?php namespace Tests;
 
-use BookStack\JointPermission;
-use BookStack\Page;
-use BookStack\Repos\EntityRepo;
+use BookStack\Auth\Permissions\JointPermission;
+use BookStack\Entities\Page;
+use BookStack\Entities\Repos\EntityRepo;
+use BookStack\Auth\User;
+use BookStack\Entities\Repos\PageRepo;
 
 class CommandsTest extends TestCase
 {
@@ -52,10 +54,10 @@ class CommandsTest extends TestCase
     public function test_clear_revisions_command()
     {
         $this->asEditor();
-        $entityRepo = $this->app[EntityRepo::class];
+        $pageRepo = app(PageRepo::class);
         $page = Page::first();
-        $entityRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
-        $entityRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
+        $pageRepo->updatePage($page, $page->book_id, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']);
+        $pageRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']);
 
         $this->assertDatabaseHas('page_revisions', [
             'page_id' => $page->id,
@@ -99,4 +101,22 @@ class CommandsTest extends TestCase
 
         $this->assertDatabaseHas('joint_permissions', ['entity_id' => $page->id]);
     }
+
+    public function test_add_admin_command()
+    {
+        $exitCode = \Artisan::call('bookstack:create-admin', [
+            '--email' => '[email protected]',
+            '--name' => 'Admin Test',
+            '--password' => 'testing-4',
+        ]);
+        $this->assertTrue($exitCode === 0, 'Command executed successfully');
+
+        $this->assertDatabaseHas('users', [
+            'email' => '[email protected]',
+            'name' => 'Admin Test'
+        ]);
+
+        $this->assertTrue(User::where('email', '=', '[email protected]')->first()->hasSystemRole('admin'), 'User has admin role as expected');
+        $this->assertTrue(\Auth::attempt(['email' => '[email protected]', 'password' => 'testing-4']), 'Password stored as expected');
+    }
 }