Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2017-01-25 19:35:40 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
6669998c10e66ebfa2d492290efd23f34ae66463
6669998c
1 parent
492e2f17
Upgraded to Laravel 5.4
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
276 additions
and
245 deletions
app/Exceptions/Handler.php
app/Http/Controllers/Controller.php
composer.json
composer.lock
tests/ActivityTrackingTest.php
tests/AttachmentTest.php
tests/Auth/AuthTest.php
tests/Auth/LdapTest.php
tests/Auth/SocialAuthTest.php
tests/BrowserKitTest.php
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
version
app/Exceptions/Handler.php
View file @
6669998
...
...
@@ -3,9 +3,9 @@
namespace
BookStack\Exceptions
;
use
Exception
;
use
Illuminate\Contracts\Validation\ValidationException
;
use
Illuminate\Auth\AuthenticationException
;
use
Illuminate\Validation\ValidationException
;
use
Illuminate\Database\Eloquent\ModelNotFoundException
;
use
PhpSpec\Exception\Example\ErrorException
;
use
Symfony\Component\HttpKernel\Exception\HttpException
;
use
Illuminate\Foundation\Exceptions\Handler
as
ExceptionHandler
;
use
Illuminate\Auth\Access\AuthorizationException
;
...
...
app/Http/Controllers/Controller.php
View file @
6669998
...
...
@@ -4,7 +4,7 @@ namespace BookStack\Http\Controllers;
use
BookStack\Ownable
;
use
Illuminate\Foundation\Bus\DispatchesJobs
;
use
Illuminate\Http\Exception\HttpResponseException
;
use
Illuminate\Http\Exception
s
\HttpResponseException
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
as
BaseController
;
use
Illuminate\Foundation\Validation\ValidatesRequests
;
...
...
composer.json
View file @
6669998
...
...
@@ -6,17 +6,18 @@
"type"
:
"project"
,
"require"
:
{
"php"
:
">=5.6.4"
,
"laravel/framework"
:
"
^5.3.4
"
,
"laravel/framework"
:
"
5.4.*
"
,
"ext-tidy"
:
"*"
,
"intervention/image"
:
"^2.3"
,
"laravel/socialite"
:
"^
2
.0"
,
"barryvdh/laravel-ide-helper"
:
"^2.
1
"
,
"barryvdh/laravel-debugbar"
:
"^2.
2.3
"
,
"laravel/socialite"
:
"^
3
.0"
,
"barryvdh/laravel-ide-helper"
:
"^2.
2.3
"
,
"barryvdh/laravel-debugbar"
:
"^2.
3.2
"
,
"league/flysystem-aws-s3-v3"
:
"^1.0"
,
"barryvdh/laravel-dompdf"
:
"^0.7"
,
"predis/predis"
:
"^1.1"
,
"gathercontent/htmldiff"
:
"^0.2.1"
,
"barryvdh/laravel-snappy"
:
"^0.3.1"
"barryvdh/laravel-snappy"
:
"^0.3.1"
,
"laravel/browser-kit-testing"
:
"^1.0"
},
"require-dev"
:
{
"fzaninotto/faker"
:
"~1.4"
,
...
...
@@ -35,7 +36,8 @@
},
"autoload-dev"
:
{
"classmap"
:
[
"tests/TestCase.php"
"tests/TestCase.php"
,
"tests/BrowserKitTest.php"
]
},
"scripts"
:
{
...
...
composer.lock
View file @
6669998
This diff could not be displayed because it is too large.
tests/ActivityTrackingTest.php
View file @
6669998
<?php
use
Illuminate\Foundation\Testing\WithoutMiddleware
;
use
Illuminate\Foundation\Testing\DatabaseMigrations
;
use
Illuminate\Foundation\Testing\DatabaseTransactions
;
class
ActivityTrackingTest
extends
TestCase
class
ActivityTrackingTest
extends
BrowserKitTest
{
public
function
test_recently_viewed_books
()
...
...
tests/AttachmentTest.php
View file @
6669998
<?php
class
AttachmentTest
extends
TestCase
class
AttachmentTest
extends
BrowserKitTest
{
/**
* Get a test file that can be uploaded
...
...
tests/Auth/AuthTest.php
View file @
6669998
...
...
@@ -3,7 +3,7 @@
use
BookStack\Notifications\ConfirmEmail
;
use
Illuminate\Support\Facades\Notification
;
class
AuthTest
extends
TestCase
class
AuthTest
extends
BrowserKitTest
{
public
function
test_auth_working
()
...
...
@@ -220,6 +220,9 @@ class AuthTest extends TestCase
public
function
test_reset_password_flow
()
{
Notification
::
fake
();
$this
->
visit
(
'/login'
)
->
click
(
'Forgot Password?'
)
->
seePageIs
(
'/password/email'
)
->
type
(
'admin@admin.com'
,
'email'
)
...
...
@@ -230,8 +233,13 @@ class AuthTest extends TestCase
'email'
=>
'admin@admin.com'
]);
$user
=
\BookStack\User
::
where
(
'email'
,
'='
,
'admin@admin.com'
)
->
first
();
Notification
::
assertSentTo
(
$user
,
\BookStack\Notifications\ResetPassword
::
class
);
$n
=
Notification
::
sent
(
$user
,
\BookStack\Notifications\ResetPassword
::
class
);
$reset
=
DB
::
table
(
'password_resets'
)
->
where
(
'email'
,
'='
,
'admin@admin.com'
)
->
first
();
$this
->
visit
(
'/password/reset/'
.
$
reset
->
token
)
$this
->
visit
(
'/password/reset/'
.
$
n
->
first
()
->
token
)
->
see
(
'Reset Password'
)
->
submitForm
(
'Reset Password'
,
[
'email'
=>
'admin@admin.com'
,
...
...
tests/Auth/LdapTest.php
View file @
6669998
<?php
use
BookStack\Services\LdapService
;
use
BookStack\User
;
class
LdapTest
extends
\TestCase
class
LdapTest
extends
BrowserKitTest
{
protected
$mockLdap
;
...
...
tests/Auth/SocialAuthTest.php
View file @
6669998
<?php
class
SocialAuthTest
extends
TestCase
class
SocialAuthTest
extends
BrowserKitTest
{
public
function
test_social_registration
()
...
...
tests/BrowserKitTest.php
0 → 100644
View file @
6669998
<?php
use
Illuminate\Foundation\Testing\DatabaseTransactions
;
use
Symfony\Component\DomCrawler\Crawler
;
abstract
class
BrowserKitTest
extends
\Laravel\BrowserKitTesting\TestCase
{
use
DatabaseTransactions
;
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected
$baseUrl
=
'http://localhost'
;
// Local user instances
private
$admin
;
private
$editor
;
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public
function
createApplication
()
{
$app
=
require
__DIR__
.
'/../bootstrap/app.php'
;
$app
->
make
(
Illuminate\Contracts\Console\Kernel
::
class
)
->
bootstrap
();
return
$app
;
}
/**
* Set the current user context to be an admin.
* @return $this
*/
public
function
asAdmin
()
{
return
$this
->
actingAs
(
$this
->
getAdmin
());
}
/**
* Get the current admin user.
* @return mixed
*/
public
function
getAdmin
()
{
if
(
$this
->
admin
===
null
)
{
$adminRole
=
\BookStack\Role
::
getRole
(
'admin'
);
$this
->
admin
=
$adminRole
->
users
->
first
();
}
return
$this
->
admin
;
}
/**
* Set the current editor context to be an editor.
* @return $this
*/
public
function
asEditor
()
{
if
(
$this
->
editor
===
null
)
{
$this
->
editor
=
$this
->
getEditor
();
}
return
$this
->
actingAs
(
$this
->
editor
);
}
/**
* Get a user that's not a system user such as the guest user.
*/
public
function
getNormalUser
()
{
return
\BookStack\User
::
where
(
'system_name'
,
'='
,
null
)
->
get
()
->
last
();
}
/**
* Quickly sets an array of settings.
* @param $settingsArray
*/
protected
function
setSettings
(
$settingsArray
)
{
$settings
=
app
(
'BookStack\Services\SettingService'
);
foreach
(
$settingsArray
as
$key
=>
$value
)
{
$settings
->
put
(
$key
,
$value
);
}
}
/**
* Create a group of entities that belong to a specific user.
* @param $creatorUser
* @param $updaterUser
* @return array
*/
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
->
chapters
()
->
saveMany
([
$chapter
]);
$chapter
->
pages
()
->
saveMany
([
$page
]);
$restrictionService
=
$this
->
app
[
\BookStack\Services\PermissionService
::
class
];
$restrictionService
->
buildJointPermissionsForEntity
(
$book
);
return
[
'book'
=>
$book
,
'chapter'
=>
$chapter
,
'page'
=>
$page
];
}
/**
* Quick way to create a new user
* @param array $attributes
* @return mixed
*/
protected
function
getEditor
(
$attributes
=
[])
{
$user
=
factory
(
\BookStack\User
::
class
)
->
create
(
$attributes
);
$role
=
\BookStack\Role
::
getRole
(
'editor'
);
$user
->
attachRole
(
$role
);;
return
$user
;
}
/**
* Quick way to create a new user without any permissions
* @param array $attributes
* @return mixed
*/
protected
function
getNewBlankUser
(
$attributes
=
[])
{
$user
=
factory
(
\BookStack\User
::
class
)
->
create
(
$attributes
);
return
$user
;
}
/**
* Assert that a given string is seen inside an element.
*
* @param bool|string|null $element
* @param integer $position
* @param string $text
* @param bool $negate
* @return $this
*/
protected
function
seeInNthElement
(
$element
,
$position
,
$text
,
$negate
=
false
)
{
$method
=
$negate
?
'assertNotRegExp'
:
'assertRegExp'
;
$rawPattern
=
preg_quote
(
$text
,
'/'
);
$escapedPattern
=
preg_quote
(
e
(
$text
),
'/'
);
$content
=
$this
->
crawler
->
filter
(
$element
)
->
eq
(
$position
)
->
html
();
$pattern
=
$rawPattern
==
$escapedPattern
?
$rawPattern
:
"(
{
$rawPattern
}
|
{
$escapedPattern
}
)"
;
$this
->
$method
(
"/
$pattern
/i"
,
$content
);
return
$this
;
}
/**
* Assert that the current page matches a given URI.
*
* @param string $uri
* @return $this
*/
protected
function
seePageUrlIs
(
$uri
)
{
$this
->
assertEquals
(
$uri
,
$this
->
currentUri
,
"Did not land on expected page [
{
$uri
}
].
\n
"
);
return
$this
;
}
/**
* Do a forced visit that does not error out on exception.
* @param string $uri
* @param array $parameters
* @param array $cookies
* @param array $files
* @return $this
*/
protected
function
forceVisit
(
$uri
,
$parameters
=
[],
$cookies
=
[],
$files
=
[])
{
$method
=
'GET'
;
$uri
=
$this
->
prepareUrlForRequest
(
$uri
);
$this
->
call
(
$method
,
$uri
,
$parameters
,
$cookies
,
$files
);
$this
->
clearInputs
()
->
followRedirects
();
$this
->
currentUri
=
$this
->
app
->
make
(
'request'
)
->
fullUrl
();
$this
->
crawler
=
new
Crawler
(
$this
->
response
->
getContent
(),
$uri
);
return
$this
;
}
/**
* Click the text within the selected element.
* @param $parentElement
* @param $linkText
* @return $this
*/
protected
function
clickInElement
(
$parentElement
,
$linkText
)
{
$elem
=
$this
->
crawler
->
filter
(
$parentElement
);
$link
=
$elem
->
selectLink
(
$linkText
);
$this
->
visit
(
$link
->
link
()
->
getUri
());
return
$this
;
}
/**
* Check if the page contains the given element.
* @param string $selector
* @return bool
*/
protected
function
pageHasElement
(
$selector
)
{
$elements
=
$this
->
crawler
->
filter
(
$selector
);
$this
->
assertTrue
(
count
(
$elements
)
>
0
,
"The page does not contain an element matching "
.
$selector
);
return
$this
;
}
/**
* Check if the page contains the given element.
* @param string $selector
* @return bool
*/
protected
function
pageNotHasElement
(
$selector
)
{
$elements
=
$this
->
crawler
->
filter
(
$selector
);
$this
->
assertFalse
(
count
(
$elements
)
>
0
,
"The page contains "
.
count
(
$elements
)
.
" elements matching "
.
$selector
);
return
$this
;
}
}
tests/Entity/EntitySearchTest.php
View file @
6669998
<?php
use
Illuminate\Support\Facades\DB
;
class
EntitySearchTest
extends
TestCase
class
EntitySearchTest
extends
BrowserKitTest
{
public
function
test_page_search
()
...
...
tests/Entity/EntityTest.php
View file @
6669998
<?php
use
Illuminate\Support\Facades\DB
;
class
EntityTest
extends
TestCase
class
EntityTest
extends
BrowserKitTest
{
public
function
test_entity_creation
()
...
...
tests/Entity/MarkdownTest.php
View file @
6669998
<?php
class
MarkdownTest
extends
TestCase
class
MarkdownTest
extends
BrowserKitTest
{
protected
$page
;
...
...
tests/Entity/PageContentTest.php
View file @
6669998
<?php
class
PageContentTest
extends
TestCase
class
PageContentTest
extends
BrowserKitTest
{
public
function
test_page_includes
()
...
...
tests/Entity/PageDraftTest.php
View file @
6669998
<?php
class
PageDraftTest
extends
TestCase
class
PageDraftTest
extends
BrowserKitTest
{
protected
$page
;
protected
$entityRepo
;
...
...
tests/Entity/SortTest.php
View file @
6669998
<?php
class
SortTest
extends
TestCase
class
SortTest
extends
BrowserKitTest
{
protected
$book
;
...
...
tests/Entity/TagTest.php
View file @
6669998
<?php
namespace
Entity
;
<?php
use
BookStack\Tag
;
use
BookStack\Page
;
use
BookStack\Services\PermissionService
;
class
TagTest
extends
\TestCase
class
TagTest
extends
BrowserKitTest
{
protected
$defaultTagCount
=
20
;
...
...
tests/ImageTest.php
View file @
6669998
<?php
class
ImageTest
extends
TestCase
class
ImageTest
extends
BrowserKitTest
{
/**
...
...
tests/Permissions/RestrictionsTest.php
View file @
6669998
<?php
class
RestrictionsTest
extends
TestCase
class
RestrictionsTest
extends
BrowserKitTest
{
protected
$user
;
protected
$viewer
;
...
...
tests/Permissions/RolesTest.php
View file @
6669998
<?php
class
RolesTest
extends
TestCase
class
RolesTest
extends
BrowserKitTest
{
protected
$user
;
...
...
tests/PublicActionTest.php
View file @
6669998
<?php
class
PublicActionTest
extends
TestCase
class
PublicActionTest
extends
BrowserKitTest
{
public
function
test_app_not_public
()
...
...
tests/TestCase.php
View file @
6669998
...
...
@@ -9,15 +9,11 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
use
DatabaseTransactions
;
/**
* The base URL
to use while testing
the application.
* The base URL
of
the application.
*
* @var string
*/
protected
$baseUrl
=
'http://localhost'
;
// Local user instances
private
$admin
;
private
$editor
;
public
$baseUrl
=
'http://localhost'
;
/**
* Creates the application.
...
...
@@ -28,207 +24,8 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
{
$app
=
require
__DIR__
.
'/../bootstrap/app.php'
;
$app
->
make
(
Illuminate\Contracts\Console\
Kernel
::
class
)
->
bootstrap
();
$app
->
make
(
Kernel
::
class
)
->
bootstrap
();
return
$app
;
}
/**
* Set the current user context to be an admin.
* @return $this
*/
public
function
asAdmin
()
{
return
$this
->
actingAs
(
$this
->
getAdmin
());
}
/**
* Get the current admin user.
* @return mixed
*/
public
function
getAdmin
()
{
if
(
$this
->
admin
===
null
)
{
$adminRole
=
\BookStack\Role
::
getRole
(
'admin'
);
$this
->
admin
=
$adminRole
->
users
->
first
();
}
return
$this
->
admin
;
}
/**
* Set the current editor context to be an editor.
* @return $this
*/
public
function
asEditor
()
{
if
(
$this
->
editor
===
null
)
{
$this
->
editor
=
$this
->
getEditor
();
}
return
$this
->
actingAs
(
$this
->
editor
);
}
/**
* Get a user that's not a system user such as the guest user.
*/
public
function
getNormalUser
()
{
return
\BookStack\User
::
where
(
'system_name'
,
'='
,
null
)
->
get
()
->
last
();
}
/**
* Quickly sets an array of settings.
* @param $settingsArray
*/
protected
function
setSettings
(
$settingsArray
)
{
$settings
=
app
(
'BookStack\Services\SettingService'
);
foreach
(
$settingsArray
as
$key
=>
$value
)
{
$settings
->
put
(
$key
,
$value
);
}
}
/**
* Create a group of entities that belong to a specific user.
* @param $creatorUser
* @param $updaterUser
* @return array
*/
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
->
chapters
()
->
saveMany
([
$chapter
]);
$chapter
->
pages
()
->
saveMany
([
$page
]);
$restrictionService
=
$this
->
app
[
\BookStack\Services\PermissionService
::
class
];
$restrictionService
->
buildJointPermissionsForEntity
(
$book
);
return
[
'book'
=>
$book
,
'chapter'
=>
$chapter
,
'page'
=>
$page
];
}
/**
* Quick way to create a new user
* @param array $attributes
* @return mixed
*/
protected
function
getEditor
(
$attributes
=
[])
{
$user
=
factory
(
\BookStack\User
::
class
)
->
create
(
$attributes
);
$role
=
\BookStack\Role
::
getRole
(
'editor'
);
$user
->
attachRole
(
$role
);;
return
$user
;
}
/**
* Quick way to create a new user without any permissions
* @param array $attributes
* @return mixed
*/
protected
function
getNewBlankUser
(
$attributes
=
[])
{
$user
=
factory
(
\BookStack\User
::
class
)
->
create
(
$attributes
);
return
$user
;
}
/**
* Assert that a given string is seen inside an element.
*
* @param bool|string|null $element
* @param integer $position
* @param string $text
* @param bool $negate
* @return $this
*/
protected
function
seeInNthElement
(
$element
,
$position
,
$text
,
$negate
=
false
)
{
$method
=
$negate
?
'assertNotRegExp'
:
'assertRegExp'
;
$rawPattern
=
preg_quote
(
$text
,
'/'
);
$escapedPattern
=
preg_quote
(
e
(
$text
),
'/'
);
$content
=
$this
->
crawler
->
filter
(
$element
)
->
eq
(
$position
)
->
html
();
$pattern
=
$rawPattern
==
$escapedPattern
?
$rawPattern
:
"(
{
$rawPattern
}
|
{
$escapedPattern
}
)"
;
$this
->
$method
(
"/
$pattern
/i"
,
$content
);
return
$this
;
}
/**
* Assert that the current page matches a given URI.
*
* @param string $uri
* @return $this
*/
protected
function
seePageUrlIs
(
$uri
)
{
$this
->
assertEquals
(
$uri
,
$this
->
currentUri
,
"Did not land on expected page [
{
$uri
}
].
\n
"
);
return
$this
;
}
/**
* Do a forced visit that does not error out on exception.
* @param string $uri
* @param array $parameters
* @param array $cookies
* @param array $files
* @return $this
*/
protected
function
forceVisit
(
$uri
,
$parameters
=
[],
$cookies
=
[],
$files
=
[])
{
$method
=
'GET'
;
$uri
=
$this
->
prepareUrlForRequest
(
$uri
);
$this
->
call
(
$method
,
$uri
,
$parameters
,
$cookies
,
$files
);
$this
->
clearInputs
()
->
followRedirects
();
$this
->
currentUri
=
$this
->
app
->
make
(
'request'
)
->
fullUrl
();
$this
->
crawler
=
new
Crawler
(
$this
->
response
->
getContent
(),
$uri
);
return
$this
;
}
/**
* Click the text within the selected element.
* @param $parentElement
* @param $linkText
* @return $this
*/
protected
function
clickInElement
(
$parentElement
,
$linkText
)
{
$elem
=
$this
->
crawler
->
filter
(
$parentElement
);
$link
=
$elem
->
selectLink
(
$linkText
);
$this
->
visit
(
$link
->
link
()
->
getUri
());
return
$this
;
}
/**
* Check if the page contains the given element.
* @param string $selector
* @return bool
*/
protected
function
pageHasElement
(
$selector
)
{
$elements
=
$this
->
crawler
->
filter
(
$selector
);
$this
->
assertTrue
(
count
(
$elements
)
>
0
,
"The page does not contain an element matching "
.
$selector
);
return
$this
;
}
/**
* Check if the page contains the given element.
* @param string $selector
* @return bool
*/
protected
function
pageNotHasElement
(
$selector
)
{
$elements
=
$this
->
crawler
->
filter
(
$selector
);
$this
->
assertFalse
(
count
(
$elements
)
>
0
,
"The page contains "
.
count
(
$elements
)
.
" elements matching "
.
$selector
);
return
$this
;
}
}
...
...
tests/UserProfileTest.php
View file @
6669998
<?php
class
UserProfileTest
extends
TestCase
class
UserProfileTest
extends
BrowserKitTest
{
protected
$user
;
...
...
version
View file @
6669998
v0.1
3
-dev
v0.1
5
-dev
...
...
Please
register
or
sign in
to post a comment