Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Move
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 process
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
3
 getRequiredFields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2017-2022 (original work) Open Assessment Technologies SA ;
19 */
20
21namespace oat\taoQtiTest\models\runner\synchronisation\action;
22
23use common_Exception;
24use common_exception_Error;
25use common_exception_InconsistentData;
26use common_Logger;
27use Exception;
28use oat\taoQtiTest\model\Service\MoveCommand;
29use oat\taoQtiTest\model\Service\MoveService;
30use oat\taoQtiTest\models\runner\QtiRunnerServiceContext;
31use oat\taoQtiTest\models\runner\synchronisation\TestRunnerAction;
32
33/**
34 * Move forward or back item into the test context.
35 *
36 * @package oat\taoQtiTest\models\runner\synchronisation\action
37 */
38class Move extends TestRunnerAction
39{
40    /**
41     * Process the move action.
42     *
43     * Validate required fields.
44     * Stop/Start timer and save item state.
45     * Save item response and wrap the move to runner service.
46     * Start next timer.
47     *
48     * @throws common_Exception
49     * @throws common_exception_Error
50     * @throws common_exception_InconsistentData
51     */
52    public function process(): array
53    {
54        $this->validate();
55
56        try {
57            if ($this->getRequestParameter('offline') === true) {
58                $this->setOffline();
59            }
60
61            $serviceContext = $this->getServiceContext();
62
63            $moveCommand = new MoveCommand(
64                $this->getServiceContext(),
65                $this->hasRequestParameter('start')
66            );
67
68            $this->setNavigationContextToCommand($moveCommand);
69            $this->setItemContextToCommand($moveCommand);
70            $this->setToolsStateContextToCommand($moveCommand);
71
72            /** @var MoveService $moveService */
73            $moveService = $this->getPsrContainer()->get(MoveService::class);
74
75            $response = $moveService($moveCommand);
76
77            common_Logger::d('Test session state : ' . $serviceContext->getTestSession()->getState());
78
79            return $response->toArray();
80        } catch (Exception $e) {
81            common_Logger::e(
82                $e->getMessage(),
83                ['deliveryExecutionId' => $this->getServiceContext()->getTestExecutionUri()]
84            );
85
86            return $this->getErrorResponse($e);
87        }
88    }
89
90    /**
91     * Direction and scope are required for move action.
92     *
93     * @return array
94     */
95    protected function getRequiredFields(): array
96    {
97        return array_merge(parent::getRequiredFields(), ['direction', 'scope']);
98    }
99}