]> BookStack Code Mirror - bookstack/commitdiff
Namespaced tests to align with new laravel default
authorDan Brown <redacted>
Sat, 4 Feb 2017 11:58:42 +0000 (11:58 +0000)
committerDan Brown <redacted>
Sat, 4 Feb 2017 11:58:42 +0000 (11:58 +0000)
21 files changed:
composer.json
tests/ActivityTrackingTest.php
tests/AttachmentTest.php
tests/Auth/AuthTest.php
tests/Auth/LdapTest.php
tests/Auth/SocialAuthTest.php
tests/BrowserKitTest.php
tests/CreatesApplication.php [new file with mode: 0644]
tests/Entity/EntitySearchTest.php
tests/Entity/EntityTest.php
tests/Entity/MarkdownTest.php
tests/Entity/PageContentTest.php
tests/Entity/PageDraftTest.php
tests/Entity/SortTest.php
tests/Entity/TagTest.php
tests/ImageTest.php
tests/Permissions/RestrictionsTest.php
tests/Permissions/RolesTest.php
tests/PublicActionTest.php
tests/TestCase.php
tests/UserProfileTest.php

index 959bdbdc2930bc256682a0dae944a51a96f58c7b..5755afffecddd7dccd96698d10a7e80e942ba0c0 100644 (file)
         }
     },
     "autoload-dev": {
-        "classmap": [
-            "tests/TestCase.php",
-            "tests/BrowserKitTest.php"
-        ]
+        "psr-4": {
+            "Tests\\": "tests/"
+        }
     },
     "scripts": {
         "post-root-package-install": [
index 1373179966f1e7c3b97c685d5c88f00fc09d2009..bb65fbcf4b8745ec7d9b39c8e0bd5b20de1cbe71 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 
 class ActivityTrackingTest extends BrowserKitTest
index f99051a72a569fdcc680e71314d7b09fbbf05bbb..a17f003dbb3f8af95d8cb8b39fd50d98d3f08bd7 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class AttachmentTest extends BrowserKitTest
 {
@@ -75,7 +75,6 @@ class AttachmentTest extends BrowserKitTest
     {
         $page = \BookStack\Page::first();
         $this->asAdmin();
-        $admin = $this->getAdmin();
         $fileName = 'upload_test_file.txt';
 
         $this->uploadFile($fileName, $page->id);
index f7595883853aee417e87d08c489beef6e55a4269..4de35faff089c500aa6e0c58b475323d7ba37f94 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 use BookStack\Notifications\ConfirmEmail;
 use Illuminate\Support\Facades\Notification;
@@ -88,7 +88,7 @@ class AuthTest extends BrowserKitTest
             ->press('Resend Confirmation Email');
 
         // Get confirmation and confirm notification matches
-        $emailConfirmation = DB::table('email_confirmations')->where('user_id', '=', $dbUser->id)->first();
+        $emailConfirmation = \DB::table('email_confirmations')->where('user_id', '=', $dbUser->id)->first();
         Notification::assertSentTo($dbUser, ConfirmEmail::class, function($notification, $channels) use ($emailConfirmation) {
             return $notification->token === $emailConfirmation->token;
         });
@@ -177,7 +177,7 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/settings/users');
 
             $userPassword = \BookStack\User::find($user->id)->password;
-            $this->assertTrue(Hash::check('newpassword', $userPassword));
+            $this->assertTrue(\Hash::check('newpassword', $userPassword));
     }
 
     public function test_user_deletion()
@@ -238,7 +238,6 @@ class AuthTest extends BrowserKitTest
         Notification::assertSentTo($user, \BookStack\Notifications\ResetPassword::class);
         $n = Notification::sent($user, \BookStack\Notifications\ResetPassword::class);
 
-        $reset = DB::table('password_resets')->where('email', '=', '[email protected]')->first();
         $this->visit('/password/reset/' . $n->first()->token)
             ->see('Reset Password')
             ->submitForm('Reset Password', [
index 80d0c9fe29ef5ff542340c3b05633063857d5216..681ead91c7e7bffda43284200b00e90bf32a8c9a 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 use BookStack\User;
 
 class LdapTest extends BrowserKitTest
@@ -12,7 +12,7 @@ class LdapTest extends BrowserKitTest
     {
         parent::setUp();
         app('config')->set(['auth.method' => 'ldap', 'services.ldap.base_dn' => 'dc=ldap,dc=local', 'auth.providers.users.driver' => 'ldap']);
-        $this->mockLdap = Mockery::mock(BookStack\Services\Ldap::class);
+        $this->mockLdap = \Mockery::mock(\BookStack\Services\Ldap::class);
         $this->app['BookStack\Services\Ldap'] = $this->mockLdap;
         $this->mockUser = factory(User::class)->make();
     }
@@ -22,7 +22,7 @@ class LdapTest extends BrowserKitTest
         $this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
         $this->mockLdap->shouldReceive('setVersion')->once();
         $this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
-            ->with($this->resourceId, config('services.ldap.base_dn'), Mockery::type('string'), Mockery::type('array'))
+            ->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
             ->andReturn(['count' => 1, 0 => [
                 'uid' => [$this->mockUser->name],
                 'cn' => [$this->mockUser->name],
@@ -50,7 +50,7 @@ class LdapTest extends BrowserKitTest
         $this->mockLdap->shouldReceive('setVersion')->once();
         $ldapDn = 'cn=test-user,dc=test' . config('services.ldap.base_dn');
         $this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
-            ->with($this->resourceId, config('services.ldap.base_dn'), Mockery::type('string'), Mockery::type('array'))
+            ->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
             ->andReturn(['count' => 1, 0 => [
                 'cn' => [$this->mockUser->name],
                 'dn' => $ldapDn,
@@ -73,7 +73,7 @@ class LdapTest extends BrowserKitTest
         $this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
         $this->mockLdap->shouldReceive('setVersion')->once();
         $this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
-            ->with($this->resourceId, config('services.ldap.base_dn'), Mockery::type('string'), Mockery::type('array'))
+            ->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
             ->andReturn(['count' => 1, 0 => [
                 'uid' => [$this->mockUser->name],
                 'cn' => [$this->mockUser->name],
index aff86a81e853b2ce23729bc9adfb03c785a395d7..e3494d073e84ff59d52201f6c4ebe2e6242fd783 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class SocialAuthTest extends BrowserKitTest
 {
@@ -11,10 +11,10 @@ class SocialAuthTest extends BrowserKitTest
         $this->setSettings(['registration-enabled' => 'true']);
         config(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
 
-        $mockSocialite = Mockery::mock('Laravel\Socialite\Contracts\Factory');
+        $mockSocialite = \Mockery::mock('Laravel\Socialite\Contracts\Factory');
         $this->app['Laravel\Socialite\Contracts\Factory'] = $mockSocialite;
-        $mockSocialDriver = Mockery::mock('Laravel\Socialite\Contracts\Provider');
-        $mockSocialUser = Mockery::mock('\Laravel\Socialite\Contracts\User');
+        $mockSocialDriver = \Mockery::mock('Laravel\Socialite\Contracts\Provider');
+        $mockSocialUser = \Mockery::mock('\Laravel\Socialite\Contracts\User');
 
         $mockSocialite->shouldReceive('driver')->twice()->with('google')->andReturn($mockSocialDriver);
         $mockSocialDriver->shouldReceive('redirect')->once()->andReturn(redirect('/'));
@@ -34,18 +34,16 @@ class SocialAuthTest extends BrowserKitTest
 
     public function test_social_login()
     {
-        $user = factory(\BookStack\User::class)->make();
-
         config([
             'GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc',
             'GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc',
             'APP_URL' => 'http://localhost'
         ]);
 
-        $mockSocialite = Mockery::mock('Laravel\Socialite\Contracts\Factory');
+        $mockSocialite = \Mockery::mock('Laravel\Socialite\Contracts\Factory');
         $this->app['Laravel\Socialite\Contracts\Factory'] = $mockSocialite;
-        $mockSocialDriver = Mockery::mock('Laravel\Socialite\Contracts\Provider');
-        $mockSocialUser = Mockery::mock('\Laravel\Socialite\Contracts\User');
+        $mockSocialDriver = \Mockery::mock('Laravel\Socialite\Contracts\Provider');
+        $mockSocialUser = \Mockery::mock('\Laravel\Socialite\Contracts\User');
 
         $mockSocialUser->shouldReceive('getId')->twice()->andReturn('logintest123');
 
@@ -68,7 +66,7 @@ class SocialAuthTest extends BrowserKitTest
         ->seePageIs('/login');
 
         // Test social callback with matching social account
-        DB::table('social_accounts')->insert([
+        \DB::table('social_accounts')->insert([
             'user_id' => $this->getAdmin()->id,
             'driver' => 'github',
             'driver_id' => 'logintest123'
index 0a97c1292cee49ddfb85772d04535b6e9ee00327..674aef9844fd7fedbe90e9ad3a1e6ecd76691762 100644 (file)
@@ -1,9 +1,12 @@
-<?php
+<?php namespace Tests;
 
+use BookStack\Role;
+use Illuminate\Contracts\Console\Kernel;
 use Illuminate\Foundation\Testing\DatabaseTransactions;
+use Laravel\BrowserKitTesting\TestCase;
 use Symfony\Component\DomCrawler\Crawler;
 
-abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
+abstract class BrowserKitTest extends TestCase
 {
 
     use DatabaseTransactions;
@@ -28,7 +31,7 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     {
         $app = require __DIR__.'/../bootstrap/app.php';
 
-        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+        $app->make(Kernel::class)->bootstrap();
 
         return $app;
     }
@@ -48,7 +51,7 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
      */
     public function getAdmin() {
         if($this->admin === null) {
-            $adminRole = \BookStack\Role::getRole('admin');
+            $adminRole = Role::getRole('admin');
             $this->admin = $adminRole->users->first();
         }
         return $this->admin;
@@ -95,9 +98,9 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     protected function createEntityChainBelongingToUser($creatorUser, $updaterUser = false)
     {
         if ($updaterUser === false) $updaterUser = $creatorUser;
-        $book = factory(BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
-        $chapter = factory(BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
-        $page = factory(BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]);
+        $book = factory(\BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
+        $chapter = factory(\BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
+        $page = factory(\BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]);
         $book->chapters()->saveMany([$chapter]);
         $chapter->pages()->saveMany([$page]);
         $restrictionService = $this->app[\BookStack\Services\PermissionService::class];
@@ -117,7 +120,7 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     protected function getEditor($attributes = [])
     {
         $user = factory(\BookStack\User::class)->create($attributes);
-        $role = \BookStack\Role::getRole('editor');
+        $role = Role::getRole('editor');
         $user->attachRole($role);;
         return $user;
     }
@@ -211,7 +214,6 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     /**
      * Check if the page contains the given element.
      * @param  string  $selector
-     * @return bool
      */
     protected function pageHasElement($selector)
     {
@@ -223,7 +225,6 @@ abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
     /**
      * Check if the page contains the given element.
      * @param  string  $selector
-     * @return bool
      */
     protected function pageNotHasElement($selector)
     {
diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php
new file mode 100644 (file)
index 0000000..42a5da2
--- /dev/null
@@ -0,0 +1,18 @@
+<?php namespace Tests;
+
+use Illuminate\Contracts\Console\Kernel;
+
+trait CreatesApplication
+{
+    /**
+     * Creates the application.
+     *
+     * @return \Illuminate\Foundation\Application
+     */
+    public function createApplication()
+    {
+        $app = require __DIR__.'/../bootstrap/app.php';
+        $app->make(Kernel::class)->bootstrap();
+        return $app;
+    }
+}
\ No newline at end of file
index 23351e5462837e2384b7b7c71c5d78eb3ee6447b..4ef8d46fbf0643815540633d149d71d402e23629 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class EntitySearchTest extends BrowserKitTest
 {
index 1b115ad65112cf3a600660959840af3afb06fd57..5fa331737148f08419d111c74ff8c8ee9bb18164 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class EntityTest extends BrowserKitTest
 {
index 03f3aa12fecc2fd2ccd30c19320c6a6202712cc7..b85e92565aa69037982e82271c41cf19cd46e9d5 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class MarkdownTest extends BrowserKitTest
 {
index 3a005bc6773705445923dd0c3d188f769f500349..4f65d3406449e3e0d42192bf494d9a35bfdb6b85 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class PageContentTest extends BrowserKitTest
 {
index de875c3f3b09b2dbd2acc9f0cf0966c29976e935..b8ac9d3aeef6d37f86022986a8371b725aa1028a 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 
 class PageDraftTest extends BrowserKitTest
index 3c6400d5817a26e3493cb61e3506e83c81a01d2c..d61b3f56f494bfaf00fa1cf5bee4aaa1aca3973f 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class SortTest extends BrowserKitTest
 {
index f4ce581e3f93d49571213b0cbeb34fe24a457ce1..257c207891e0befcc92cedd00db213faecc47d58 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 use BookStack\Tag;
 use BookStack\Page;
index debde848c00422e0df0cdc85bcbd431cca63ac02..3bb41138bae7d50dd8d9821fed27bf0ad54ebad0 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class ImageTest extends BrowserKitTest
 {
index e874fccaeb2b73ea47badbcf7eba697cd9927737..7007985e4ff19d72738e3c26919666290db4471f 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class RestrictionsTest extends BrowserKitTest
 {
index a4b5029150f26ff8099f65dae0015d0a51372ed4..24b8ae0f5fbc4717ff7fdc92b83cb68c2f7a15f6 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class RolesTest extends BrowserKitTest
 {
index 6127e1cd40bdd8a878f6f219e1f2e622b54baf9e..422511dbfc6ecf30c9c6bc28b7494afa2087f24d 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class PublicActionTest extends BrowserKitTest
 {
index e0455f44712cd424c2ddea4d8f5dd670251c516f..6b97682e8584f19b8873b53ae286b2e84a508acf 100644 (file)
@@ -1,31 +1,8 @@
-<?php
+<?php namespace Tests;
 
-use Illuminate\Foundation\Testing\DatabaseTransactions;
-use Symfony\Component\DomCrawler\Crawler;
+use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
 
-class TestCase extends Illuminate\Foundation\Testing\TestCase
+abstract class TestCase extends BaseTestCase
 {
-
-    use DatabaseTransactions;
-
-    /**
-     * The base URL of the application.
-     *
-     * @var string
-     */
-    public $baseUrl = 'http://localhost';
-
-    /**
-     * Creates the application.
-     *
-     * @return \Illuminate\Foundation\Application
-     */
-    public function createApplication()
-    {
-        $app = require __DIR__.'/../bootstrap/app.php';
-
-        $app->make(Kernel::class)->bootstrap();
-
-        return $app;
-    }
-}
+    use CreatesApplication;
+}
\ No newline at end of file
index a448e3a9f6429de1f28ac954b616454550759abd..12f88483f6a6e6e2171fec1034c514ecfb8eda60 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php namespace Tests;
 
 class UserProfileTest extends BrowserKitTest
 {
@@ -55,8 +55,8 @@ class UserProfileTest extends BrowserKitTest
         $newUser = $this->getEditor();
         $this->actingAs($newUser);
         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
-        Activity::add($entities['book'], 'book_update', $entities['book']->id);
-        Activity::add($entities['page'], 'page_create', $entities['book']->id);
+        \Activity::add($entities['book'], 'book_update', $entities['book']->id);
+        \Activity::add($entities['page'], 'page_create', $entities['book']->id);
 
         $this->asAdmin()->visit('/user/' . $newUser->id)
             ->seeInElement('#recent-activity', 'updated book')
@@ -69,8 +69,8 @@ class UserProfileTest extends BrowserKitTest
         $newUser = $this->getEditor();
         $this->actingAs($newUser);
         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
-        Activity::add($entities['book'], 'book_update', $entities['book']->id);
-        Activity::add($entities['page'], 'page_create', $entities['book']->id);
+        \Activity::add($entities['book'], 'book_update', $entities['book']->id);
+        \Activity::add($entities['page'], 'page_create', $entities['book']->id);
 
         $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
             ->seePageIs('/user/' . $newUser->id)