* @package taoQtiTest */ class QtiTestConverterTest extends GenerisPhpUnitTestRunner { /** * Data provider * @return array[] the parameters */ public function dataProvider() { $dataPath = __DIR__ . '/data/'; return [ [ $dataPath . 'qtitest.xml', json_encode(json_decode(file_get_contents($dataPath . 'qtitest.json'))) ], [ $dataPath . 'branching/test.xml', json_encode(json_decode(file_get_contents($dataPath . 'branching/test.json'))) ] ]; } /** * Test {@link taoQtiTest_models_classes_QtiTestConverter::toJson} * @dataProvider dataProvider * * @param string $testPath * the path of the QTI test to convert * @param string $expected * the expected json result */ public function testToJson($testPath, $expected) { $doc = new XmlDocument('2.1'); try { $doc->load($testPath); } catch (StorageException $e) { $this->fail($e->getMessage()); } $converter = new taoQtiTest_models_classes_QtiTestConverter($doc); $result = $converter->toJson(); $this->assertEquals($expected, $result); } /** * 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([ '/ {2,}/', '/|\t|(?:\r?\n[ \t]*)+/s' ], [ ' ', '' ], $doc->saveToString()) ; $expected = preg_replace([ '/ {2,}/', '/|\t|(?:\r?\n[ \t]*)+/s' ], [ ' ', '' ], file_get_contents($testPath)) ; $this->assertEquals($result, $expected); } public function testLookupClass() { $class = new ReflectionClass(taoQtiTest_models_classes_QtiTestConverter::class); $lookupClassMethod = $class->getMethod('lookupClass'); $lookupClassMethod->setAccessible(true); $doc = new XmlDocument('2.1'); $converter = new taoQtiTest_models_classes_QtiTestConverter($doc); $result = $lookupClassMethod->invoke($converter, 'or'); $this->assertEquals($result, 'qtism\data\expressions\operators\OrOperator'); $result = $lookupClassMethod->invoke($converter, 'lt'); $this->assertEquals($result, 'qtism\data\expressions\operators\Lt'); } }