本文整理汇总了PHP中qtism\data\storage\xml\XmlDocument::saveToString方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlDocument::saveToString方法的具体用法?PHP XmlDocument::saveToString怎么用?PHP XmlDocument::saveToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtism\data\storage\xml\XmlDocument
的用法示例。
在下文中一共展示了XmlDocument::saveToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: testLoadSaveToStringSchemaValidate
/**
* @dataProvider qtiImplementationGuideAssessmentTestFiles
*
* @param string $uri The URI describing the file to load.
*/
public function testLoadSaveToStringSchemaValidate($uri)
{
$doc = new XmlDocument('2.1');
$doc->load($uri);
$file = tempnam('/tmp', 'qsm');
$str = $doc->saveToString();
file_put_contents($file, $str);
$doc = new XmlDocument('2.1');
try {
$doc->load($file, true);
// validate on load.
$this->assertTrue(true);
unlink($file);
} catch (XmlStorageException $e) {
$this->assertTrue(false, $e->getMessage());
unlink($file);
}
}
示例3: convert
public function convert(item $item, array $questions)
{
// Make sure we clean up the log
LogService::flush();
// Try to build the identifier using item `reference`
// Otherwise, generate an alternative identifier and store the original reference as `label`
$itemReference = $item->get_reference();
$itemIdentifier = Format::isIdentifier($itemReference, false) ? $itemReference : 'ITEM_' . StringUtil::generateRandomString(12);
if ($itemReference !== $itemIdentifier) {
LogService::log("The item `reference` ({$itemReference}) is not a valid identifier, thus can not be used for `assessmentItem` identifier. " . "Replaced it with randomly generated `{$itemIdentifier}` and stored the original `reference` as `label` attribute");
}
$builder = new AssessmentItemBuilder();
$assessmentItem = $builder->build($itemIdentifier, $itemReference, $questions, $item->get_content());
$xml = new XmlDocument();
$xml->setDocumentComponent($assessmentItem);
// Flush out all the error messages stored in this static class, also ensure they are unique
$messages = array_values(array_unique(LogService::flush()));
return [$xml->saveToString(true), $messages];
}
示例4: explodeRubricBlocks
/**
* Explode the rubric blocks of the test definition into separate QTI-XML files and
* remove the compact XML document from the file system (useless for
* the rest of the compilation process).
*
* @param XmlCompactDocument $compiledDoc
*/
protected function explodeRubricBlocks(XmlCompactDocument $compiledDoc)
{
$privateDir = $this->getPrivateDirectory();
$explodedRubricBlocks = $compiledDoc->explodeRubricBlocks();
foreach ($explodedRubricBlocks as $href => $rubricBlock) {
$doc = new XmlDocument();
$doc->setDocumentComponent($rubricBlock);
$data = $doc->saveToString();
$privateDir->write($href, $data);
}
}
示例5: testEmbedAssets
/**
* @dataProvider sharedStimulusConvertProvider
*/
public function testEmbedAssets($directory, $exception, $converted)
{
$xmlDocument = new XmlDocument();
$xmlDocument->load($directory . '/stimulus.xml');
try {
$xmlConverted = SharedStimulusPackageImporter::embedAssets($directory . '/stimulus.xml');
$xmlDocument->load($xmlConverted);
$strXml = $xmlDocument->saveToString();
$xmlDocument->load($converted);
$convertStr = $xmlDocument->saveToString();
$this->assertEquals($convertStr, $strXml, __('Conversion return a wrong string'));
} catch (\tao_models_classes_FileNotFoundException $e) {
$this->assertNotNull($exception, __('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'));
}
}
}
}
示例6: testUnknownClassWhileSavingBecauseOfVersion3
public function testUnknownClassWhileSavingBecauseOfVersion3()
{
$doc = new XmlDocument('2.2.0');
$doc->loadFromString('
<div>
<bdo dir="rtl">I am reversed!</bdo>
</div>');
// This should fail because in QTI 2.2.0 because <bdo> does not exist.
$doc->setVersion('2.1.0');
$expectedMsg = "'bdo' components are not supported in QTI version '2.1.0'";
$this->setExpectedException('qtism\\data\\storage\\xml\\XmlStorageException', $expectedMsg, XmlStorageException::VERSION);
$str = $doc->saveToString(true);
}
示例7: saveDoc
/**
* Save the content of test from a QTI Document
* @param core_kernel_classes_Resource $test
* @param qtism\data\storage\xml\XmlDocument $doc
* @return boolean true if saved
* @throws taoQtiTest_models_classes_QtiTestServiceException
*/
private function saveDoc(core_kernel_classes_Resource $test, XmlDocument $doc)
{
$file = $this->getQtiTestFile($test);
return $file->update($doc->saveToString());
}