Skip to content

Commit 09bcebd

Browse files
committed
Merge branch 'master' into release-1.0.5
2 parents 9cae8aa + ac21f7b commit 09bcebd

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

controller/visual_demo_controller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public function handle($action)
7373

7474
if ($action === 'disable')
7575
{
76-
// If cookie already exists, lets destroy it and redirect user to previous page viewed.
76+
// Destroy our cookie and redirect user to previous page viewed.
7777
$this->user->set_cookie('phpbb_ads_visual_demo', '', 1);
7878
$redirect = $this->request->variable('redirect', $this->user->data['session_page']);
7979
}
8080
else
8181
{
82-
// Since cookie does not exist yet, lets create one and send user to the index page.
82+
// Create our cookie and send user to the index page.
8383
$this->user->set_cookie('phpbb_ads_visual_demo', time(), 0);
8484
$redirect = "{$this->root_path}index.{$this->php_ext}";
8585
}

tests/controller/visual_demo_test.php

+24-9
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,27 @@ protected function get_controller()
7878
public function controller_data()
7979
{
8080
return array(
81+
array(
82+
'enable',
83+
false,
84+
200,
85+
0,
86+
),
8187
array(
8288
'enable',
8389
true,
84-
true, // use ajax to bypass redirects in testing
8590
200,
8691
0,
8792
),
8893
array(
8994
'disable',
9095
true,
91-
true, // use ajax to bypass redirects in testing
96+
200,
97+
1,
98+
),
99+
array(
100+
'disable',
101+
false,
92102
200,
93103
1,
94104
),
@@ -100,12 +110,13 @@ public function controller_data()
100110
*
101111
* @dataProvider controller_data
102112
*/
103-
public function test_controller($action, $is_admin, $is_ajax, $status_code, $cookie_time)
113+
public function test_controller($action, $is_ajax, $status_code, $cookie_time)
104114
{
115+
// User is an admin
105116
$this->auth->expects($this->any())
106117
->method('acl_get')
107118
->with($this->stringContains('a_'), $this->anything())
108-
->will($this->returnValue($is_admin));
119+
->will($this->returnValue(true));
109120

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

118-
$controller = $this->get_controller();
129+
// If non-ajax redirect is encountered, in testing it will trigger error
130+
if (!$is_ajax)
131+
{
132+
$this->setExpectedTriggerError(E_USER_ERROR);
133+
}
119134

135+
$controller = $this->get_controller();
120136
$response = $controller->handle($action);
121137
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\JsonResponse', $response);
122138
$this->assertEquals($status_code, $response->getStatusCode());
@@ -132,13 +148,11 @@ public function controller_fails_data()
132148
return array(
133149
array(
134150
'enable',
135-
false, // is admin
136151
403,
137152
'NO_AUTH_OPERATION',
138153
),
139154
array(
140155
'disable',
141-
false, // is admin
142156
403,
143157
'NO_AUTH_OPERATION',
144158
),
@@ -150,12 +164,13 @@ public function controller_fails_data()
150164
*
151165
* @dataProvider controller_fails_data
152166
*/
153-
public function test_controller_fails($action, $is_admin, $status_code, $message)
167+
public function test_controller_fails($action, $status_code, $message)
154168
{
169+
// User is not an admin
155170
$this->auth->expects($this->any())
156171
->method('acl_get')
157172
->with($this->stringContains('a_'), $this->anything())
158-
->will($this->returnValue($is_admin));
173+
->will($this->returnValue(false));
159174

160175
$controller = $this->get_controller();
161176

0 commit comments

Comments
 (0)