Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| taoQtiTest_helpers_TestCompilerUtils | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
9 | |
100.00% |
1 / 1 |
| testMeta | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| testContainsBranchRules | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
| testContainsPreConditions | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
| 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) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use qtism\data\AssessmentTest; |
| 23 | use qtism\data\NavigationMode; |
| 24 | |
| 25 | /** |
| 26 | * Utility methods for the QtiTest Test compilation process. |
| 27 | * |
| 28 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
| 29 | * |
| 30 | */ |
| 31 | class taoQtiTest_helpers_TestCompilerUtils |
| 32 | { |
| 33 | public const COMPILATION_VERSION = 'compilationVersion'; |
| 34 | |
| 35 | /** |
| 36 | * Get an associative array representing some meta-data about the |
| 37 | * given $test. |
| 38 | * |
| 39 | * The following keys can be accessed: |
| 40 | * |
| 41 | * 'branchRules': whether or not the test definition contains branchRule components in force. |
| 42 | * 'preConditions': whether or not the test definition contains preCondition components in force. |
| 43 | * |
| 44 | * @param AssessmentTest $test |
| 45 | * @return array An associative array. |
| 46 | */ |
| 47 | public static function testMeta(AssessmentTest $test) |
| 48 | { |
| 49 | $meta = []; |
| 50 | |
| 51 | $meta['branchRules'] = self::testContainsBranchRules($test); |
| 52 | $meta['preConditions'] = self::testContainsPreConditions($test); |
| 53 | $meta[self::COMPILATION_VERSION] = 1; |
| 54 | |
| 55 | return $meta; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Whether or not a given $test contains branchRules subject to be |
| 60 | * in force during its execution. |
| 61 | * |
| 62 | * @param AssessmentTest $test |
| 63 | * @return boolean |
| 64 | */ |
| 65 | private static function testContainsBranchRules(AssessmentTest $test) |
| 66 | { |
| 67 | $testParts = $test->getComponentsByClassName('testPart'); |
| 68 | $containsBranchRules = false; |
| 69 | |
| 70 | foreach ($testParts as $testPart) { |
| 71 | // Remember that branchRules are ignored when the navigation mode |
| 72 | // is non linear. |
| 73 | if ($testPart->getNavigationMode() !== NavigationMode::NONLINEAR) { |
| 74 | $branchings = $testPart->getComponentsByClassName('branchRule'); |
| 75 | |
| 76 | if (count($branchings) > 0) { |
| 77 | $containsBranchRules = true; |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return $containsBranchRules; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Whether or not a given $test contains preConditions subject to be in force |
| 88 | * during its execution. |
| 89 | * |
| 90 | * @param AssessmentTest $test |
| 91 | * @return boolean |
| 92 | */ |
| 93 | private static function testContainsPreConditions(AssessmentTest $test) |
| 94 | { |
| 95 | $testParts = $test->getComponentsByClassName('testPart'); |
| 96 | $containsPreConditions = false; |
| 97 | |
| 98 | foreach ($testParts as $testPart) { |
| 99 | // PreConditions are only taken into account |
| 100 | // in linear navigation mode. |
| 101 | if ($testPart->getNavigationMode() !== NavigationMode::NONLINEAR) { |
| 102 | $preConditions = $testPart->getComponentsByClassName('preCondition'); |
| 103 | |
| 104 | if (count($preConditions) > 0) { |
| 105 | $containsPreConditions = true; |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return $containsPreConditions; |
| 112 | } |
| 113 | } |