Skip to content

Commit

Permalink
Merge pull request #331 from oat-sa/feature/TR-4502/add-ruby-tags_legacy
Browse files Browse the repository at this point in the history
Legacy:: Add <ruby> tag to marshaling and unmarshaling
  • Loading branch information
kilatib authored Sep 30, 2022
2 parents b3ba786 + f02ab7f commit 0d7c8a3
Show file tree
Hide file tree
Showing 19 changed files with 776 additions and 54 deletions.
35 changes: 35 additions & 0 deletions qtism/data/content/xhtml/html5/Rb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2022 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace qtism\data\content\xhtml\html5;

use qtism\data\content\FlowStatic;

class Rb extends Html5LayoutElement implements FlowStatic
{
public const QTI_CLASS_NAME = 'rb';

public function getQtiClassName()
{
return self::QTI_CLASS_NAME;
}
}
35 changes: 35 additions & 0 deletions qtism/data/content/xhtml/html5/Rp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2022 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace qtism\data\content\xhtml\html5;

use qtism\data\content\FlowStatic;

class Rp extends Html5LayoutElement implements FlowStatic
{
public const QTI_CLASS_NAME = 'rp';

public function getQtiClassName()
{
return self::QTI_CLASS_NAME;
}
}
35 changes: 35 additions & 0 deletions qtism/data/content/xhtml/html5/Rt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2022 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace qtism\data\content\xhtml\html5;

use qtism\data\content\FlowStatic;

class Rt extends Html5LayoutElement implements FlowStatic
{
public const QTI_CLASS_NAME = 'rt';

public function getQtiClassName()
{
return self::QTI_CLASS_NAME;
}
}
35 changes: 35 additions & 0 deletions qtism/data/content/xhtml/html5/Ruby.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2022 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace qtism\data\content\xhtml\html5;

use qtism\data\content\FlowStatic;

class Ruby extends Html5LayoutElement implements FlowStatic
{
public const QTI_CLASS_NAME = 'ruby';

public function getQtiClassName()
{
return self::QTI_CLASS_NAME;
}
}
20 changes: 20 additions & 0 deletions qtism/data/storage/xml/marshalling/ContentMarshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
use qtism\data\content\TemplateInline;
use qtism\data\content\xhtml\html5\Figcaption;
use qtism\data\content\xhtml\html5\Figure;
use qtism\data\content\xhtml\html5\Rb;
use qtism\data\content\xhtml\html5\Rp;
use qtism\data\content\xhtml\html5\Rt;
use qtism\data\content\xhtml\html5\Ruby;
use qtism\data\content\xhtml\lists\Dl;
use qtism\data\content\xhtml\lists\DlElement;
use qtism\data\content\xhtml\lists\Li;
Expand Down Expand Up @@ -141,6 +145,10 @@ public function __construct($version)
'i',
'kbd',
'q',
Ruby::QTI_CLASS_NAME,
Rb::QTI_CLASS_NAME,
Rp::QTI_CLASS_NAME,
Rt::QTI_CLASS_NAME,
'samp',
'small',
'span',
Expand Down Expand Up @@ -292,6 +300,14 @@ protected function getChildrenComponents(QtiComponent $component)
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Figcaption) {
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Ruby) {
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Rb) {
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Rp) {
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Rt) {
return $component->getContent()->getArrayCopy();
}
}

Expand Down Expand Up @@ -338,6 +354,10 @@ 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 === Ruby::QTI_CLASS_NAME) {
return $this->getChildElementsByTagName($element, [Rb::QTI_CLASS_NAME, Rp::QTI_CLASS_NAME, Rt::QTI_CLASS_NAME]);
} elseif ($localName === 'gapImg') {
return $this->getChildElementsByTagName($element, 'object');
} elseif ($element->localName === 'infoControl') {
Expand Down
2 changes: 1 addition & 1 deletion qtism/data/storage/xml/marshalling/MarshallerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public function createMarshaller($object, array $args = [])
}
} catch (ReflectionException $e) {
$msg = "No marshaller implementation could be found for component '${qtiClassName}'.";
throw new RuntimeException($msg, 0, $e);
throw new MarshallerNotFoundException($msg, 0, $e);
}

$marshaller = $this->instantiateMarshaller($class, $args);
Expand Down
8 changes: 8 additions & 0 deletions qtism/data/storage/xml/marshalling/Qti22MarshallerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
use qtism\common\utils\Reflection;
use qtism\data\content\xhtml\html5\Figcaption;
use qtism\data\content\xhtml\html5\Figure;
use qtism\data\content\xhtml\html5\Rb;
use qtism\data\content\xhtml\html5\Rp;
use qtism\data\content\xhtml\html5\Rt;
use qtism\data\content\xhtml\html5\Ruby;
use ReflectionClass;

