Skip to content

Commit c494691

Browse files
committed
Update json response testing
1 parent b702426 commit c494691

3 files changed

Lines changed: 12 additions & 20 deletions

File tree

controller/admin_controller.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -377,30 +377,20 @@ protected function get_submitted_action()
377377
protected function ad_enable($enable)
378378
{
379379
$ad_id = $this->request->variable('id', 0);
380+
$success = $this->manager->update_ad($ad_id, ['ad_enabled' => (int) $enable]);
380381

381-
$success = $this->manager->update_ad($ad_id, array(
382-
'ad_enabled' => (int) $enable,
383-
));
384-
385-
if ($success)
382+
if ($success && $this->request->is_ajax())
386383
{
387-
if ($this->request->is_ajax())
388-
{
389-
$json_response = new \phpbb\json_response;
390-
$json_response->send(array(
391-
'text' => $this->language->lang($enable ? 'ENABLED' : 'DISABLED'),
392-
'title' => $this->language->lang('AD_ENABLE_TITLE', (int) $enable),
393-
));
394-
}
395-
else
396-
{
397-
$this->success($enable ? 'ACP_AD_ENABLE_SUCCESS' : 'ACP_AD_DISABLE_SUCCESS');
398-
}
384+
$json_response = new \phpbb\json_response;
385+
$json_response->send([
386+
'text' => $this->language->lang($enable ? 'ENABLED' : 'DISABLED'),
387+
'title' => $this->language->lang('AD_ENABLE_TITLE', (int) $enable),
388+
]);
399389
}
400-
else
401-
{
390+
391+
$success ?
392+
$this->success($enable ? 'ACP_AD_ENABLE_SUCCESS' : 'ACP_AD_DISABLE_SUCCESS') :
402393
$this->error($enable ? 'ACP_AD_ENABLE_ERRORED' : 'ACP_AD_DISABLE_ERRORED');
403-
}
404394
}
405395

406396
/**

tests/controller/admin_controller_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ public function test_ad_enable($ad_id, $enable, $is_ajax, $err_msg)
936936
if ($is_ajax)
937937
{
938938
$this->expectOutputString('{"text":"' . ($enable ? 'Enabled' : 'Disabled') . '","title":"AD_ENABLE_TITLE"}');
939+
$this->expectException(\RuntimeException::class);
939940
}
940941
else
941942
{

tests/controller/admin_input_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public function test_banner_upload($can_create_directory, $can_move_file, $is_aj
249249
{
250250
$text = !empty($file_error) ? '"CANNOT_CREATE_DIRECTORY"' : '"' . addcslashes(trim(substr($ad_code_expected, strpos($ad_code_expected, '<img'))), "/\"") . '"';
251251
$this->expectOutputString('{"success":' . (count($file_error) ? 'false' : 'true') . ',"title":"Information","text":' . $text . '}');
252+
$this->expectException(\RuntimeException::class);
252253
}
253254

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

0 commit comments

Comments
 (0)