diff --git a/src/qtism/data/content/xhtml/Img.php b/src/qtism/data/content/xhtml/Img.php index f6f27367f..d34cea471 100644 --- a/src/qtism/data/content/xhtml/Img.php +++ b/src/qtism/data/content/xhtml/Img.php @@ -32,6 +32,8 @@ */ class Img extends AtomicInline { + public const QTI_CLASS_NAME_IMG='img'; + /** * The img's src attribute. * diff --git a/src/qtism/data/content/xhtml/html5/Figcaption.php b/src/qtism/data/content/xhtml/html5/Figcaption.php new file mode 100644 index 000000000..8fcb41ac0 --- /dev/null +++ b/src/qtism/data/content/xhtml/html5/Figcaption.php @@ -0,0 +1,81 @@ +setContent(new InlineCollection()); + } + + public function getQtiClassName() + { + return self::QTI_CLASS_NAME_FIGCAPTION; + } + + public function getComponents() + { + return $this->getContent(); + } + + /** + * Set the collection of Flow objects composing the Div. + * + * @param InlineCollection $content A collection of Flow objects. + */ + public function setContent(InlineCollection $content) + { + $this->content = $content; + } + + /** + * Get the collection of Flow objects composing the Div. + * + * @return InlineCollection + */ + public function getContent() + { + return $this->content; + } +} diff --git a/src/qtism/data/content/xhtml/html5/Figure.php b/src/qtism/data/content/xhtml/html5/Figure.php new file mode 100644 index 000000000..89d03ab57 --- /dev/null +++ b/src/qtism/data/content/xhtml/html5/Figure.php @@ -0,0 +1,81 @@ +setContent(new FlowCollection()); + } + + public function getQtiClassName() + { + return self::QTI_CLASS_NAME_FIGURE; + } + + public function getComponents() + { + return $this->getContent(); + } + + /** + * Set the collection of Flow objects composing the Div. + * + * @param FlowCollection $content A collection of Flow objects. + */ + public function setContent(FlowCollection $content) + { + $this->content = $content; + } + + /** + * Get the collection of Flow objects composing the Div. + * + * @return FlowCollection + */ + public function getContent() + { + return $this->content; + } +} diff --git a/src/qtism/data/storage/xml/marshalling/ContentMarshaller.php b/src/qtism/data/storage/xml/marshalling/ContentMarshaller.php index 5d93e54e3..941dad67f 100644 --- a/src/qtism/data/storage/xml/marshalling/ContentMarshaller.php +++ b/src/qtism/data/storage/xml/marshalling/ContentMarshaller.php @@ -52,6 +52,8 @@ use qtism\data\content\SimpleInline; use qtism\data\content\TemplateBlock; use qtism\data\content\TemplateInline; +use qtism\data\content\xhtml\html5\Figcaption; +use qtism\data\content\xhtml\html5\Figure; use qtism\data\content\xhtml\lists\Dl; use qtism\data\content\xhtml\lists\DlElement; use qtism\data\content\xhtml\lists\Li; @@ -64,6 +66,7 @@ use qtism\data\content\xhtml\tables\Tr; use qtism\data\content\xhtml\text\Blockquote; use qtism\data\content\xhtml\text\Div; +use qtism\data\content\xhtml\Img; use qtism\data\ExternalQtiComponent; use qtism\data\QtiComponent; use qtism\data\QtiComponentCollection; @@ -106,7 +109,7 @@ public function __construct($version) 'graphicGapMatchInteraction', 'hotspotChoice', 'hr', - 'img', + Img::QTI_CLASS_NAME_IMG, 'include', 'math', 'mediaInteraction', @@ -177,6 +180,8 @@ public function __construct($version) 'modalFeedback', 'feedbackBlock', 'bdo', + Figure::QTI_CLASS_NAME_FIGURE, + Figcaption::QTI_CLASS_NAME_FIGCAPTION ]; /** @@ -288,6 +293,10 @@ protected function getChildrenComponents(QtiComponent $component) return $component->getContent()->getArrayCopy(); } elseif ($component instanceof InfoControl) { return $component->getContent()->getArrayCopy(); + } elseif ($component instanceof Figure) { + return $component->getContent()->getArrayCopy(); + } elseif ($component instanceof Figcaption) { + return $component->getContent()->getArrayCopy(); } } @@ -341,6 +350,8 @@ protected function getChildrenElements(DOMElement $element) return self::getChildElements($element); } elseif ($localName === 'simpleMatchSet') { return $this->getChildElementsByTagName($element, 'simpleAssociableChoice'); + } elseif ($localName === Figure::QTI_CLASS_NAME_FIGURE) { + return $this->getChildElementsByTagName($element, [Figcaption::QTI_CLASS_NAME_FIGCAPTION, Img::QTI_CLASS_NAME_IMG]); } elseif ($localName === 'gapImg') { return $this->getChildElementsByTagName($element, 'object'); } else { diff --git a/src/qtism/data/storage/xml/marshalling/Html5ContentMarshaller.php b/src/qtism/data/storage/xml/marshalling/Html5ContentMarshaller.php new file mode 100644 index 000000000..1fd89a933 --- /dev/null +++ b/src/qtism/data/storage/xml/marshalling/Html5ContentMarshaller.php @@ -0,0 +1,103 @@ + + * @license GPLv2 + */ + +namespace qtism\data\storage\xml\marshalling; + +use DOMElement; +use qtism\common\utils\Version; +use qtism\data\content\FlowCollection; +use qtism\data\content\xhtml\html5\Html5Element; +use qtism\data\QtiComponent; +use qtism\data\QtiComponentCollection; + +/** + * Marshalling/Unmarshalling implementation for generic Html5. + */ +abstract class Html5ContentMarshaller extends ContentMarshaller +{ + use QtiNamespacePrefixTrait; + use QtiHtml5AttributeTrait; + + public function getExpectedQtiClassName() + { + return Version::compare($this->getVersion(), '2.2', '>=') ? static::getExpectedQtiClassName() : 'not_existing'; + } + + abstract protected static function getContentCollectionClassName(); + + /** + * @param DOMElement $element + * @param QtiComponentCollection $children + * @return mixed + * @throws UnmarshallingException + */ + protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) + { + $fqClass = $this->lookupClass($element); + $component = new $fqClass(); + $collectionClassName = static::getContentCollectionClassName() ?? FlowCollection::class; + + $component->setContent(new $collectionClassName($children->getArrayCopy())); + + if (($xmlBase = self::getXmlBase($element)) !== false) { + $component->setXmlBase($xmlBase); + } + + $this->fillBodyElementAttributes($component, $element); + $this->fillBodyElement($component, $element); + + return $component; + } + + + /** + * @param QtiComponent $component + * @param array $elements + * @return DOMElement + */ + protected function marshallChildrenKnown(QtiComponent $component, array $elements) + { + /** @var Html5Element $component */ + $element = $this->getNamespacedElement($component); + + if ($component->hasXmlBase() === true) { + self::setXmlBase($element, $component->getXmlBase()); + } + + foreach ($elements as $e) { + $element->appendChild($e); + } + + $this->fillElement($element, $component); + + return $element; + } + + protected function setLookupClasses() + { + $this->lookupClasses = [ + "qtism\\data\\content\\xhtml", + "qtism\\data\\content\\xhtml\\html5" + ]; + } +} diff --git a/src/qtism/data/storage/xml/marshalling/Html5ElementMarshaller.php b/src/qtism/data/storage/xml/marshalling/Html5ElementMarshaller.php index 13e16f172..e8d59b10f 100644 --- a/src/qtism/data/storage/xml/marshalling/Html5ElementMarshaller.php +++ b/src/qtism/data/storage/xml/marshalling/Html5ElementMarshaller.php @@ -24,48 +24,33 @@ namespace qtism\data\storage\xml\marshalling; use DOMElement; -use qtism\common\utils\Version; use qtism\data\content\BodyElement; -use qtism\data\content\enums\Role; use qtism\data\content\xhtml\html5\Html5Element; use qtism\data\QtiComponent; -use qtism\data\storage\xml\versions\QtiVersion; /** * Marshalling/Unmarshalling implementation for generic Html5. */ abstract class Html5ElementMarshaller extends Marshaller { + use QtiNamespacePrefixTrait; + use QtiHtml5AttributeTrait; + /** * Marshall a Html5 element object into a DOMElement object. * * @param QtiComponent $component * @return DOMElement The according DOMElement object. + * @throws \DOMException */ protected function marshall(QtiComponent $component): DOMElement { /** @var Html5Element $component */ - $prefix = $component->getTargetNamespacePrefix(); - $version = QtiVersion::create($this->getVersion()); - $namespace = $version->getExternalNamespace($prefix); - - $element = static::getDOMCradle()->createElementNS( - $namespace, - $prefix . ':' . $component->getQtiClassName() - ); - + $element = $this->getNamespacedElement($component); $this->fillElement($element, $component); - if ($component->hasTitle()) { - $this->setDOMElementAttribute($element, 'title', $component->getTitle()); - } - - if ($component->hasRole()) { - $this->setDOMElementAttribute($element, 'role', Role::getNameByConstant($component->getRole())); - } - - return $element; + return $this->marshallHtml5Attributes($component, $element); } /** @@ -80,13 +65,7 @@ protected function marshall(QtiComponent $component): DOMElement */ protected function fillBodyElement(BodyElement $bodyElement, DOMElement $element) { - if (Version::compare($this->getVersion(), '2.2.0', '>=') === true) { - $title = $this->getDOMElementAttributeAs($element, 'title'); - $bodyElement->setTitle($title); - - $role = $this->getDOMElementAttributeAs($element, 'role', Role::class); - $bodyElement->setRole($role); - } + $this->fillBodyElementAttributes($bodyElement, $element); parent::fillBodyElement($bodyElement, $element); } diff --git a/src/qtism/data/storage/xml/marshalling/Html5FigcaptionMarshaller.php b/src/qtism/data/storage/xml/marshalling/Html5FigcaptionMarshaller.php new file mode 100644 index 000000000..107f8b72e --- /dev/null +++ b/src/qtism/data/storage/xml/marshalling/Html5FigcaptionMarshaller.php @@ -0,0 +1,84 @@ +hasId()) { + $this->setDOMElementAttribute($element, 'id', $component->getId()); + } + + if ($component->hasClass()) { + $this->setDOMElementAttribute($element, 'class', $component->getClass()); + } + + return $component; + } + + /** + * @param QtiComponent $component + * @param array $elements + * @return DOMElement + */ + protected function marshallChildrenKnown(QtiComponent $component, array $elements) + { + $element = parent::marshallChildrenKnown($component, $elements); + + if ($component->hasId()) { + $this->setDOMElementAttribute($element, 'id', $component->getId()); + } + + if ($component->hasClass()) { + $this->setDOMElementAttribute($element, 'class', $component->getClass()); + } + + return $element; + } + + protected static function getContentCollectionClassName() + { + return InlineCollection::class; + } +} diff --git a/src/qtism/data/storage/xml/marshalling/Html5FigureMarshaller.php b/src/qtism/data/storage/xml/marshalling/Html5FigureMarshaller.php new file mode 100644 index 000000000..d4c9c87fd --- /dev/null +++ b/src/qtism/data/storage/xml/marshalling/Html5FigureMarshaller.php @@ -0,0 +1,85 @@ +hasId()) { + $this->setDOMElementAttribute($element, 'id', $component->getId()); + } + + if ($component->hasClass()) { + $this->setDOMElementAttribute($element, 'class', $component->getClass()); + } + + return $component; + } + + /** + * @param QtiComponent $component + * @param array $elements + * @return DOMElement + */ + protected function marshallChildrenKnown(QtiComponent $component, array $elements) + { + $element = parent::marshallChildrenKnown($component, $elements); + + if ($component->hasId()) { + $this->setDOMElementAttribute($element, 'id', $component->getId()); + } + + if ($component->hasClass()) { + $this->setDOMElementAttribute($element, 'class', $component->getClass()); + } + + return $element; + } + + protected static function getContentCollectionClassName() + { + return FlowCollection::class; + } +} diff --git a/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php b/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php index 8c3cd1fd5..81da816b8 100644 --- a/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php +++ b/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php @@ -26,6 +26,8 @@ use DOMElement; use InvalidArgumentException; use qtism\data\ExternalQtiComponent; +use qtism\data\content\xhtml\html5\Figure; +use qtism\data\content\xhtml\html5\Figcaption; use qtism\data\QtiComponent; use qtism\data\storage\xml\QtiNamespaced; use qtism\data\storage\xml\Utils; diff --git a/src/qtism/data/storage/xml/marshalling/Qti22MarshallerFactory.php b/src/qtism/data/storage/xml/marshalling/Qti22MarshallerFactory.php index f7fb7e541..c4837864c 100644 --- a/src/qtism/data/storage/xml/marshalling/Qti22MarshallerFactory.php +++ b/src/qtism/data/storage/xml/marshalling/Qti22MarshallerFactory.php @@ -24,6 +24,8 @@ namespace qtism\data\storage\xml\marshalling; use qtism\common\utils\Reflection; +use qtism\data\content\xhtml\html5\Figcaption; +use qtism\data\content\xhtml\html5\Figure; use ReflectionClass; /** @@ -41,6 +43,8 @@ public function __construct() { parent::__construct(); $this->addMappingEntry('bdo', SimpleInlineMarshaller::class); + $this->addMappingEntry(Figure::QTI_CLASS_NAME_FIGURE, Html5FigureMarshaller::class); + $this->addMappingEntry(Figcaption::QTI_CLASS_NAME_FIGCAPTION, Html5FigcaptionMarshaller::class); } /** diff --git a/src/qtism/data/storage/xml/marshalling/QtiHtml5AttributeTrait.php b/src/qtism/data/storage/xml/marshalling/QtiHtml5AttributeTrait.php new file mode 100644 index 000000000..c541ad82b --- /dev/null +++ b/src/qtism/data/storage/xml/marshalling/QtiHtml5AttributeTrait.php @@ -0,0 +1,62 @@ +hasTitle()) { + $this->setDOMElementAttribute($element, 'title', $component->getTitle()); + } + + if ($component->hasRole()) { + $this->setDOMElementAttribute($element, 'role', Role::getNameByConstant($component->getRole())); + } + + return $element; + } + + protected function fillBodyElementAttributes(BodyElement &$bodyElement, DOMElement $element) + { + if (Version::compare($this->getVersion(), '2.2.0', '>=') === true) { + $title = $this->getDOMElementAttributeAs($element, 'title'); + $bodyElement->setTitle($title); + + $role = $this->getDOMElementAttributeAs($element, 'role', Role::class); + $bodyElement->setRole($role); + } + } +} diff --git a/src/qtism/data/storage/xml/marshalling/QtiNamespacePrefixTrait.php b/src/qtism/data/storage/xml/marshalling/QtiNamespacePrefixTrait.php new file mode 100644 index 000000000..7e6f4f381 --- /dev/null +++ b/src/qtism/data/storage/xml/marshalling/QtiNamespacePrefixTrait.php @@ -0,0 +1,53 @@ +getTargetNamespacePrefix(); + $version = QtiVersion::create($this->getVersion()); + $namespace = $version->getExternalNamespace($prefix); + + return Marshaller::getDOMCradle()->createElementNS( + $namespace, + $prefix . ':' . $component->getQtiClassName() + ); + } +} diff --git a/src/qtism/runtime/rendering/markup/xhtml/FigcaptionRenderer.php b/src/qtism/runtime/rendering/markup/xhtml/FigcaptionRenderer.php new file mode 100644 index 000000000..ba6c1d67a --- /dev/null +++ b/src/qtism/runtime/rendering/markup/xhtml/FigcaptionRenderer.php @@ -0,0 +1,46 @@ +hasId()) { + $fragment->firstChild->setAttribute('id', $component->getId()); + } + if ($component->hasClass()) { + $fragment->firstChild->setAttribute('class', $component->getClass()); + } + } +} diff --git a/src/qtism/runtime/rendering/markup/xhtml/FigureRenderer.php b/src/qtism/runtime/rendering/markup/xhtml/FigureRenderer.php new file mode 100644 index 000000000..4403f3549 --- /dev/null +++ b/src/qtism/runtime/rendering/markup/xhtml/FigureRenderer.php @@ -0,0 +1,46 @@ +hasId()) { + $fragment->firstChild->setAttribute('id', $component->getId()); + } + if ($component->hasClass()) { + $fragment->firstChild->setAttribute('class', $component->getClass()); + } + } +} diff --git a/src/qtism/runtime/rendering/markup/xhtml/XhtmlRenderingEngine.php b/src/qtism/runtime/rendering/markup/xhtml/XhtmlRenderingEngine.php index 22ad527ec..415e09931 100644 --- a/src/qtism/runtime/rendering/markup/xhtml/XhtmlRenderingEngine.php +++ b/src/qtism/runtime/rendering/markup/xhtml/XhtmlRenderingEngine.php @@ -23,6 +23,8 @@ namespace qtism\runtime\rendering\markup\xhtml; +use qtism\data\content\xhtml\html5\Figcaption; +use qtism\data\content\xhtml\html5\Figure; use qtism\runtime\rendering\markup\AbstractMarkupRenderingEngine; /** @@ -119,6 +121,8 @@ public function __construct() $this->registerRenderer('extendedTextInteraction', new ExtendedTextInteractionRenderer()); $this->registerRenderer('feedbackBlock', new FeedbackBlockRenderer()); $this->registerRenderer('feedbackInline', new FeedbackInlineRenderer()); + $this->registerRenderer(Figure::QTI_CLASS_NAME_FIGURE, new FigureRenderer()); + $this->registerRenderer(Figcaption::QTI_CLASS_NAME_FIGCAPTION, new FigcaptionRenderer()); $this->registerRenderer('gap', new GapRenderer()); $this->registerRenderer('gapImg', new GapImgRenderer()); $this->registerRenderer('gapMatchInteraction', new GapMatchInteractionRenderer()); diff --git a/test/qtismtest/data/content/xhtml/html5/FigcaptionTest.php b/test/qtismtest/data/content/xhtml/html5/FigcaptionTest.php new file mode 100644 index 000000000..74c75fbbb --- /dev/null +++ b/test/qtismtest/data/content/xhtml/html5/FigcaptionTest.php @@ -0,0 +1,55 @@ +getId()); + self::assertEquals($class, $subject->getClass()); + } + + public function testCreateWithDefaultValues(): void + { + $subject = new Figcaption(); + + self::assertEquals('', $subject->getId()); + self::assertEquals('', $subject->getClass()); + } + + public function testGetQtiClassName(): void + { + $subject = new Figcaption(); + + self::assertEquals(Figcaption::QTI_CLASS_NAME_FIGCAPTION, $subject->getQtiClassName()); + } +} diff --git a/test/qtismtest/data/content/xhtml/html5/FigureTest.php b/test/qtismtest/data/content/xhtml/html5/FigureTest.php new file mode 100644 index 000000000..fb2573625 --- /dev/null +++ b/test/qtismtest/data/content/xhtml/html5/FigureTest.php @@ -0,0 +1,55 @@ +getId()); + self::assertEquals($class, $subject->getClass()); + } + + public function testCreateWithDefaultValues(): void + { + $subject = new Figure(); + + self::assertEquals('', $subject->getId()); + self::assertEquals('', $subject->getClass()); + } + + public function testGetQtiClassName(): void + { + $subject = new Figure(); + + self::assertEquals(Figure::QTI_CLASS_NAME_FIGURE, $subject->getQtiClassName()); + } +} diff --git a/test/qtismtest/data/storage/xml/marshalling/Html5FigcaptionMarshallerTest.php b/test/qtismtest/data/storage/xml/marshalling/Html5FigcaptionMarshallerTest.php new file mode 100644 index 000000000..0ed3a95f7 --- /dev/null +++ b/test/qtismtest/data/storage/xml/marshalling/Html5FigcaptionMarshallerTest.php @@ -0,0 +1,134 @@ +assertHtml5MarshallingOnlyInQti22AndAbove(new Figcaption(), Figcaption::QTI_CLASS_NAME_FIGCAPTION); + } + + /** + * @throws MarshallerNotFoundException + * @throws MarshallingException + */ + public function testMarshall22(): void + { + $id = 'id'; + $class = 'testclass'; + + $expected = sprintf( + '<%1$s id="%2$s" class="%3$s">text content', + $this->namespaceTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + $id, + $class, + $this->prefixTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + ); + + $object = new Figcaption(null, null, $id, $class); + $object->setContent(new InlineCollection([new TextRun('text content')])); + + $this->assertMarshalling($expected, $object); + } + + /** + * @throws MarshallerNotFoundException + * @throws MarshallingException + */ + public function testMarshall22WithDefaultValues(): void + { + $expected = sprintf( + '<%s>text content', + $this->namespaceTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + $this->prefixTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION) + ); + + $object = new Figcaption(); + $object->setContent(new InlineCollection([new TextRun('text content')])); + + $this->assertMarshalling($expected, $object); + } + + /** + * @throws MarshallerNotFoundException + */ + public function testUnMarshallerDoesNotExistInQti21(): void + { + $this->assertHtml5UnmarshallingOnlyInQti22AndAbove( + sprintf( + '<%s>', + $this->namespaceTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + $this->prefixTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION) + ), + Figcaption::QTI_CLASS_NAME_FIGCAPTION + ); + } + + /** + * @throws MarshallerNotFoundException + */ + public function testUnmarshall22(): void + { + $id = 'id'; + $class = 'testclass'; + + $xml = sprintf( + '<%1$s id="%2$s" class="%3$s">text content', + $this->namespaceTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + $id, + $class, + $this->prefixTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION) + ); + + $expected = new Figcaption(null, null, $id, $class); + $expected->setContent(new InlineCollection([new TextRun('text content')])); + + $this->assertUnmarshalling($expected, $xml); + } + + public function testUnmarshall22WithDefaultValues(): void + { + $xml = sprintf( + '<%s>text content', + $this->namespaceTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + $this->prefixTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION) + ); + + $expected = new Figcaption(); + $expected->setContent(new InlineCollection([new TextRun('text content')])); + + $this->assertUnmarshalling($expected, $xml); + } +} diff --git a/test/qtismtest/data/storage/xml/marshalling/Html5FigureMarshallerTest.php b/test/qtismtest/data/storage/xml/marshalling/Html5FigureMarshallerTest.php new file mode 100644 index 000000000..7e5356797 --- /dev/null +++ b/test/qtismtest/data/storage/xml/marshalling/Html5FigureMarshallerTest.php @@ -0,0 +1,135 @@ +assertHtml5MarshallingOnlyInQti22AndAbove(new Figure(), Figure::QTI_CLASS_NAME_FIGURE); + } + + /** + * @throws MarshallerNotFoundException + * @throws MarshallingException + */ + public function testMarshall22(): void + { + $id = 'id'; + $class = 'testclass'; + + $expected = sprintf( + '<%1$s id="%2$s" class="%3$s"><%5$s>text content', + $this->namespaceTag(Figure::QTI_CLASS_NAME_FIGURE), + $id, + $class, + $this->prefixTag(Figure::QTI_CLASS_NAME_FIGURE), + $this->prefixTag(Figcaption::QTI_CLASS_NAME_FIGCAPTION), + ); + + $figcaption = new Figcaption(); + $figcaption->setContent(new InlineCollection([new TextRun('text content')])); + + $object = new Figure(null, null, $id, $class); + $object->setContent(new FlowCollection([$figcaption])); + + $this->assertMarshalling($expected, $object); + } + + /** + * @throws MarshallerNotFoundException + * @throws MarshallingException + */ + public function testMarshall22WithDefaultValues(): void + { + $expected = sprintf( + '<%s/>', + $this->namespaceTag(Figure::QTI_CLASS_NAME_FIGURE), + ); + + $video = new Figure(); + + $this->assertMarshalling($expected, $video); + } + + /** + * @throws MarshallerNotFoundException + */ + public function testUnMarshallerDoesNotExistInQti21(): void + { + $this->assertHtml5UnmarshallingOnlyInQti22AndAbove( + sprintf( + '<%s>', + $this->namespaceTag(Figure::QTI_CLASS_NAME_FIGURE), + $this->prefixTag(Figure::QTI_CLASS_NAME_FIGURE) + ), + Figure::QTI_CLASS_NAME_FIGURE + ); + } + + /** + * @throws MarshallerNotFoundException + */ + public function testUnmarshall22(): void + { + $id = 'id'; + $class = 'testclass'; + + $xml = sprintf( + '<%1$s id="%2$s" class="%3$s">', + $this->namespaceTag(Figure::QTI_CLASS_NAME_FIGURE), + $id, + $class, + $this->prefixTag(Figure::QTI_CLASS_NAME_FIGURE), + ); + + $expected = new Figure(null, null, $id, $class); + + $this->assertUnmarshalling($expected, $xml); + } + + public function testUnmarshall22WithDefaultValues(): void + { + $xml = sprintf( + '<%s>', + $this->namespaceTag(Figure::QTI_CLASS_NAME_FIGURE), + $this->prefixTag(Figure::QTI_CLASS_NAME_FIGURE) + ); + + $expected = new Figure(); + + $this->assertUnmarshalling($expected, $xml); + } +} diff --git a/test/samples/custom/items/2_2/figure_html5.xml b/test/samples/custom/items/2_2/figure_html5.xml new file mode 100644 index 000000000..90455c55d --- /dev/null +++ b/test/samples/custom/items/2_2/figure_html5.xml @@ -0,0 +1,32 @@ + + + + + + + 0 + + + +
+
+ + AWS.jpg + A sample t-shirt size table. + +

 

+

 

+
+
+
+
+ + choice #1 + choice #2 + choice #3 + +
+
+
+ +