/**
Expand All @@ -42,6 +46,10 @@ public function __construct()
parent::__construct();
$this->addMappingEntry(Figure::QTI_CLASS_NAME_FIGURE, Html5ContentMarshaller::class);
$this->addMappingEntry(Figcaption::QTI_CLASS_NAME_FIGCAPTION, Html5ContentMarshaller::class);
$this->addMappingEntry(Ruby::QTI_CLASS_NAME, Html5ContentMarshaller::class);
$this->addMappingEntry(Rb::QTI_CLASS_NAME, Html5ContentMarshaller::class);
$this->addMappingEntry(Rp::QTI_CLASS_NAME, Html5ContentMarshaller::class);
$this->addMappingEntry(Rt::QTI_CLASS_NAME, Html5ContentMarshaller::class);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions qtism/data/storage/xml/marshalling/RecursiveMarshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,16 @@ protected function marshall(QtiComponent $component)
// Hierarchical node, 1st pass.
$this->mark($node);
$this->pushTrail($node); // repush for a further pass.
$children = array_reverse($this->getChildrenComponents($node)); // next nodes to explore.
$childrenComponentList = $this->getChildrenComponents($node) ?? [];
$children = array_reverse($childrenComponentList); // next nodes to explore.

foreach ($children as $c) {
$this->pushTrail($c);
}
} elseif ($this->isMarked($node)) {
} elseif ($this->isMarked($node) && !$node instanceof DOMElement) {
// Push the result on the trail.
$finals = $this->emptyFinal(count($this->getChildrenComponents($node)));
$childrenComponentList = $this->getChildrenComponents($node) ?? [];
$finals = $this->emptyFinal(count($childrenComponentList));
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$element = $marshaller->marshallChildrenKnown($node, $finals);
$this->pushProcessed($element);
Expand Down
11 changes: 11 additions & 0 deletions qtism/runtime/rendering/markup/xhtml/XhtmlRenderingEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

namespace qtism\runtime\rendering\markup\xhtml;

use OAT\Library\QtiItemJsonCompilation\Rt;
use qtism\data\content\xhtml\html5\Figcaption;
use qtism\data\content\xhtml\html5\Figure;
use qtism\data\content\xhtml\html5\Rb;
use qtism\data\content\xhtml\html5\Rp;
use qtism\data\content\xhtml\html5\Ruby;
use qtism\runtime\rendering\markup\AbstractMarkupRenderingEngine;

/**
Expand Down Expand Up @@ -154,6 +160,11 @@ public function __construct()
$this->registerRenderer('positionObjectStage', new PositionObjectStageRenderer());
$this->registerRenderer('assessmentItem', new AssessmentItemRenderer());
$this->registerRenderer('printedVariable', new PrintedVariableRenderer());
$this->registerRenderer(Figure::QTI_CLASS_NAME_FIGURE, new ExternalQtiComponentRenderer());
$this->registerRenderer(Figcaption::QTI_CLASS_NAME_FIGCAPTION, new ExternalQtiComponentRenderer());
$this->registerRenderer(Ruby::QTI_CLASS_NAME, new ExternalQtiComponentRenderer());
$this->registerRenderer(Rb::QTI_CLASS_NAME, new ExternalQtiComponentRenderer());
$this->registerRenderer(Rp::QTI_CLASS_NAME, new ExternalQtiComponentRenderer());

// External QTI Components.
$this->registerRenderer('math', new MathRenderer());
Expand Down
16 changes: 5 additions & 11 deletions test/qtismtest/data/content/xhtml/html5/Html5LayoutElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function testCreateWithValues(): void
$lang = 'en';
$label = 'This is the label.';

$subject = new FakeHtml5LayoutElement($title, $role, $id, $class, $lang, $label);
$subject = $this->getMockForAbstractClass(Html5LayoutElement::class, [
$title, $role, $id, $class, $lang, $label
]);

self::assertSame($title, $subject->getTitle());
self::assertEquals(Role::getConstantByName($role), $subject->getRole());
Expand All @@ -34,7 +36,7 @@ public function testCreateWithValues(): void

public function testCreateWithDefaultValues(): void
{
$subject = new FakeHtml5LayoutElement();
$subject = $this->getMockForAbstractClass(Html5LayoutElement::class);

self::assertSame('', $subject->getTitle());
self::assertSame('', $subject->getId());
Expand All @@ -46,7 +48,7 @@ public function testCreateWithDefaultValues(): void

public function testSetContent(): void
{
$subject = new FakeHtml5LayoutElement();
$subject = $this->getMockForAbstractClass(Html5LayoutElement::class);
$content = new FlowCollection(
[
new P(),
Expand All @@ -61,11 +63,3 @@ public function testSetContent(): void
self::assertEquals($content, $subject->getComponents());
}
}

class FakeHtml5LayoutElement extends Html5LayoutElement
{
public function getQtiClassName(): string
{
return '';
}
}
57 changes: 57 additions & 0 deletions test/qtismtest/data/content/xhtml/html5/RbTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2022 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace qtismtest\data\content\xhtml\html5;

use qtism\data\content\xhtml\html5\Rb;
use qtismtest\QtiSmTestCase;

class RbTest extends QtiSmTestCase
{
public const SUBJECT_QTI_CLASS = 'rb';

public function testCreateWithValues(): void
{
$id = 'testid';
$class = 'test_class';

$subject = new Rb(null, null, $id, $class);

self::assertEquals($id, $subject->getId());
self::assertEquals($class, $subject->getClass());
}

public function testCreateWithDefaultValues(): void
{
$subject = new Rb();

self::assertEquals('', $subject->getId());
self::assertEquals('', $subject->getClass());
}

public function testGetQtiClassName(): void
{
$subject = new Rb();

self::assertEquals(self::SUBJECT_QTI_CLASS, $subject->getQtiClassName());
}
}
Loading

0 comments on commit 0d7c8a3

Please sign in to comment.