Skip to content

Commit 3fae156

Browse files
committed
Revert AJAX hacks
1 parent a3507fa commit 3fae156

3 files changed

Lines changed: 20 additions & 35 deletions

File tree

tests/controller/admin_controller_test.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,15 @@ public function test_ad_enable($ad_id, $enable, $is_ajax, $err_msg)
930930
->method('is_ajax')
931931
->willReturn($is_ajax);
932932

933+
if ($is_ajax)
934+
{
935+
$this->expectOutputString('{"text":"' . ($enable ? 'Enabled' : 'Disabled') . '","title":"AD_ENABLE_TITLE"}');
936+
}
937+
else
938+
{
939+
$this->setExpectedTriggerError($ad_id ? E_USER_NOTICE : E_USER_WARNING, $err_msg);
940+
}
941+
933942
$variable_expectations = [['action', ''], ['id', 0]];
934943
$return_values = [$enable ? 'enable' : 'disable', $ad_id];
935944
$this->request
@@ -942,23 +951,6 @@ public function test_ad_enable($ad_id, $enable, $is_ajax, $err_msg)
942951
return array_shift($return_values);
943952
});
944953

945-
if ($is_ajax)
946-
{
947-
// Handle trigger_error() output called from json_response
948-
if (version_compare(\PHPUnit\Runner\Version::id(), '10.0.0', '>='))
949-
{
950-
$this->markTestSkipped('setExpectedTriggerError not available in PHPUnit 10+');
951-
}
952-
else
953-
{
954-
$this->setExpectedTriggerError(E_WARNING);
955-
}
956-
}
957-
else
958-
{
959-
$this->setExpectedTriggerError($ad_id ? E_USER_NOTICE : E_USER_WARNING, $err_msg);
960-
}
961-
962954
$controller->mode_manage();
963955
}
964956

tests/controller/admin_input_test.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,13 @@ protected function setUp(): void
9898
*/
9999
public function get_input_controller(): admin_input
100100
{
101-
return new class($this->user, $this->user_loader, $this->language, $this->request, $this->banner) extends \phpbb\ads\controller\admin_input {
102-
protected function send_ajax_response($success, $text): void
103-
{
104-
if ($this->request->is_ajax())
105-
{
106-
echo json_encode([
107-
'success' => $success
108-
], JSON_THROW_ON_ERROR);
109-
}
110-
}
111-
};
101+
return new \phpbb\ads\controller\admin_input(
102+
$this->user,
103+
$this->user_loader,
104+
$this->language,
105+
$this->request,
106+
$this->banner
107+
);
112108
}
113109

114110
/**
@@ -245,14 +241,14 @@ public function test_banner_upload($can_create_directory, $can_move_file, $is_aj
245241
->method('remove');
246242
}
247243

248-
$this->request->expects(self::atLeast(1))
244+
$this->request->expects(self::once())
249245
->method('is_ajax')
250246
->willReturn($is_ajax);
251247

252248
if ($is_ajax)
253249
{
254-
// Handle trigger_error() output called from json_response
255-
$this->expectOutputString('{"success":' . (count($file_error) ? 'false' : 'true') . '}');
250+
$text = !empty($file_error) ? '"CANNOT_CREATE_DIRECTORY"' : '"' . addcslashes(trim(substr($ad_code_expected, strpos($ad_code_expected, '<img'))), "/\"") . '"';
251+
$this->expectOutputString('{"success":' . (count($file_error) ? 'false' : 'true') . ',"title":"Information","text":' . $text . '}');
256252
}
257253

258254
$result = $input_controller->banner_upload($ad_code);

tests/controller/visual_demo_test.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,13 @@ public function test_controller($action, $is_ajax, $status_code, $cookie_time)
139139
->method('set_cookie')
140140
->with('phpbb_ads_visual_demo', $this->anything(), $cookie_time);
141141

142-
$controller = $this->get_controller();
143-
144142
// If a non-ajax redirect is encountered, in testing it will trigger_error
145143
if (!$is_ajax)
146144
{
147145
$this->setExpectedTriggerError(E_USER_DEPRECATED);
148-
$controller->handle($action);
149-
return; // Skip response assertions since redirect calls exit
150146
}
151147

148+
$controller = $this->get_controller();
152149
$response = $controller->handle($action);
153150
self::assertInstanceOf(JsonResponse::class, $response);
154151
self::assertEquals($status_code, $response->getStatusCode());

0 commit comments

Comments
 (0)