当前位置: 首页>>代码示例>>PHP>>正文


PHP xml\XmlDocument类代码示例

本文整理汇总了PHP中qtism\data\storage\xml\XmlDocument的典型用法代码示例。如果您正苦于以下问题:PHP XmlDocument类的具体用法?PHP XmlDocument怎么用?PHP XmlDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XmlDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAssigningScoresAndCorrectResponses

 public function testAssigningScoresAndCorrectResponses()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/items/template_processing.xml');
     $session = new AssessmentItemSession($doc->getDocumentComponent());
     $itemSessionControl = new ItemSessionControl();
     $itemSessionControl->setMaxAttempts(0);
     $session->setItemSessionControl($itemSessionControl);
     $session->beginItemSession();
     // Check that the templateProcessing was correctly processed.
     $this->assertEquals('ChoiceA', $session->getVariable('RESPONSE')->getCorrectResponse()->getValue());
     $this->assertEquals(1.0, $session['GOODSCORE']->getValue());
     $this->assertEquals(0.0, $session['WRONGSCORE']->getValue());
     // Check that it really works...
     // With a correct response.
     $session->beginAttempt();
     $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceA'))));
     $session->endAttempt($responses);
     $this->assertEquals(1.0, $session['SCORE']->getValue());
     // With an incorrect response.
     $session->beginAttempt();
     $responses = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceB'))));
     $session->endAttempt($responses);
     $this->assertEquals(0.0, $session['SCORE']->getValue());
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:25,代码来源:AssessmentItemSessionTemplateTest.php

