Skip to content

Commit

Permalink
Merge branch 'master' into release-1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro committed Mar 6, 2018
2 parents 9cae8aa + ac21f7b commit 09bcebd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions controller/visual_demo_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public function handle($action)

if ($action === 'disable')
{
// If cookie already exists, lets destroy it and redirect user to previous page viewed.
// Destroy our cookie and redirect user to previous page viewed.
$this->user->set_cookie('phpbb_ads_visual_demo', '', 1);
$redirect = $this->request->variable('redirect', $this->user->data['session_page']);
}
else
{
// Since cookie does not exist yet, lets create one and send user to the index page.
// Create our cookie and send user to the index page.
$this->user->set_cookie('phpbb_ads_visual_demo', time(), 0);
$redirect = "{$this->root_path}index.{$this->php_ext}";
}
Expand Down
33 changes: 24 additions & 9 deletions tests/controller/visual_demo_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,27 @@ protected function get_controller()
public function controller_data()
{
return array(
array(
'enable',
false,
200,
0,
),
array(
'enable',
true,
true, // use ajax to bypass redirects in testing
200,
0,
),
array(
'disable',
true,
true, // use ajax to bypass redirects in testing
200,
1,
),
array(
'disable',
false,
200,
1,
),
Expand All @@ -100,12 +110,13 @@ public function controller_data()
*
* @dataProvider controller_data
*/
public function test_controller($action, $is_admin, $is_ajax, $status_code, $cookie_time)
public function test_controller($action, $is_ajax, $status_code, $cookie_time)
{
// User is an admin
$this->auth->expects($this->any())
->method('acl_get')
->with($this->stringContains('a_'), $this->anything())
->will($this->returnValue($is_admin));
->will($this->returnValue(true));

$this->request->expects($this->any())
->method('is_ajax')
Expand All @@ -115,8 +126,13 @@ public function test_controller($action, $is_admin, $is_ajax, $status_code, $coo
->method('set_cookie')
->with('phpbb_ads_visual_demo', $this->anything(), $cookie_time);

$controller = $this->get_controller();
// If non-ajax redirect is encountered, in testing it will trigger error
if (!$is_ajax)
{
$this->setExpectedTriggerError(E_USER_ERROR);
}

$controller = $this->get_controller();
$response = $controller->handle($action);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertEquals($status_code, $response->getStatusCode());
Expand All @@ -132,13 +148,11 @@ public function controller_fails_data()
return array(
array(
'enable',
false, // is admin
403,
'NO_AUTH_OPERATION',
),
array(
'disable',
false, // is admin
403,
'NO_AUTH_OPERATION',
),
Expand All @@ -150,12 +164,13 @@ public function controller_fails_data()
*
* @dataProvider controller_fails_data
*/
public function test_controller_fails($action, $is_admin, $status_code, $message)
public function test_controller_fails($action, $status_code, $message)
{
// User is not an admin
$this->auth->expects($this->any())
->method('acl_get')
->with($this->stringContains('a_'), $this->anything())
->will($this->returnValue($is_admin));
->will($this->returnValue(false));

$controller = $this->get_controller();

Expand Down

0 comments on commit 09bcebd

Please sign in to comment.