25 use Slim\Psr7\Factory\StreamFactory;
27 use Slim\Psr7\Headers;
28 use Slim\Psr7\Request;
30 require_once dirname(__DIR__, 4) .
'/lib/php/Plugin/FO_Plugin.php';
44 const YAML_LOC = __DIR__ .
'/../../../ui/api/documentation/openapi.yaml';
91 protected function setUp() : void
94 $container = M::mock(
'ContainerBuilder');
95 $this->dbHelper = M::mock(DbHelper::class);
96 $this->restHelper = M::mock(RestHelper::class);
97 $this->userDao = M::mock(UserDao::class);
98 $this->auth = M::mock(Auth::class);
100 $this->maintagentPlugin = M::mock(
'maintagent');
102 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
103 $this->restHelper->shouldReceive(
'getUserDao')
104 ->andReturn($this->userDao);
106 $this->restHelper->shouldReceive(
'getPlugin')
107 ->withArgs(array(
'maintagent'))
108 ->andReturn($this->maintagentPlugin);
110 $this->auth->shouldReceive(
'isAdmin')->andReturn(
true);
112 $container->shouldReceive(
'get')->withArgs(array(
113 'helper.restHelper'))->andReturn($this->restHelper);
115 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
116 $this->
dbManager = M::mock(DbManager::class);
117 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
118 $this->streamFactory =
new StreamFactory();
130 $response->getBody()->seek(0);
131 return json_decode($response->getBody()->getContents(),
true);
141 $_SESSION[
'UserLevel'] = 10;
144 "options" => [
"A",
"F",
"g",
"l",
"o"],
145 "logsDate"=>
"2021-08-19",
146 "goldDate"=>
"2022-07-16"
150 "A"=>
"Run all maintenance operations.",
151 "F"=>
"Validate folder contents.",
152 "g"=>
"Remove orphaned gold files.",
153 "o"=>
"Remove older gold files from repository.",
154 "l"=>
"Remove older log files from repository."
157 $alteredOptions = array();
158 foreach ($rq[
'options'] as $key) {
159 $alteredOptions[$key] = $key;
162 $body[
'options'] = $alteredOptions;
164 $this->maintagentPlugin->shouldReceive(
'getOptions')->andReturn($OPTIONS);
166 $mess = _(
"The maintenance job has been queued");
168 $this->maintagentPlugin->shouldReceive(
'handle')->withArgs([$body])->andReturn($mess);
170 $info =
new Info(201, $mess, InfoType::INFO);
173 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
175 $reqBody = $this->streamFactory->createStream(json_encode(
179 $requestHeaders =
new Headers();
180 $requestHeaders->setHeader(
'Content-Type',
'application/json');
181 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
182 $requestHeaders, [], [], $reqBody);
185 $actualResponse = $this->maintenanceController->createMaintenance($request,
new ResponseHelper(),
null);
187 $this->assertEquals($expectedResponse->getStatusCode(),
188 $actualResponse->getStatusCode());
Contains the constants and helpers for authentication of user.
Provides helper methods to access database for REST api.
Override Slim response for withJson function.
Provides various DAO helper functions for REST api.
Different type of infos provided by REST.
Info model to contain general error and return values.
Tests for MaintenanceController.
setUp()
Setup test objects.
getResponseJson($response)
fo_dbManager * dbManager
fo_dbManager object