示例2: testSeparateStylesheetTwo

 public function testSeparateStylesheetTwo()
 {
     // The loaded component is still a rubricBlock but this
     // time with two (YES, TWO!) stylesheets.
     $doc = new XmlDocument('2.1');
     $doc->load(self::samplesDir() . 'rendering/rubricblock_3.xml');
     $this->assertEquals(2, count($doc->getDocumentComponent()->getStylesheets()));
     $renderingEngine = new XhtmlRenderingEngine();
     $renderingEngine->setStylesheetPolicy(XhtmlRenderingEngine::STYLESHEET_SEPARATE);
     $rendering = $renderingEngine->render($doc->getDocumentComponent());
     $linkElts = $rendering->getElementsByTagName('link');
     $this->assertEquals(0, $linkElts->length);
     $linksFragment = $renderingEngine->getStylesheets();
     $this->assertInstanceOf('\\DOMDocumentFragment', $linksFragment);
     $this->assertEquals(2, $linksFragment->childNodes->length);
     // Test first <link> element.
     $linkElt = $linksFragment->childNodes->item(0);
     $this->assertEquals('link', $linkElt->localName);
     $this->assertEquals('style1.css', $linkElt->getAttribute('href'));
     $this->assertEquals('text/css', $linkElt->getAttribute('type'));
     $this->assertEquals('screen', $linkElt->getAttribute('media'));
     $this->assertEquals('\\0_ !HOURRAY! _0/', $linkElt->getAttribute('title'));
     // Test second <link> element.
     $linkElt = $linksFragment->childNodes->item(1);
     $this->assertEquals('link', $linkElt->localName);
     $this->assertEquals('style2.css', $linkElt->getAttribute('href'));
     $this->assertEquals('text/css', $linkElt->getAttribute('type'));
     $this->assertEquals('screen', $linkElt->getAttribute('media'));
     $this->assertEquals('0/*\\0 (Jedi duel)', $linkElt->getAttribute('title'));
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:30,代码来源:XhtmlRenderingEngineTest.php

示例3: parse

 public function parse($xmlString, $validate = true)
 {
     // TODO: Remove this, and move it higher up
     LogService::flush();
     $xmlDocument = new XmlDocument();
     if ($validate === false) {
         LogService::log('QTI pre-validation is turned off, some invalid attributes might be stripped from XML content upon conversion');
     }
     $xmlDocument->loadFromString($xmlString, $validate);
     /** @var AssessmentItem $assessmentItem */
     $assessmentTest = $xmlDocument->getDocumentComponent();
     if (!$assessmentTest instanceof AssessmentTest) {
         throw new MappingException('XML is not a valid <assessmentItem> document');
     }
     // Ignore `testPart` and `assessmentSection`. Grab every item references and merge in array
     $itemReferences = [];
     foreach ($assessmentTest->getComponentsByClassName('assessmentItemRef', true) as $assessmentItemRef) {
         $itemReferences[] = $assessmentItemRef->getIdentifier();
     }
     LogService::log('Support for mapping is very limited. Elements such `testPart`, `assessmentSections`, `seclection`, `rubricBlock`, ' . 'etc are ignored. Please see developer docs for more details');
     $data = new activity_data();
     $data->set_items($itemReferences);
     $activity = new activity($assessmentTest->getIdentifier(), $data);
     // Flush out all the error messages stored in this static class, also ensure they are unique
     $messages = array_values(array_unique(LogService::flush()));
     return [$activity, $messages];
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:27,代码来源:TestMapper.php

示例4: testFromJson

 /**
  * Test {@link taoQtiTest_models_classes_QtiTestConverter::fromJson}
  * @dataProvider dataProvider
  * 
  * @param string $testPath            
  * @param string $json            
  */
 public function testFromJson($testPath, $json)
 {
     $doc = new XmlDocument('2.1');
     $converter = new taoQtiTest_models_classes_QtiTestConverter($doc);
     $converter->fromJson($json);
     $result = preg_replace(array('/ {2,}/', '/<!--.*?-->|\\t|(?:\\r?\\n[ \\t]*)+/s'), array(' ', ''), $doc->saveToString());
     $expected = preg_replace(array('/ {2,}/', '/<!--.*?-->|\\t|(?:\\r?\\n[ \\t]*)+/s'), array(' ', ''), file_get_contents($testPath));
     $this->assertEquals($result, $expected);
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:16,代码来源:QtiTestConverterTest.php

示例5: testGetShuffledChoiceIdentifierAtInvalidShuffledChoiceIndex

 public function testGetShuffledChoiceIdentifierAtInvalidShuffledChoiceIndex()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'ims/items/2_1/choice_fixed.xml');
     $session = new AssessmentItemSession($doc->getDocumentComponent());
     $session->beginItemSession();
     $this->setExpectedException('\\OutOfBoundsException', 'No identifier at index 1337.');
     $session->getShuffledChoiceIdentifierAt(0, 1337);
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:9,代码来源:AssessmentItemSessionShufflingTest.php

示例6: testTimeLimits

 public function testTimeLimits()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/timelimits.xml');
     $testPart = $doc->getDocumentComponent()->getComponentByIdentifier('testPartId');
     $this->assertTrue($testPart->hasTimeLimits());
     $timeLimits = $testPart->getTimeLimits();
     $this->assertTrue($timeLimits->getMinTime()->equals(new Duration('PT60S')));
     $this->assertTrue($timeLimits->getMaxTime()->equals(new Duration('PT120S')));
     $this->assertTrue($timeLimits->doesAllowLateSubmission());
 }
开发者ID:hutnikau,项目名称:qti-sdk,代码行数:11,代码来源:AssessmentTestTest.php

示例7: testMappingMcqQuestion

    public function testMappingMcqQuestion()
    {
        $questionJson = $this->getFixtureFileContents('learnosityjsons/item_mcq.json');
        $question = json_decode($questionJson, true);
        list($xmlString, $messages) = Converter::convertLearnosityToQtiItem($question);
        $this->assertNotNull($xmlString);
        $this->assertTrue(StringUtil::startsWith($xmlString, '<?xml version="1.0" encoding="UTF-8"?>
<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"'));
        $document = new XmlDocument();
        $document->loadFromString($xmlString);
        $this->assertNotNull($document);
    }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:12,代码来源:QuestionMapperTest.php

示例8: testItemSessionControls

 public function testItemSessionControls()
 {
     $doc = new XmlDocument('2.1');
     $doc->load(self::samplesDir() . 'custom/runtime/routeitem_itemsessioncontrols.xml');
     // Q01.
     $q01 = $doc->getDocumentComponent()->getComponentByIdentifier('Q01');
     $this->assertInstanceOf('qtism\\data\\AssessmentItemRef', $q01);
     $this->assertEquals(2, $q01->getItemSessionControl()->getMaxAttempts());
     // P02.
     $p02 = $doc->getDocumentComponent()->getComponentByIdentifier('P02');
     $this->assertInstanceOf('qtism\\data\\TestPart', $p02);
     $this->assertEquals(4, $p02->getItemSessionControl()->getMaxAttempts());
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:13,代码来源:XmlAssessmentTestDocumentTest.php

示例9: processResponses

 /**
  * Item's ResponseProcessing.
  *
  * @param core_kernel_classes_Resource $item The Item you want to apply ResponseProcessing.
  * @throws \RuntimeException If an error occurs while processing responses or transmitting results
  */
 protected function processResponses(core_kernel_classes_Resource $item)
 {
     $jsonPayload = taoQtiCommon_helpers_Utils::readJsonPayload();
     try {
         $qtiXmlFilePath = QtiFile::getQtiFilePath($item);
         $qtiXmlDoc = new XmlDocument();
         $qtiXmlDoc->load($qtiXmlFilePath);
     } catch (StorageException $e) {
         $msg = "An error occurred while loading QTI-XML file at expected location '{$qtiXmlFilePath}'.";
         common_Logger::e($e->getPrevious()->getMessage());
         throw new \RuntimeException($msg, 0, $e);
     }
     $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), new SessionManager());
     $itemSession->beginItemSession();
     $variables = array();
     $filler = new taoQtiCommon_helpers_PciVariableFiller($qtiXmlDoc->getDocumentComponent());
     // Convert client-side data as QtiSm Runtime Variables.
     foreach ($jsonPayload as $id => $response) {
         try {
             $var = $filler->fill($id, $response);
             // Do not take into account QTI Files at preview time.
             // Simply delete the created file.
             if (taoQtiCommon_helpers_Utils::isQtiFile($var, false) === true) {
                 $fileManager = taoQtiCommon_helpers_Utils::getFileDatatypeManager();
                 $fileManager->delete($var->getValue());
             } else {
                 $variables[] = $var;
             }
         } catch (OutOfRangeException $e) {
             // A variable value could not be converted, ignore it.
             // Developer's note: QTI Pairs with a single identifier (missing second identifier of the pair) are transmitted as an array of length 1,
             // this might cause problem. Such "broken" pairs are simply ignored.
             common_Logger::d("Client-side value for variable '{$id}' is ignored due to data malformation.");
         } catch (OutOfBoundsException $e) {
             // No such identifier found in item.
             common_Logger::d("The variable with identifier '{$id}' is not declared in the item definition.");
         }
     }
     try {
         $itemSession->beginAttempt();
         $itemSession->endAttempt(new State($variables));
         // Return the item session state to the client-side.
         echo json_encode(array('success' => true, 'displayFeedback' => true, 'itemSession' => self::buildOutcomeResponse($itemSession)));
     } catch (AssessmentItemSessionException $e) {
         $msg = "An error occurred while processing the responses.";
         throw new \RuntimeException($msg, 0, $e);
     } catch (taoQtiCommon_helpers_ResultTransmissionException $e) {
         $msg = "An error occurred while transmitting a result to the target Result Server.";
         throw new \RuntimeException($msg, 0, $e);
     }
 }
开发者ID:nagyist,项目名称:extension-tao-itemqti,代码行数:57,代码来源:QtiPreview.php

示例10: testBasicSelection

 public function testBasicSelection()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/runtime/selection_and_ordering.xml');
     $testPart = $doc->getDocumentComponent()->getComponentByIdentifier('testPart');
     $this->assertEquals('testPart', $testPart->getIdentifier());
     $s01 = $doc->getDocumentComponent()->getComponentByIdentifier('S01', true);
     $this->assertEquals('S01', $s01->getIdentifier());
     // Prepare route selection of S01A.
     $s01a = $doc->getDocumentComponent()->getComponentByIdentifier('S01A', true);
     $this->assertEquals('S01A', $s01a->getIdentifier());
     $s01aRoute = new SelectableRoute();
     foreach ($s01a->getSectionParts() as $sectionPart) {
         $s01aRoute->addRouteItem($sectionPart, $s01a, $testPart, $doc->getDocumentComponent());
     }
     // Prepare route selection of S01B.
     $s01b = $doc->getDocumentComponent()->getComponentByIdentifier('S01B', true);
     $this->assertEquals('S01B', $s01b->getIdentifier());
     $s01bRoute = new SelectableRoute();
     foreach ($s01b->getSectionParts() as $sectionPart) {
         $s01bRoute->addRouteItem($sectionPart, $s01b, $testPart, $doc->getDocumentComponent());
     }
     $selection = new BasicSelection($s01, new SelectableRouteCollection(array($s01aRoute, $s01bRoute)));
     $selectedRoutes = $selection->select();
     $selectedRoute = new SelectableRoute();
     foreach ($selectedRoutes as $r) {
         $selectedRoute->appendRoute($r);
     }
     $routeCheck1 = self::isRouteCorrect($selectedRoute, array('Q1', 'Q2', 'Q3'));
     $routeCheck2 = self::isRouteCorrect($selectedRoute, array('Q4', 'Q5', 'Q6'));
     $this->assertFalse($routeCheck1 === true && $routeCheck2 === true);
     $this->assertTrue($routeCheck1 === true || $routeCheck2 === true);
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:33,代码来源:BasicSelectionTest.php

示例11: testLoadInteractionMixSaschsen

 public function testLoadInteractionMixSaschsen()
 {
     $xmlDoc = new XmlDocument('2.1');
     $xmlDoc->load(self::samplesDir() . 'ims/tests/interaction_mix_sachsen/interaction_mix_sachsen.xml');
     $phpDoc = new PhpDocument();
     $phpDoc->setDocumentComponent($xmlDoc->getDocumentComponent());
     $file = tempnam('/tmp', 'qsm');
     $phpDoc->save($file);
     $phpDoc = new PhpDocument();
     $phpDoc->load($file);
     $this->assertEquals('InteractionMixSachsen_1901710679', $phpDoc->getDocumentComponent()->getIdentifier());
     unlink($file);
     $this->assertFalse(file_exists($file));
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:14,代码来源:PhpDocumentTest.php

示例12: testLoadAndResolveXIncludeDifferentBase

 /**
  * @depends testLoadAndResolveXIncludeSameBase
  */
 public function testLoadAndResolveXIncludeDifferentBase()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'custom/items/xinclude/xinclude_ns_in_tag_subfolder.xml', true);
     $doc->xInclude();
     $includes = $doc->getDocumentComponent()->getComponentsByClassName('include');
     $this->assertEquals(0, count($includes));
     // And we should find an img component then!
     $imgs = $doc->getDocumentComponent()->getComponentsByClassName('img');
     $this->assertEquals(1, count($imgs));
     // Check that xml:base was appropriately resolved. In this case,
     // no content for xml:base because 'xinclude_ns_in_tag_content1.xml' is in the
     // same directory as the main xml file.
     $this->assertEquals('subfolder/', $imgs[0]->getXmlBase());
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:18,代码来源:XmlDocumentXIncludeTest.php

示例13: testModerateXmlBase

 public function testModerateXmlBase()
 {
     $doc = new XmlDocument();
     $doc->load(self::samplesDir() . 'rendering/xmlbase_2.xml');
     $div = $doc->getDocumentComponent();
     $this->assertInstanceOf('qtism\\data\\content\\xhtml\\text\\Div', $div);
     $this->assertFalse($div->hasXmlBase());
     $this->assertEquals('', $div->getXmlBase());
     $subDivs = $div->getComponentsByClassName('div');
     $this->assertEquals(2, count($subDivs));
     $this->assertTrue($subDivs[0]->hasXmlBase());
     $this->assertEquals('http://www.qtism-project.org/farm/', $subDivs[0]->getXmlBase());
     $this->assertTrue($subDivs[1]->hasXmlBase());
     $this->assertEquals('http://www.qtism-project.org/birds/', $subDivs[1]->getXmlBase());
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:15,代码来源:XmlAssessmentContentDocumentTest.php

示例14: convertToAssessmentItem

 protected function convertToAssessmentItem(array $data)
 {
     list($xml, $manifest) = Converter::convertLearnosityToQtiItem($data);
     // Assert the XML string is formed and not empty
     // Also, assert manifest is in form of array, regardless it was empty or not
     $this->assertTrue(is_string($xml) && !empty($xml));
     $this->assertTrue(is_array($manifest));
     $document = new XmlDocument();
     $document->loadFromString($xml);
     /** @var AssessmentItem $assessmentItem */
     $assessmentItem = $document->getDocumentComponent();
     // Basic assert on <assessmentItem> object
     $this->assertNotNull($assessmentItem);
     $this->assertTrue($assessmentItem instanceof AssessmentItem);
     return $assessmentItem;
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:16,代码来源:AbstractQuestionTypeTest.php

示例15: parse

 public function parse($xmlString, $validate = true)
 {
     // TODO: Remove this, and move it higher up
     LogService::flush();
     $xmlDocument = new XmlDocument();
     if ($validate === false) {
         LogService::log('QTI pre-validation is turned off, some invalid attributes might be stripped from XML content upon conversion');
     }
     $xmlDocument->loadFromString($xmlString, $validate);
     /** @var AssessmentItem $assessmentItem */
     $assessmentItem = $xmlDocument->getDocumentComponent();
     if (!$assessmentItem instanceof AssessmentItem) {
         throw new MappingException('XML is not a valid <assessmentItem> document');
     }
     return $this->parseWithAssessmentItemComponent($assessmentItem);
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:16,代码来源:ItemMapper.php


注:本文中的qtism\data\storage\xml\XmlDocument类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。