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
2015-09-22 21:07:50 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
fd3929e8099d45160f242bea18556ed78ef0eaf8
fd3929e8
1 parent
1b736ac0
Started Social Auth Testing
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
12 deletions
tests/AuthTest.php
tests/SocialAuthTest.php
tests/TestCase.php
tests/AuthTest.php
View file @
fd3929e
...
...
@@ -113,18 +113,6 @@ class AuthTest extends TestCase
}
/**
* Quickly sets an array of settings.
* @param $settingsArray
*/
private
function
setSettings
(
$settingsArray
)
{
$settings
=
app
(
'BookStack\Services\SettingService'
);
foreach
(
$settingsArray
as
$key
=>
$value
)
{
$settings
->
put
(
$key
,
$value
);
}
}
/**
* Perform a login
* @param string $email
* @param string $password
...
...
tests/SocialAuthTest.php
0 → 100644
View file @
fd3929e
<?php
class
SocialAuthTest
extends
TestCase
{
public
function
testSocialRegistration
()
{
// http://docs.mockery.io/en/latest/reference/startup_methods.html
$user
=
factory
(
\BookStack\User
::
class
)
->
make
();
$this
->
setSettings
([
'registration-enabled'
=>
'true'
]);
$this
->
setEnvironment
([
'GOOGLE_APP_ID'
=>
'abc123'
,
'GOOGLE_APP_SECRET'
=>
'123abc'
,
'APP_URL'
=>
'http://localhost'
]);
$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'
);
$mockSocialite
->
shouldReceive
(
'driver'
)
->
twice
()
->
with
(
'google'
)
->
andReturn
(
$mockSocialDriver
);
$mockSocialDriver
->
shouldReceive
(
'redirect'
)
->
once
()
->
andReturn
(
redirect
(
'/'
));
$mockSocialDriver
->
shouldReceive
(
'user'
)
->
once
()
->
andReturn
(
$mockSocialUser
);
$mockSocialUser
->
shouldReceive
(
'getId'
)
->
twice
()
->
andReturn
(
1
);
$mockSocialUser
->
shouldReceive
(
'getEmail'
)
->
twice
()
->
andReturn
(
$user
->
email
);
$mockSocialUser
->
shouldReceive
(
'getName'
)
->
once
()
->
andReturn
(
$user
->
name
);
$mockSocialUser
->
shouldReceive
(
'getAvatar'
)
->
once
()
->
andReturn
(
'avatar_placeholder'
);
$this
->
visit
(
'/register/service/google'
);
$this
->
visit
(
'/login/service/google/callback'
);
$this
->
seeInDatabase
(
'users'
,
[
'name'
=>
$user
->
name
,
'email'
=>
$user
->
email
]);
$user
=
$user
->
whereEmail
(
$user
->
email
)
->
first
();
$this
->
seeInDatabase
(
'social_accounts'
,
[
'user_id'
=>
$user
->
id
]);
}
protected
function
setEnvironment
(
$array
)
{
foreach
(
$array
as
$key
=>
$value
)
{
putenv
(
"
$key
=
$value
"
);
}
}
}
tests/TestCase.php
View file @
fd3929e
...
...
@@ -36,4 +36,16 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
}
return
$this
->
actingAs
(
$this
->
admin
);
}
/**
* 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
);
}
}
}
...
...
Please
register
or
sign in
to post a comment