}
},
"autoload-dev": {
- "classmap": [
- "tests/TestCase.php",
- "tests/BrowserKitTest.php"
- ]
+ "psr-4": {
+ "Tests\\": "tests/"
+ }
},
"scripts": {
"post-root-package-install": [
-<?php
+<?php namespace Tests;
class ActivityTrackingTest extends BrowserKitTest
-<?php
+<?php namespace Tests;
class AttachmentTest extends BrowserKitTest
{
{
$page = \BookStack\Page::first();
$this->asAdmin();
- $admin = $this->getAdmin();
$fileName = 'upload_test_file.txt';
$this->uploadFile($fileName, $page->id);
-<?php
+<?php namespace Tests;
use BookStack\Notifications\ConfirmEmail;
use Illuminate\Support\Facades\Notification;
->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;
});
->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()
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', [
-<?php
+<?php namespace Tests;
use BookStack\User;
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();
}
$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],
$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,
$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],
-<?php
+<?php namespace Tests;
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('/'));
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');
->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'
-<?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;
{
$app = require __DIR__.'/../bootstrap/app.php';
- $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+ $app->make(Kernel::class)->bootstrap();
return $app;
}
*/
public function getAdmin() {
if($this->admin === null) {
- $adminRole = \BookStack\Role::getRole('admin');
+ $adminRole = Role::getRole('admin');
$this->admin = $adminRole->users->first();
}
return $this->admin;
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];
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;
}
/**
* Check if the page contains the given element.
* @param string $selector
- * @return bool
*/
protected function pageHasElement($selector)
{
/**
* Check if the page contains the given element.
* @param string $selector
- * @return bool
*/
protected function pageNotHasElement($selector)
{
--- /dev/null
+<?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
-<?php
+<?php namespace Tests;
class EntitySearchTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class EntityTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class MarkdownTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class PageContentTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class PageDraftTest extends BrowserKitTest
-<?php
+<?php namespace Tests;
class SortTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
use BookStack\Tag;
use BookStack\Page;
-<?php
+<?php namespace Tests;
class ImageTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class RestrictionsTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class RolesTest extends BrowserKitTest
{
-<?php
+<?php namespace Tests;
class PublicActionTest extends BrowserKitTest
{
-<?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
-<?php
+<?php namespace Tests;
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')
$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)