public function testTemplateOrientedFeedback() { $file = self::samplesDir() . 'rendering/postrendering/templateoriented_1.xml'; $doc = new \DOMDocument('1.0', 'UTF-8'); $doc->load($file, LIBXML_NONET); $file = file($file); // Check file consistency... $this->assertEquals("<!-- qtism-if ((\$qtismId = \$qtismState['outcome1']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() == 'showoutcome1'): -->", trim($file[3])); $this->assertEquals("<!-- qtism-if ((\$qtismId = \$qtismState['outcome2']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() != 'hideoutcome2'): -->", trim($file[5])); $this->assertEquals("<!-- qtism-endif -->", trim($file[9])); $this->assertEquals("<!-- qtism-endif -->", trim($file[11])); $this->assertEquals("<!-- qtism-if ((\$qtismId = \$qtismState['outcome3']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() != 'hideoutcome3'): -->", trim($file[13])); $this->assertEquals("<!-- qtism-endif -->", trim($file[15])); $this->assertEquals("<div><!-- qtism-printVariable(\$qtismState, \"outcome5\", \"hello int %i!\", false, 10, -1, \";\", \"\", \"=\") --></div>", trim($file[17])); $this->assertEquals("<!-- qtism-if ((\$qtismId = \$qtismState['outcome4']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() == 'showoutcome4'): -->", trim($file[19])); $this->assertEquals("<!-- qtism-endif -->", trim($file[21])); // Check output consistency... $renderer = new MarkupPostRenderer(true, true, true); $output = $renderer->render($doc); $filename = tempnam('/tmp', 'qsm'); file_put_contents($filename, $output); $file = file($filename); $this->assertEquals("<?php if ((\$qtismId = \$qtismState['outcome1']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() == 'showoutcome1'): ?>", trim($file[2])); $this->assertEquals("<?php if ((\$qtismId = \$qtismState['outcome2']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() != 'hideoutcome2'): ?>", trim($file[4])); $this->assertEquals("<?php endif; ?>", trim($file[8])); $this->assertEquals("<?php endif; ?>", trim($file[10])); $this->assertEquals("<?php if ((\$qtismId = \$qtismState['outcome3']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() != 'hideoutcome3'): ?>", trim($file[12])); $this->assertEquals("<?php endif; ?>", trim($file[14])); $this->assertEquals("<div><?php echo qtism\\runtime\\rendering\\markup\\Utils::printVariable(\$qtismState, \"outcome5\", \"hello int %i!\", false, 10, -1, \";\", \"\", \"=\"); ?></div>", trim($file[16])); $this->assertEquals("<?php if ((\$qtismId = \$qtismState['outcome4']) !== null && \$qtismId instanceof qtism\\common\\datatypes\\Identifier && \$qtismId->getValue() == 'showoutcome4'): ?>", trim($file[18])); $this->assertEquals("<?php endif; ?>", trim($file[20])); unlink($filename); }
public function testTemplateOrientedInclude() { $file = self::samplesDir() . 'rendering/postrendering/templateoriented_2.xml'; $doc = new \DOMDocument('1.0', 'UTF-8'); $doc->load($file, LIBXML_NONET); // Check output consistency... $renderer = new MarkupPostRenderer(true, true, true); $output = $renderer->render($doc); $filename = tempnam('/tmp', 'qsm'); file_put_contents($filename, $output); $file = file($filename); $this->assertEquals('<?php include(dirname(__FILE__) . "/0-" . $qtismState->getShuffledChoiceIdentifierAt(0, 0) . ".phtml"); ?>', trim($file[4])); $this->assertEquals('<?php include(dirname(__FILE__) . "/0-" . $qtismState->getShuffledChoiceIdentifierAt(0, 2) . ".phtml"); ?>', trim($file[6])); $fragments = $renderer->getFragments(); $this->assertEquals($fragments[0]['path'], '0-red.phtml'); $this->assertEquals($fragments[1]['path'], '0-black.phtml'); unlink($filename); }