本文整理匯總了PHP中qtism\data\storage\xml\XmlDocument::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP XmlDocument::load方法的具體用法?PHP XmlDocument::load怎麽用?PHP XmlDocument::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtism\data\storage\xml\XmlDocument
的用法示例。
在下文中一共展示了XmlDocument::load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: 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());
}
示例3: 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'));
}
示例4: testWrite
public function testWrite()
{
$uri = self::samplesDir() . 'custom/standalone_assessmentsection.xml';
$doc = new XmlDocument();
$doc->load($uri);
$assessmentSection = $doc->getDocumentComponent();
// Write the file.
$uri = tempnam('/tmp', 'qsm');
$doc->save($uri);
$this->assertTrue(file_exists($uri));
// Reload it.
$doc->load($uri);
$this->assertInstanceOf('qtism\\data\\AssessmentSection', $doc->getDocumentComponent());
// Retest.
$this->testLoad($doc->getDocumentComponent());
unlink($uri);
}
示例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);
}
示例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());
}
示例7: testToJson
/**
* Test {@link taoQtiTest_models_classes_QtiTestConverter::toJson}
* @dataProvider dataProvider
*
* @param string $testPath
* the path of the QTI test to convert
* @param string $expected
* the expected json result
*/
public function testToJson($testPath, $expected)
{
$doc = new XmlDocument('2.1');
try {
$doc->load($testPath);
} catch (StorageException $e) {
$this->fail($e->getMessage());
}
$converter = new taoQtiTest_models_classes_QtiTestConverter($doc);
$result = $converter->toJson();
$this->assertEquals($expected, $result);
}
示例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());
}
示例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);
}
}
示例10: 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));
}
示例11: 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());
}
示例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());
}
示例13: testIsValidSharedStimulus
/**
* @dataProvider sharedStimulusFilenameProvider
*/
public function testIsValidSharedStimulus($filename, $response, $exception)
{
try {
$xmlDocumentValid = SharedStimulusImporter::isValidSharedStimulus($filename);
$this->assertTrue($response, __('It should not be valid'));
$xmlDocument = new XmlDocument();
$xmlDocument->load($filename);
$this->assertEquals($xmlDocument->getDomDocument()->C14N(), $xmlDocumentValid->getDomDocument()->C14N(), __('The loaded cml is wrong'));
} catch (\Exception $e) {
$this->assertFalse($response, __('It should not throw an exception'));
if (!is_null($e)) {
$this->assertInstanceOf(get_class($exception), $e, __('The exception class is wrong'));
if ($exception->getMessage() !== '') {
$this->assertEquals($exception->getMessage(), $e->getMessage(), __('The exception message is wrong'));
}
}
}
}
示例14: testAssessmentTests
function testAssessmentTests(array $files, $validate = false)
{
$loaded = 0;
$totalSpent = 0;
foreach ($files as $f) {
$start = microtime();
$testDoc = new XmlDocument();
$testDoc->load($f, $validate);
$end = microtime();
$spent = spentTime($start, $end);
$totalSpent += $spent;
output("Test '" . pathinfo($f, PATHINFO_BASENAME) . "' loaded in " . sprintf("%.8f", $spent) . " seconds.");
$partCount = count($testDoc->getDocumentComponent()->getComponentsByClassName('testPart'));
$sectionCount = count($testDoc->getDocumentComponent()->getComponentsByClassName('assessmentSection'));
$itemCount = count($testDoc->getDocumentComponent()->getComponentsByClassName('assessmentItemRef'));
outputDescription("{$partCount} testPart(s), {$sectionCount} assessmentSection(s), {$itemCount} assessmentItemRef(s)");
outputDescription("Memory usage is " . memory_get_usage() / pow(1024, 2) . " MB");
output('');
$loaded++;
}
outputAverage($totalSpent / $loaded);
}
示例15: dirname
<?php
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine;
use qtism\runtime\common\State;
use qtism\runtime\common\TemplateVariable;
use qtism\common\enums\BaseType;
use qtism\common\enums\Cardinality;
use qtism\common\datatypes\QtiString;
require_once dirname(__FILE__) . '/../../vendor/autoload.php';
$doc = new XmlDocument();
$doc->load(dirname(__FILE__) . '/../samples/rendering/math_3.xml');
$tpl_E = new TemplateVariable('TPL_E', Cardinality::SINGLE, BaseType::STRING, new QtiString('E'));
$tpl_m = new TemplateVariable('TPL_m', Cardinality::SINGLE, BaseType::STRING, new QtiString('m'));
$tpl_c = new TemplateVariable('TPL_c', Cardinality::SINGLE, BaseType::STRING, new QtiString('c'));
$renderer = new XhtmlRenderingEngine();
$renderer->setState(new State(array($tpl_E, $tpl_m, $tpl_c)));
$renderer->setPrintedVariablePolicy(XhtmlRenderingEngine::TEMPLATE_ORIENTED);
$rendering = $renderer->render($doc->getDocumentComponent());
$rendering->formatOutput = true;
echo $rendering->saveXML();