createTest($testIdentifier, $testTitle); $this->extendTest($test); $xmlDoc = new XmlDocument($this->getQtiVersion(), $test); return $xmlDoc->saveToString(); } /** * @param string $testIdentifier * @param string $testTitle * * @return AssessmentTest * @throws InvalidService * @throws InvalidServiceManagerException * @throws common_exception_Error * @throws common_ext_ExtensionException */ protected function createTest(string $testIdentifier, string $testTitle): AssessmentTest { $itemSectionControl = new ItemSessionControl(); $itemSectionControl->setMaxAttempts($this->getConfigurationRegistry()->getMaxAttempts()); $assessmentSection = new AssessmentSection( $this->getAssessmentSectionId(), $this->getAssessmentSectionTitle(), true ); $assessmentSection->setRequired(true); $assessmentSections = new AssessmentSectionCollection([$assessmentSection]); $testPart = new TestPart( $this->getTestPartId(), $assessmentSections, $this->getConfigurationRegistry()->getNavigationMode(), $this->getConfigurationRegistry()->getSubmissionMode() ); $testPart->setItemSessionControl($itemSectionControl); $testPartCollection = new TestPartCollection([$testPart]); $test = new AssessmentTest($testIdentifier, $testTitle, $testPartCollection); $test->setToolName('tao'); $test->setToolVersion($this->getApplicationService()->getPlatformVersion()); return $test; } private function extendTest(AssessmentTest $test): void { $testExtensionsClassNames = $this->getOption(self::OPTION_EXTENSIONS); if (!$testExtensionsClassNames || !is_array($testExtensionsClassNames)) { return; } foreach ($testExtensionsClassNames as $testExtensionsClassName) { try { $testExtension = $this->getServiceLocator()->get($testExtensionsClassName); } catch (ServiceNotFoundException $e) { $testExtension = new $testExtensionsClassName(); } if (!$testExtension instanceof TestExtensionInterface) { throw new RuntimeException('A test extension should inherit ' . TestExtensionInterface::class); } $testExtension->extend($test); } } /** * @return string * * @throws InvalidService * @throws InvalidServiceManagerException */ private function getAssessmentSectionId(): string { return "{$this->getConfigurationRegistry()->getSectionIdPrefix()}-1"; } /** * @return string * * @throws InvalidService * @throws InvalidServiceManagerException */ private function getAssessmentSectionTitle(): string { return "{$this->getConfigurationRegistry()->getSectionTitlePrefix()} 1"; } private function getQtiVersion(): string { return $this->getOption(self::OPTION_QTI_VERSION) ?? self::DEFAULT_QTI_VERSION; } /** * @return string * * @throws InvalidService * @throws InvalidServiceManagerException */ private function getTestPartId(): string { return "{$this->getConfigurationRegistry()->getPartIdPrefix()}-1"; } private function getApplicationService(): ApplicationService { /** @noinspection PhpIncompatibleReturnTypeInspection */ return $this->getServiceLocator()->get(ApplicationService::SERVICE_ID); } /** * @return DefaultConfigurationRegistry * * @throws InvalidService * @throws InvalidServiceManagerException */ private function getConfigurationRegistry(): DefaultConfigurationRegistry { return $this->getSubService(self::OPTION_CONFIGURATION_REGISTRY, DefaultConfigurationRegistry::class); } }