Skip to content

Commit

Permalink
fix: parse record-typed candidate response values when reading the re…
Browse files Browse the repository at this point in the history
…mote results.xml
  • Loading branch information
wazelin committed Nov 8, 2024
1 parent b462f7c commit b5b0200
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 13 deletions.
29 changes: 20 additions & 9 deletions models/Mapper/ResultMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA;
*
* Copyright (c) 2019-2024 (original work) Open Assessment Technologies SA;
*/

namespace oat\taoResultServer\models\Mapper;
Expand Down Expand Up @@ -325,14 +324,26 @@ protected function createResponseVariable(ResultResponseVariable $itemVariable)
*/
protected function serializeValueCollection(ValueCollection $valueCollection)
{
$values = array_map(
function (Value $value) {
return $value->getValue();
},
iterator_to_array($valueCollection)
);
$isRecord = false;
$values = [];
/** @var Value $value */
foreach ($valueCollection as $value) {
$fieldIdentifier = $value->getFieldIdentifier();
$baseType = $value->getBaseType();
$isRecord = $fieldIdentifier && $baseType !== -1;
$values[] = $isRecord
? [
'name' => $fieldIdentifier,
'base' => [
BaseType::getNameByConstant($baseType) => $value->getValue(),
]
]
: $value->getValue();
}

return implode(';', $values);
return $isRecord
? json_encode(['record' => $values])
: implode(';', $values);
}

/**
Expand Down
53 changes: 50 additions & 3 deletions test/Unit/models/Mapper/ResultMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA;
*
* Copyright (c) 2019-2024 (original work) Open Assessment Technologies SA;
*/

namespace oat\taoResultServer\test\Unit\models\Mapper;
Expand Down Expand Up @@ -124,7 +123,7 @@ public function testGetTestVariablesWithTemplateVariables()
public function testGetItemVariables()
{
$variablesByItemResult = $this->load()->getItemVariables();
$this->assertCount(3, $variablesByItemResult);
$this->assertCount(4, $variablesByItemResult);

$this->assertArrayHasKey('fixture-identifier-itemResult1', $variablesByItemResult);
$this->assertArrayHasKey('fixture-identifier-itemResult2', $variablesByItemResult);
Expand Down Expand Up @@ -186,6 +185,54 @@ public function testGetItemVariables()
$this->assertEquals('fixture-value20', $variable4->getCorrectResponse());
$this->assertEquals('single', $variable4->getCardinality());
$this->assertEquals('identifier', $variable4->getBaseType());

/** @var taoResultServer_models_classes_ResponseVariable $variable5 */
$variable5 = $variablesByItemResult['fixture-identifier-itemResult4'][0];
$this->assertInstanceOf(\taoResultServer_models_classes_ResponseVariable::class, $variable5);
$this->assertEquals('fixture-identifier6', $variable5->getIdentifier());
$this->assertEquals(
json_encode(
[
'record' => [
[
'name' => 'correct',
'base' => [
'integer' => '1'
]
],
[
'name' => 'candidateResponse',
'base' => [
'string' => ''
]
],
[
'name' => 'score',
'base' => [
'integer' => '1'
]
],
[
'name' => 'maxscore',
'base' => [
'integer' => '1'
]
],
[
'name' => 'applet',
'base' => [
'string' => 'payload'
]
]
]
]
),
$variable5->getCandidateResponse()
);
$this->assertEquals('record', $variable5->getCardinality());
$this->assertNull($variable5->getBaseType());
$epochDateTime = (new DateTime())->setTimestamp(explode(' ', $variable5->getEpoch())[1]);
$this->assertSame('2018-06-27T09:41:45', $epochDateTime->format('Y-m-d\TH:i:s'));
}

public function testGetItemVariablesWithTemplateVariables()
Expand Down
31 changes: 30 additions & 1 deletion test/resources/result/simple-assessment-result.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ This program is free software; you can redistribute it and/or
~ modify it under the terms of the GNU General Public License
~ as published by the Free Software Foundation; under version 2
~ of the License (non-upgradable).
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
~
~ Copyright (c) 2024 (original work) Open Assessment Technologies SA;
-->

<assessmentResult xmlns="http://www.imsglobal.org/xsd/imsqti_result_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_result_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_result_v2p1.xsd">
Expand Down Expand Up @@ -60,4 +78,15 @@
<value>fixture-value19</value>
</outcomeVariable>
</itemResult>
</assessmentResult>
<itemResult identifier="fixture-identifier-itemResult4" datestamp="2018-06-27T09:45:45.529" sessionStatus="final" sequenceIndex="2">
<responseVariable cardinality="record" identifier="fixture-identifier6">
<candidateResponse>
<value fieldIdentifier="correct" baseType="integer">1</value>
<value fieldIdentifier="candidateResponse" baseType="string"/>
<value fieldIdentifier="score" baseType="integer">1</value>
<value fieldIdentifier="maxscore" baseType="integer">1</value>
<value fieldIdentifier="applet" baseType="string">payload</value>
</candidateResponse>
</responseVariable>
</itemResult>
</assessmentResult>

0 comments on commit b5b0200

Please sign in to comment.