Exemplo n.º 1
0
 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'));
 }
<?php

use qtism\runtime\rendering\markup\AbstractMarkupRenderingEngine;
use qtism\data\View;
use qtism\data\ViewCollection;
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine;
require_once dirname(__FILE__) . '/../../qtism/qtism.php';
$doc = new XmlDocument();
$doc->load('../samples/rendering/rubricblock_2.xml');
$renderer = new XhtmlRenderingEngine();
$separate = false;
if (isset($argv[1]) && strtolower($argv[1]) === 'separate') {
    $separate = true;
}
$renderer->setStylesheetPolicy($separate === true ? XhtmlRenderingEngine::STYLESHEET_SEPARATE : XhtmlRenderingEngine::STYLESHEET_INLINE);
$rendering = $renderer->render($doc->getDocumentComponent());
$rendering->formatOutput = true;
echo $rendering->saveXML();
if ($separate === true) {
    echo "\n\nSeparate Stylesheets:\n";
    echo "----------------------\n\n";
    $stylesheets = $renderer->getStylesheets();
    echo $stylesheets->ownerDocument->saveXML($stylesheets) . "\n";
}
 /**
  * Initialize the compilation by:
  * 
  * * 1. Spawning public and private compilation directoryies.
  * * 2. Instantiating appropriate rendering engine and CSS utilities.
  * 
  * for the next compilation process.
  */
 protected function initCompilation()
 {
     $ds = DIRECTORY_SEPARATOR;
     // Initialize public and private compilation directories.
     $this->setPrivateDirectory($this->spawnPrivateDirectory());
     $this->setPublicDirectory($this->spawnPublicDirectory());
     // Extra path.
     $testService = taoQtiTest_models_classes_QtiTestService::singleton();
     $testDefinitionDir = dirname($testService->getRelTestPath($this->getResource()));
     $this->setExtraPath($testDefinitionDir);
     // Initialize rendering engine.
     $renderingEngine = new XhtmlRenderingEngine();
     $renderingEngine->setStylesheetPolicy(XhtmlRenderingEngine::STYLESHEET_SEPARATE);
     $renderingEngine->setXmlBasePolicy(XhtmlRenderingEngine::XMLBASE_PROCESS);
     $renderingEngine->setFeedbackShowHidePolicy(XhtmlRenderingEngine::TEMPLATE_ORIENTED);
     $renderingEngine->setViewPolicy(XhtmlRenderingEngine::TEMPLATE_ORIENTED);
     $renderingEngine->setPrintedVariablePolicy(XhtmlRenderingEngine::TEMPLATE_ORIENTED);
     $renderingEngine->setStateName(TAOQTITEST_RENDERING_STATE_NAME);
     $renderingEngine->setRootBase(TAOQTITEST_PLACEHOLDER_BASE_URI . rtrim($this->getExtraPath(), $ds));
     $renderingEngine->setViewsName(TAOQTITEST_VIEWS_NAME);
     $this->setRenderingEngine($renderingEngine);
     // Initialize CSS Scoper.
     $this->setCssScoper(new CssScoper());
     // Initialize Post Markup Renderer.
     $this->setMarkupPostRenderer(new MarkupPostRenderer(true, true, true));
 }
Exemplo n.º 4
0
 /**
  * Instantiate an appropriate Rendering Engine.
  * 
  * The instantiated Rendering Engine implementation will depend on the "flavour"
  * CLI argument.
  * 
  * @return \qtism\runtime\rendering\markup\AbstractMarkupRenderingEngine
  */
 private function instantiateEngine()
 {
     $arguments = $this->getArguments();
     $engine = null;
     switch (strtolower($arguments['flavour'])) {
         case 'goldilocks':
             $engine = new GoldilocksRenderingEngine();
             break;
         case 'xhtml':
             $engine = new XhtmlRenderingEngine();
             break;
     }
     if ($arguments['xmlbase'] === 'process') {
         $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_PROCESS);
     } elseif ($arguments['xmlbase'] === 'keep') {
         $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_KEEP);
     } elseif ($arguments['xmlbase'] === 'ignore') {
         $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_IGNORE);
     }
     if ($arguments['document'] === true) {
         $engine->setStylesheetPolicy(AbstractMarkupRenderingEngine::STYLESHEET_SEPARATE);
     }
     if ($arguments['csshierarchy'] === true) {
         $engine->setCssClassPolicy(AbstractMarkupRenderingEngine::CSSCLASS_ABSTRACT);
     }
     return $engine;
 }