View source
<?php
namespace Drupal\Tests\jsonrpc_core\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\jsonrpc\Functional\JsonRpcTestBase;
class MaintenanceModeEnabledTest extends JsonRpcTestBase {
protected static $modules = [
'jsonrpc',
'jsonrpc_core',
'basic_auth',
'serialization',
];
public function testEnablingMaintenanceMode() {
$enabled_request = [
'jsonrpc' => '2.0',
'method' => 'maintenance_mode.isEnabled',
'params' => [
'enabled' => TRUE,
],
'id' => 'maintenance_mode_enabled',
];
$response = $this
->postRpc($enabled_request);
$this
->assertSame(401, $response
->getStatusCode());
$account = $this
->createUser([
'administer site configuration',
], NULL, TRUE);
$response = $this
->postRpc($enabled_request, $account);
$this
->assertSame(200, $response
->getStatusCode());
$parsed_body = Json::decode($response
->getBody());
$expected = [
'jsonrpc' => '2.0',
'id' => 'maintenance_mode_enabled',
'result' => 'enabled',
];
$this
->assertEquals($expected, $parsed_body);
$this
->drupalGet('/jsonrpc');
$this
->assertEquals('Site under maintenance', $this
->cssSelect('main h1')[0]
->getText());
$disabled_request = [
'jsonrpc' => '2.0',
'method' => 'maintenance_mode.isEnabled',
'params' => [
'enabled' => FALSE,
],
'id' => 'maintenance_mode_disabled',
];
$response = $this
->postRpc($disabled_request, $account);
$this
->assertSame(200, $response
->getStatusCode());
$parsed_body = Json::decode($response
->getBody());
$expected = [
'jsonrpc' => '2.0',
'id' => 'maintenance_mode_disabled',
'result' => 'disabled',
];
$this
->assertEquals($expected, $parsed_body);
$this
->drupalGet('/jsonrpc');
$this
->assertNotEquals('Site under maintenance', $this
->cssSelect('main h1')[0]
->getText());
}
}