public function testShouldNotHandleMapResponseValidation() { $testOrderInteraction = OrderInteractionBuilder::buildOrderInteraction('testOrderInteraction', ['A' => 'Order A', 'B' => 'Order B', 'C' => 'Order C'], 'testPrompt'); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $validResponseIdentifier = ['A' => [1, false], 'B' => [2, false], 'C' => [3, false]]; $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', $validResponseIdentifier); $mapper = new OrderInteractionMapper($testOrderInteraction, $responseDeclaration, $responseProcessingTemplate); $mapper->getQuestionType(); $this->assertCount(1, LogService::read()); }
public function testSimpleCaseWithInvalidValidation() { $interaction = InlineChoiceInteractionBuilder::buildSimple('testIdentifier', ['doesntmatter' => 'Doesntmatter']); $mapper = new InlineChoiceInteractionMapper($interaction, null, ResponseProcessingTemplate::mapResponsePoint()); $question = $mapper->getQuestionType(); // Should map question correctly with no `validation` object $this->assertNotNull($question); $this->assertEquals('clozedropdown', $question->get_type()); $validation = $question->get_validation(); $this->assertNull($validation); $this->assertTrue(count(LogService::read()) === 1); }
public function testMapWithMergableInteractionType() { $componentCollection = $this->buildComponentCollectionWithMergableInteractionTypes(); $result = $this->mergedItemBuilder->map('testAssessmentItemIdentifier', ItemBodyBuilder::buildItemBody($componentCollection), $componentCollection); $this->assertTrue($result); $this->assertCount(1, LogService::read()); $questions = $this->mergedItemBuilder->getQuestions(); $this->assertCount(1, $questions); $this->assertInstanceOf('LearnosityQti\\Entities\\Question', $questions[0]); $q = $questions[0]; $this->assertEquals('testAssessmentItemIdentifier_testTextEntryInteractionOne_testTextEntryInteractionTwo', $q->get_reference()); $this->assertEquals('clozetext', $q->get_type()); $qData = $q->get_data(); $this->assertEquals('clozetext', $qData->get_type()); $this->assertTrue(substr_count($qData->get_template(), '{{response}}') === 2); }
public function testWithMapResponseValidationMissingAssociableIdentifier() { $bgObject = new Object('http://img.png', 'image/png'); $bgObject->setWidth(100); $bgObject->setHeight(200); $testInteraction = GraphicGapInteractionBuilder::build('testInteraction', $bgObject, ['A' => 'img_A.png', 'B' => 'img_B.png', 'C' => 'img_C.png'], ['G1' => [0, 0, 10, 10], 'G2' => [0, 0, 10, 10]]); $responseProcessingTemplate = ResponseProcessingTemplate::mapResponse(); $responseDeclaration = ResponseDeclarationBuilder::buildWithMapping('testIdentifier', ['A G1' => [1, false]], 'QtiDirectedPair'); $mapper = new GraphicGapMatchInteractionMapper($testInteraction, $responseDeclaration, $responseProcessingTemplate); /** @var imageclozeassociation $q */ $q = $mapper->getQuestionType(); $this->assertEquals('imageclozeassociation', $q->get_type()); $this->assertEquals(['<img src="img_A.png"/>', '<img src="img_B.png"/>', '<img src="img_C.png"/>'], $q->get_possible_responses()); $this->assertFalse($q->get_duplicate_responses()); $this->assertNull($q->get_validation()); $containsWarning = false; foreach (LogService::read() as $message) { if (StringUtil::contains($message, 'Amount of gap identifiers 2 does not match the amount 1 for <responseDeclaration>')) { return true; } } $this->assertTrue($containsWarning); }
public function testInvalidResponseProcessingTemplate() { $interaction = new \qtism\data\content\interactions\TextEntryInteraction('testIdentifier'); $mapper = new TextEntryInteractionMapper($interaction, null, ResponseProcessingTemplate::getFromTemplateUrl('')); $question = $mapper->getQuestionType(); $this->assertCount(1, LogService::read()); }
public function testInvalidResponseProcessingTemplate() { $itemBody = $this->buildItemBodyWithSingleInteraction(); $responseDeclarations = new QtiComponentCollection(); $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithMapping('testIdentifierOne', ['Sydney' => [2, false], 'sydney' => [1, false]])); $mapper = new MergedTextEntryInteractionMapper('dummyReference', $itemBody, $responseDeclarations, ResponseProcessingTemplate::getFromTemplateUrl('')); $question = $mapper->getQuestionType(); $this->assertNotNull($question); $this->assertNull($question->get_validation()); $this->assertCount(1, LogService::read()); }
public function testWithMatchCorrectResponseSwappedValuePair() { $testInteraction = GapMatchInteractionBuilder::buildGapMatchInteraction('testGapMatchInteraction', ['A' => 'Gap A', 'B' => 'Gap B', 'C' => 'Gap C'], [], ['G1', 'G2']); $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect(); $validResponseIdentifier = [new QtiDirectedPair('G1', 'A'), new QtiDirectedPair('G1', 'B'), new QtiDirectedPair('G2', 'C'), new QtiDirectedPair('G2', 'B')]; $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', $validResponseIdentifier); $mapper = new GapMatchInteractionMapper($testInteraction, $responseDeclaration, $responseProcessingTemplate); /** @var clozeassociation $q */ $q = $mapper->getQuestionType(); $this->assertEquals('clozeassociation', $q->get_type()); $this->assertEquals('<p>{{response}}{{response}}</p>', $q->get_template()); $this->assertEquals(['Gap A', 'Gap B', 'Gap C'], $q->get_possible_responses()); $this->assertTrue($q->get_duplicate_responses()); $validation = $q->get_validation(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\clozeassociation_validation', $validation); $this->assertEquals('exactMatch', $validation->get_scoring_type()); $validResponse = $validation->get_valid_response(); $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\clozeassociation_validation_valid_response', $validResponse); $this->assertEquals(1, $validResponse->get_score()); $this->assertEquals(['Gap A', 'Gap C'], $validResponse->get_value()); $altResponses = $validation->get_alt_responses(); $this->assertCount(3, $altResponses); $this->assertEquals(1, $altResponses[0]->get_score()); $this->assertEquals(['Gap A', 'Gap B'], $altResponses[0]->get_value()); $this->assertEquals(1, $altResponses[1]->get_score()); $this->assertEquals(['Gap B', 'Gap C'], $altResponses[1]->get_value()); $this->assertEquals(1, $altResponses[2]->get_score()); $this->assertEquals(['Gap B', 'Gap B'], $altResponses[2]->get_value()); $errorMessages = LogService::read(); $this->assertEmpty($errorMessages); }
public function testHasMinChoice() { $validResponseIdentifier = ['one', 'two']; $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', $validResponseIdentifier); $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect(); $optionsMap = ['one' => 'Label One', 'two' => 'Label Two', 'three' => 'Label Three']; $interaction = ChoiceInteractionBuilder::buildSimple('testIdentifier', $optionsMap); $interaction->setMinChoices(1); $interactionMapper = new ChoiceInteractionMapper($interaction, $responseDeclaration, $responseProcessingTemplate); $interactionMapper->getQuestionType(); $this->assertTrue(count(LogService::read()) === 1); }