public function testShouldHandleMatchCorrectValidationWithoutMultipleResponses()
 {
     $interaction = MatchInteractionBuilder::buildMatchInteraction('testMatchInteraction', [['A' => 'Item A', 'B' => 'Item B'], ['C' => 'Item C', 'D' => 'Item D']]);
     $interaction->setMaxAssociations(2);
     $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect();
     $validResponseIdentifier = [new QtiDirectedPair('A', 'D'), new QtiDirectedPair('B', 'C')];
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', $validResponseIdentifier);
     $mapper = new MatchInteractionMapper($interaction, $responseDeclaration, $responseProcessingTemplate);
     /** @var choicematrix $choicematrix */
     $choicematrix = $mapper->getQuestionType();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\choicematrix', $choicematrix);
     $this->assertEquals('choicematrix', $choicematrix->get_type());
     $this->assertCount(2, $choicematrix->get_options());
     $this->assertContains('Item C', $choicematrix->get_options());
     $this->assertContains('Item D', $choicematrix->get_options());
     $this->assertCount(2, $choicematrix->get_stems());
     $this->assertContains('Item A', $choicematrix->get_stems());
     $this->assertContains('Item B', $choicematrix->get_stems());
     $validation = $choicematrix->get_validation();
     $this->assertTrue($validation instanceof choicematrix_validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     $validResponse = $validation->get_valid_response();
     $this->assertTrue($validResponse instanceof choicematrix_validation_valid_response);
     $this->assertEquals(1, $validResponse->get_score());
     $this->assertEquals([[1], [0]], $validResponse->get_value());
     $this->assertFalse($choicematrix->get_multiple_responses());
 }
 public function testSimpleCaseWithMatchCorrectValidation()
 {
     $interaction = InlineChoiceInteractionBuilder::buildSimple('testIdentifier', ['sydney' => 'Sydney', 'melbourne' => 'Melbourne', 'canberra' => 'Canberra']);
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', ['sydney', 'melbourne']);
     $mapper = new InlineChoiceInteractionMapper($interaction, $responseDeclaration, ResponseProcessingTemplate::matchCorrect());
     $question = $mapper->getQuestionType();
     $this->assertNotNull($question);
     $this->assertEquals('clozedropdown', $question->get_type());
     // Should populate possible responses
     $this->assertCount(1, $question->get_possible_responses());
     $this->assertCount(3, $question->get_possible_responses()[0]);
     $this->assertContains('Sydney', $question->get_possible_responses()[0]);
     $this->assertContains('Melbourne', $question->get_possible_responses()[0]);
     $this->assertContains('Canberra', $question->get_possible_responses()[0]);
     // Should have validation object
     $validation = $question->get_validation();
     $this->assertNotNull($validation);
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\clozedropdown_validation', $validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     // Should set both `valid_response` and `alt_responses` for multiple correct values
     $validResponse = $validation->get_valid_response();
     $this->assertNotNull($validResponse);
     $this->assertEquals(1, $validResponse->get_score());
     $this->assertEquals(["Sydney"], $validResponse->get_value());
     $altResponses = $validation->get_alt_responses();
     $this->assertNotNull($altResponses);
     $this->assertCount(1, $altResponses);
     $this->assertEquals(1, $altResponses[0]->get_score());
     $this->assertEquals(["Melbourne"], $altResponses[0]->get_value());
 }
 public function testMultipleInteractionWithMatchCorrectValidation()
 {
     $itemBody = $this->buildItemBodyWithTwoInteractions();
     $responseDeclarations = new QtiComponentCollection();
     $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifierTwo', ['keanu', 'gloria']));
     $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifierOne', ['sydney']));
     $mapper = new MergedInlineChoiceInteractionMapper('dummyQuestionReference', $itemBody, $responseDeclarations, ResponseProcessingTemplate::matchCorrect());
     $question = $mapper->getQuestionType();
     // Should map question correctly with `validation` object of `exactMatch` scoring type
     $this->assertNotNull($question);
     $this->assertEquals('<p>The Matrix movie is filmed at {{response}}, and starring {{response}}</p>', $question->get_template());
     $this->assertEquals('clozedropdown', $question->get_type());
     // Should set both `valid_response` and `alt_responses` for multiple correct values
     $validation = $question->get_validation();
     $this->assertNotNull($validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     $validResponse = $validation->get_valid_response();
     $this->assertNotNull($validResponse);
     $this->assertEquals(2, $validResponse->get_score());
     $this->assertEquals(["Sydney", "Keanu Reeves"], $validResponse->get_value());
     $altResponses = $validation->get_alt_responses();
     $this->assertNotNull($altResponses);
     $this->assertCount(1, $altResponses);
     $this->assertEquals(2, $altResponses[0]->get_score());
     $this->assertEquals(["Sydney", "Gloria Foster"], $altResponses[0]->get_value());
 }
 public function testWithMatchCorrectValidation()
 {
     $interaction = $this->buildHottextInteraction('identifierOne');
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('identifierOne', ['A', 'C']);
     $mapper = new HottextInteractionMapper($interaction, $responseDeclaration, ResponseProcessingTemplate::matchCorrect());
     $question = $mapper->getQuestionType();
     $this->assertNotNull($question);
     $this->assertEquals('tokenhighlight', $question->get_type());
     $validation = $question->get_validation();
     $this->assertNotNull($validation);
     $this->assertEquals(1, $validation->get_valid_response()->get_score());
     $this->assertEquals([0, 2], $validation->get_valid_response()->get_value());
 }
 public function testHotspotWithCircleShape()
 {
     $interaction = HotspotInteractionBuilder::buildWithCircleShapesChoices('testIdentifier');
     $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect();
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', ['A']);
     $mapper = new HotspotInteractionMapper($interaction, $responseDeclaration, $responseProcessingTemplate);
     $question = $mapper->getQuestionType();
     $this->assertEquals('hotspot', $question->get_type());
     $this->assertNotEmpty($question->get_area_attributes()->get_global());
     // Assert areas calculation is correct
     $areas = $question->get_areas();
     $this->assertEquals([['x' => 33.5, 'y' => 43.93], ['x' => 41.26, 'y' => 43.93], ['x' => 41.26, 'y' => 38.21], ['x' => 33.5, 'y' => 38.21]], $areas['A']);
     $this->assertEquals([['x' => 53.4, 'y' => 68.56999999999999], ['x' => 61.17, 'y' => 68.56999999999999], ['x' => 61.17, 'y' => 62.86], ['x' => 53.4, 'y' => 62.86]], $areas['B']);
     // Assert exact match validation
     $validation = $question->get_validation();
     $this->assertNotNull($validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     $this->assertEquals(1, $validation->get_valid_response()->get_score());
     $this->assertEquals([0], $validation->get_valid_response()->get_value());
 }
 public function testShouldHandleMatchCorrectValidation()
 {
     $testOrderInteraction = OrderInteractionBuilder::buildOrderInteraction('testOrderInteraction', ['A' => 'Order A', 'B' => 'Order B', 'C' => 'Order C'], 'testPrompt');
     $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect();
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', ['C', 'B', 'A']);
     $mapper = new OrderInteractionMapper($testOrderInteraction, $responseDeclaration, $responseProcessingTemplate);
     /** @var orderlist $q */
     $q = $mapper->getQuestionType();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\orderlist', $q);
     $this->assertEquals('orderlist', $q->get_type());
     $this->assertEquals('testPrompt', $q->get_stimulus());
     $this->assertEquals(['Order A', 'Order B', 'Order C'], $q->get_list());
     $validation = $q->get_validation();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\orderlist_validation', $validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     /** @var orderlist_validation_valid_response $validResponse */
     $validResponse = $validation->get_valid_response();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\orderlist_validation_valid_response', $validResponse);
     $this->assertEquals(1, $validResponse->get_score());
     $this->assertEquals([2, 1, 0], $validResponse->get_value());
     $this->assertNull($validation->get_alt_responses());
 }
 public function testSimpleCaseWithMatchCorrectValidation()
 {
     $interaction = new \qtism\data\content\interactions\TextEntryInteraction('testIdentifier');
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', ['hello', 'Hello']);
     $mapper = new TextEntryInteractionMapper($interaction, $responseDeclaration, ResponseProcessingTemplate::matchCorrect());
     $question = $mapper->getQuestionType();
     $this->assertNotNull($question);
     $validation = $question->get_validation();
     $this->assertNotNull($validation);
     $validResponse = $validation->get_valid_response();
     $this->assertNotNull($validResponse);
     $this->assertEquals(1, $validResponse->get_score());
     $responses = [];
     $responses[] = $validResponse->get_value()[0];
     $altResponses = $validation->get_alt_responses();
     $this->assertTrue(count($altResponses) === 1);
     $this->assertEquals(1, $altResponses[0]->get_score());
     foreach ($altResponses[0]->get_value() as $value) {
         $responses[] = $value;
     }
     $this->assertTrue(count($responses) === 2);
     $this->assertContains('hello', $responses);
     $this->assertContains('Hello', $responses);
 }
 public function testTwoInteractionWithCorrectAnswersValidation()
 {
     $itemBody = $this->buildItemBodyWithTwoInteraction();
     $responseDeclarations = new QtiComponentCollection();
     $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifierTwo', ['Gloria Foster', 'Keanu Reeves', 'Laurence Fishburne']));
     $responseDeclarations->attach(ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifierOne', ['Sydney']));
     $mapper = new MergedTextEntryInteractionMapper('dummyReference', $itemBody, $responseDeclarations, ResponseProcessingTemplate::matchCorrect());
     $question = $mapper->getQuestionType();
     // Should map question correctly with `validation` object of `exactMatch` scoring type
     $this->assertNotNull($question);
     $this->assertEquals('<p>The Matrix movie is filmed at {{response}}, and starring {{response}}</p>', $question->get_template());
     $this->assertEquals('clozetext', $question->get_type());
     // Should set both `valid_response` and `alt_responses` for multiple correct values
     $validation = $question->get_validation();
     $this->assertNotNull($validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     $options = [];
     $validResponse = $validation->get_valid_response();
     $this->assertNotNull($validResponse);
     $this->assertEquals(2, $validResponse->get_score());
     $options[] = $validResponse->get_value();
     $altResponses = $validation->get_alt_responses();
     $this->assertNotNull($altResponses);
     $this->assertCount(2, $altResponses);
     foreach ($altResponses as $altResponse) {
         $this->assertEquals(2, $altResponse->get_score());
         $options[] = $altResponse->get_value();
     }
     $this->assertContains(['Sydney', 'Gloria Foster'], $options);
     $this->assertContains(['Sydney', 'Keanu Reeves'], $options);
     $this->assertContains(['Sydney', 'Laurence Fishburne'], $options);
     // `match_correct` validation template always do not set casesensitive
     $this->assertFalse($question->get_case_sensitive());
 }
 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);
 }
 public function testMatchCorrectValidation()
 {
     $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'], ['G1' => [0, 0, 10, 10], 'G2' => [30, 40, 50, 60]]);
     $responseProcessingTemplate = ResponseProcessingTemplate::matchCorrect();
     $validResponseIdentifier = [new QtiDirectedPair('A', 'G1'), new QtiDirectedPair('A', 'G2'), new QtiDirectedPair('B', 'G1')];
     $responseDeclaration = ResponseDeclarationBuilder::buildWithCorrectResponse('testIdentifier', $validResponseIdentifier);
     $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"/>'], $q->get_possible_responses());
     $this->assertTrue($q->get_duplicate_responses());
     $this->assertEquals([['x' => 0, 'y' => 0], ['x' => 30, 'y' => 20]], $q->get_response_positions());
     $img = $q->get_image();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_image', $img);
     $this->assertEquals('http://img.png', $img->get_src());
     /** @var imageclozeassociation_validation $validation */
     $validation = $q->get_validation();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_validation', $validation);
     $this->assertEquals('exactMatch', $validation->get_scoring_type());
     /** @var imageclozeassociation_validation_valid_response $validResponse */
     $validResponse = $validation->get_valid_response();
     $this->assertInstanceOf('LearnosityQti\\Entities\\QuestionTypes\\imageclozeassociation_validation_valid_response', $validResponse);
     $this->assertEquals(1, $validResponse->get_score());
     $this->assertEquals(['<img src="img_A.png"/>', '<img src="img_A.png"/>'], $validResponse->get_value());
     $altResponses = $validation->get_alt_responses();
     $this->assertCount(1, $altResponses);
     $this->assertEquals(1, $altResponses[0]->get_score());
     $this->assertEquals(['<img src="img_B.png"/>', '<img src="img_A.png"/>'], $altResponses[0]->get_value());
 }