public function testParsingRegularManifest() { /** @var ManifestMapper $manifestMapper */ $manifestXml = $this->getFixtureFileContents('otherqtis/imsmanifest.xml'); $manifestMapper = AppContainer::getApplicationContainer()->get('imscp_manifest_mapper'); $result = $manifestMapper->parse($manifestXml); }
public function testMapResponseBasic() { $mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); list($item, $questions, $exceptions) = $mapper->parse($this->getFixtureFileContents('interactions/graphic_gap_match.xml')); /** @var item $item */ $this->assertNotNull($item); $this->assertInstanceOf('LearnosityQti\\Entities\\Item\\item', $item); $this->assertEquals('graphicGapfill', $item->get_reference()); $this->assertEquals('<span class="learnosity-response question-graphicGapfill_RESPONSE"></span>', $item->get_content()); $this->assertEquals('published', $item->get_status()); $this->assertEquals('Airport Tags', $item->get_description()); $this->assertEquals(['graphicGapfill_RESPONSE'], $item->get_questionReferences()); $this->assertCount(1, $questions); $this->assertContains('<p>Test intro</p>', $questions[0]->get_data()->get_stimulus()); $this->assertEquals('graphicGapfill_RESPONSE', $questions[0]->get_reference()); $this->assertEquals('imageclozeassociation', $questions[0]->get_type()); /** @var imageclozeassociation $question */ $question = $questions[0]->get_data(); $this->assertEquals(['<img src="images/CBG.png"/>', '<img src="images/EBG.png"/>', '<img src="images/EDI.png"/>', '<img src="images/GLA.png"/>', '<img src="images/MAN.png"/>', '<img src="images/MCH.png"/>'], $question->get_possible_responses()); $this->assertFalse($question->get_duplicate_responses()); /** @var imageclozeassociation_image $img */ $img = $question->get_image(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_image', $img); $this->assertEquals('images/ukairtags.png', $img->get_src()); $this->assertEquals([['x' => 5.83, 'y' => 38.57], ['x' => 62.14, 'y' => 36.79], ['x' => 32.04, 'y' => 58.93]], $question->get_response_positions()); $validation = $question->get_validation(); $this->assertNotNull($validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $this->assertEquals(3, $validation->get_valid_response()->get_score()); $this->assertEquals(['<img src="images/GLA.png"/>', '<img src="images/EDI.png"/>', '<img src="images/MAN.png"/>'], $validation->get_valid_response()->get_value()); $this->assertNull($validation->get_alt_responses()); }
public function testMapResponseWithMixedImageAndTextObject() { $mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); list($item, $questions, $exceptions) = $mapper->parse($this->getFixtureFileContents('interactions/gap_match_with_imageObject.xml')); $this->assertNotNull($item); $this->assertInstanceOf('LearnosityQti\\Entities\\Item\\item', $item); $this->assertEquals('gapMatch', $item->get_reference()); $this->assertCount(1, $questions); $this->assertEquals('gapMatch_RESPONSE', $questions[0]->get_reference()); /** @var clozeassociation $question */ $question = $questions[0]->get_data(); $validation = $question->get_validation(); $this->assertNotNull($validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $this->assertEquals(8, $validation->get_valid_response()->get_score()); $this->assertEquals(['spring', 'spring'], $validation->get_valid_response()->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertCount(5, $altResponses); $this->assertEquals(7, $altResponses[0]->get_score()); $this->assertEquals(['autumn', 'spring'], $altResponses[0]->get_value()); $this->assertEquals(7, $altResponses[1]->get_score()); $this->assertEquals(['spring', '<img src="images/664892_p01_gi02.gif"/>'], $altResponses[1]->get_value()); $this->assertEquals(6, $altResponses[2]->get_score()); $this->assertEquals(['autumn', '<img src="images/664892_p01_gi02.gif"/>'], $altResponses[2]->get_value()); $this->assertEquals(4, $altResponses[3]->get_score()); $this->assertEquals(['<img src="images/664892_p01_gi01.gif"/>', 'spring'], $altResponses[3]->get_value()); $this->assertEquals(3, $altResponses[4]->get_score()); $this->assertEquals(['<img src="images/664892_p01_gi01.gif"/>', '<img src="images/664892_p01_gi02.gif"/>'], $altResponses[4]->get_value()); }
public function testParseWithSectionsThree() { $xml = $this->getFixtureFileContents('tests/rtest03.xml'); $testMapper = AppContainer::getApplicationContainer()->get('qtiv2_test_mapper'); list($activity, $manifest) = $testMapper->parse($xml); /** @var activity $activity */ $this->assertTrue($activity instanceof activity); $this->assertCount(9, $activity->get_data()->get_items()); }
public function testManifestWriter() { /** @var ManifestMapper $manifestMapper */ $manifestXml = $this->getFixtureFileContents('otherqtis/imsmanifest.xml'); $manifestMapper = AppContainer::getApplicationContainer()->get('imscp_manifest_mapper'); $manifest = $manifestMapper->parse($manifestXml); $manifestWriter = new ManifestWriter(); list($activity, $activityTags, $itemTags) = $manifestWriter->convert($manifest); }
public function testParsingWithMathML() { $xml = $this->getFixtureFileContents('interactions/math.xml'); $itemMapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); list($item, $questions) = $itemMapper->parse($xml); $this->assertTrue($item instanceof item); $this->assertCount(1, $questions); /** @var mcq $question */ $question = $questions[0]->get_data(); $this->assertTrue($question instanceof mcq); $this->assertTrue($question->get_is_math()); $this->assertContains('<math>', $question->get_stimulus()); }
public function testSimpleExampleWithCircularsShape() { $mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); list($item, $questions, $exceptions) = $mapper->parse($this->getFixtureFileContents('interactions/hotspot.xml')); $this->assertInstanceOf('LearnosityQti\\Entities\\Item\\item', $item); $this->assertEquals('hotspot', $item->get_reference()); $this->assertContains('<span class="learnosity-response question-hotspot_RESPONSE"></span>', $item->get_content()); $this->assertEquals('published', $item->get_status()); $this->assertCount(1, $item->get_questionReferences()); $this->assertContains('hotspot_RESPONSE', $item->get_questionReferences()); /** @var hotspot $question */ $question = $questions[0]; $this->assertInstanceOf('LearnosityQti\\Entities\\Question', $question); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\hotspot', $question->get_data()); $this->assertEquals('hotspot', $question->get_type()); $validation = $question->get_data()->get_validation(); $this->assertNotNull($validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $this->assertNotNull($validation->get_valid_response()); }
public function testIntegrationSimpleChoiceInteraction() { $mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); list($item, $questions) = $mapper->parse($this->getFixtureFileContents('interactions/choice.xml')); /** @var item $item */ $this->assertInstanceOf('LearnosityQti\\Entities\\Item\\item', $item); $this->assertTrue($item->get_reference() === 'choice'); $this->assertTrue($item->get_status() === 'published'); $this->assertTrue(count($item->get_questionReferences()) === 1); $this->assertTrue(substr_count($item->get_content(), '<span class="learnosity-response question-' . $item->get_questionReferences()[0] . '"></span>') === 1); $this->assertTrue(count($questions) === 1); $q = $questions[0]; $this->assertInstanceOf('\\LearnosityQti\\Entities\\Question', $q); /* @var $q \LearnosityQti\Entities\Question */ $this->assertTrue($q->get_type() === 'mcq'); $this->assertTrue($q->get_reference() === $item->get_reference() . '_' . 'RESPONSE'); /* @var $questionType \LearnosityQti\Entities\QuestionTypes\mcq */ $questionType = $q->get_data(); $this->assertInstanceOf('\\LearnosityQti\\Entities\\QuestionTypes\\mcq', $questionType); $this->assertNotEmpty($questionType->get_stimulus()); $this->assertTrue($questionType->get_type() === 'mcq'); $options = $questionType->get_options(); $this->assertCount(3, $options); $labels = array_column($options, 'label'); $this->assertContains('You must stay with your luggage at all times.', $labels); $this->assertContains('Do not let someone else look after your luggage.', $labels); $this->assertContains('Remember your luggage when you leave.', $labels); $values = array_column($options, 'value'); $this->assertContains('ChoiceA', $values); $this->assertContains('ChoiceB', $values); $this->assertContains('ChoiceC', $values); /* @var $validation \LearnosityQti\Entities\QuestionTypes\mcq_validation */ $validation = $questionType->get_validation(); $this->assertInstanceOf('\\LearnosityQti\\Entities\\QuestionTypes\\mcq_validation', $validation); $this->assertTrue($validation->get_scoring_type() === 'exactMatch'); /* @var $validResponse \LearnosityQti\Entities\QuestionTypes\mcq_validation_valid_response */ $validResponse = $validation->get_valid_response(); $this->assertEquals(1, $validResponse->get_score()); $this->assertTrue($validResponse->get_value()[0] === 'ChoiceA'); }
public function testSimpleCaseFromQTIWebsite() { $mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); list($item, $questions, $exceptions) = $mapper->parse($this->getFixtureFileContents('interactions/hottext.xml')); $this->assertInstanceOf('LearnosityQti\\Entities\\Item\\item', $item); $this->assertEquals('IMS00004_StemError', $item->get_reference()); $this->assertContains('<span class="learnosity-response question-IMS00004_StemError_RESPONSE"></span>', $item->get_content()); $this->assertEquals('published', $item->get_status()); $this->assertCount(1, $item->get_questionReferences()); $this->assertContains('IMS00004_StemError_RESPONSE', $item->get_questionReferences()); /** @var tokenhighlight $question */ $question = $questions[0]; $this->assertInstanceOf('LearnosityQti\\Entities\\Question', $question); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\tokenhighlight', $question->get_data()); $this->assertEquals('tokenhighlight', $question->get_type()); $this->assertEquals('custom', $question->get_data()->get_tokenization()); $validation = $question->get_data()->get_validation(); $this->assertNotNull($validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $this->assertNotNull($validation->get_valid_response()); $this->assertEquals(1, $question->get_data()->get_max_selection()); }
public function parseWithAssessmentItemComponent(AssessmentItem $assessmentItem) { // TODO: Move this logging service upper to converter class level // Make sure we clean up the log // LogService::flush(); $processings = [AppContainer::getApplicationContainer()->get('rubrics_processing'), AppContainer::getApplicationContainer()->get('maths_processing'), AppContainer::getApplicationContainer()->get('assets_processing'), AppContainer::getApplicationContainer()->get('identifiers_processing')]; // Pre-processing works /** @var ProcessingInterface $processing */ foreach ($processings as $processing) { $assessmentItem = $processing->processAssessmentItem($assessmentItem); } $assessmentItem = $this->validateAssessmentItem($assessmentItem); $responseProcessingTemplate = $this->getResponseProcessingTemplate($assessmentItem->getResponseProcessing()); /** @var ItemBody $itemBody */ $itemBody = $assessmentItem->getItemBody(); // Mapping interactions $interactionComponents = $itemBody->getComponentsByClassName(Constants::$supportedInteractions, true); if (!$interactionComponents || count($interactionComponents) === 0) { throw new MappingException('No supported interaction mapper could be found'); } $responseDeclarations = $assessmentItem->getComponentsByClassName('responseDeclaration', true); $itemBuilder = $this->itemBuilderFactory->getItemBuilder($interactionComponents); $itemBuilder->map($assessmentItem->getIdentifier(), $itemBody, $interactionComponents, $responseDeclarations, $responseProcessingTemplate); $item = $itemBuilder->getItem(); if ($assessmentItem->getTitle()) { $item->set_description($assessmentItem->getTitle()); } $questions = $itemBuilder->getQuestions(); // Post-processing works /** @var ProcessingInterface $processing */ foreach ($processings as $processing) { list($item, $questions) = $processing->processItemAndQuestions($item, $questions); } // Flush out all the error messages stored in this static class, also ensure they are unique $messages = array_values(array_unique(LogService::flush())); return [$item, $questions, $messages]; }
public static function convertQtiItemToLearnosity($xmlString, $baseAssetsUrl = '', $validate = true) { $itemMapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); $itemWriter = AppContainer::getApplicationContainer()->get('learnosity_item_writer'); $questionWriter = AppContainer::getApplicationContainer()->get('learnosity_question_writer'); // Parse `em try { list($item, $questions, $exceptions) = $itemMapper->parse($xmlString, $validate); } catch (XmlStorageException $e) { // Check invalid schema error message and intercept to rethrow as known `InvalidQtiException` exception $exceptionMessage = $e->getMessage(); if (StringUtil::startsWith($exceptionMessage, 'The document could not be validated with XML Schema')) { $exceptionMessage = preg_replace('/The document could not be validated with schema(.*)/', 'The document could not be validated with standard QTI schema: ', $exceptionMessage); throw new InvalidQtiException($exceptionMessage); } else { throw $e; } } // Conversion to JSON $itemData = []; if ($item instanceof item) { $itemData = $itemWriter->convert($item); } $questionsData = []; if (is_array($questions)) { foreach ($questions as $question) { $questionsData[] = $questionWriter->convert($question); } } return [$itemData, $questionsData, $exceptions]; }
public function setup() { $this->file = $this->getFixtureFileContents('interactions/extendedtext.xml'); $this->mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); }
public function setup() { $this->file = $this->getFixtureFileContents('interactions/textEntryInteraction-inlineChoiceInteraction.xml'); $this->mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); }
<?php require 'vendor/autoload.php'; use LearnosityQti\AppContainer; // Generate entities $generator = AppContainer::getApplicationContainer()->get('learnosity_entity_generator'); $generator->generateQuestionsClasses(); $generator->generateItemClasses(); $generator->generateActivityClasses(); // Generate documentation $generator = AppContainer::getApplicationContainer()->get('learnosity_documentation_generator'); $generator->generateDocumentation();
public function setup() { $this->mapper = AppContainer::getApplicationContainer()->get('qtiv2_item_mapper'); }