load(__DIR__ . '/../../../../samples/xml/test.xml'); $this->xmlDoc = $doc; $this->testResourceMock = $this->createMock(core_kernel_classes_Resource::class); $this->qtiTestServiceMock = $this->createMock(taoQtiTest_models_classes_QtiTestService::class); $this->qtiTestServiceMock->method('getDoc')->with($this->testResourceMock)->willReturn($this->xmlDoc); $this->serviceLocatorMock = $this->getServiceLocatorMock([ taoQtiTest_models_classes_QtiTestService::class => $this->qtiTestServiceMock ]); } public function testGetTestXml() { $service = new XmlEditor(); $service->setServiceLocator($this->serviceLocatorMock); $xmlString = $service->getTestXml($this->testResourceMock); $this->assertEquals($this->xmlDoc->saveToString(), $xmlString); } /** * @throws XmlStorageException * @throws taoQtiTest_models_classes_QtiTestConverterException * @throws taoQtiTest_models_classes_QtiTestServiceException */ public function testSaveStringTest() { $service = new XmlEditor(); $xmlMock = <<<'EOL' EOL; $expectArrayTest = [ "qti-type" => "assessmentTest", "identifier" => "UnitTestQtiItem", "title" => "UnitTestQtiItem", "toolName" => "tao", "toolVersion" => "3.4.0-sprint130", "outcomeDeclarations" => [ ], "testParts" => [ [ "qti-type" => "testPart", "identifier" => "testPart-1", "navigationMode" => 0, "submissionMode" => 0, "preConditions" => [ ], "branchRules" => [ ], "itemSessionControl" => [ "qti-type" => "itemSessionControl", "maxAttempts" => 0, "showFeedback" => false, "allowReview" => true, "showSolution" => false, "allowComment" => false, "validateResponses" => false, "allowSkipping" => true ], "assessmentSections" => [ [ "qti-type" => "assessmentSection", "title" => "Section 1", "visible" => true, "keepTogether" => true, "rubricBlocks" => [ ], "sectionParts" => [ ], "identifier" => "assessmentSection-1", "required" => true, "fixed" => false, "preConditions" => [ ], "branchRules" => [ ], "observers" => new SplObjectStorage(), ] ], "testFeedbacks" => [ ], "observers" => new SplObjectStorage(), ] ], "testFeedbacks" => [ ], "observers" => new SplObjectStorage(), ]; $this->qtiTestServiceMock ->expects($this->once()) ->method('saveJsonTest') ->with($this->testResourceMock, json_encode($expectArrayTest)); $service->setServiceLocator($this->serviceLocatorMock); $service->saveStringTest($this->testResourceMock, $xmlMock); } public function testIsLocked() { $service = new XmlEditor([XmlEditor::OPTION_XML_EDITOR_LOCK => false]); $this->assertEquals(false, $service->isLocked()); } }