diff --git a/.gitattributes b/.gitattributes index 30fa8eb..2aadd08 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,18 @@ -/.distignore export-ignore -/.editorconfig export-ignore -/.env export-ignore -/.github/ export-ignore -/mkdocs.yml export-ignore -/docs/ export-ignore -/tests/ export-ignore -/vendor/ export-ignore -composer.lock export-ignore -phpunit.xml export-ignore -README.md export-ignore -renovate.json export-ignore -test.php export-ignore +/.distignore export-ignore +/.editorconfig export-ignore +/.env export-ignore +/.gitattributes export-ignore +/.github/ export-ignore +/.gitignore export-ignore +/.gitignore export-ignore +/.php-cs-fixer.dist.php export-ignore +/.readthedocs.yaml export-ignore +/docs/ export-ignore +/mkdocs.yml export-ignore +/tests/ export-ignore +/vendor/ export-ignore +composer.lock export-ignore +phpunit.xml export-ignore +README.md export-ignore +renovate.json export-ignore +test.php export-ignore \ No newline at end of file diff --git a/src/ElpParser.php b/src/ElpParser.php index e1f840d..ee3b44f 100644 --- a/src/ElpParser.php +++ b/src/ElpParser.php @@ -154,11 +154,11 @@ protected function parse(): void } // Detect version - if ($zip->locateName('content.xml') !== false) { - $this->version = 2; + if ($zip->locateName('content.xml') !== false && $zip->locateName('index.html') !== false) { + $this->version = 3; $contentFile = 'content.xml'; } elseif ($zip->locateName('contentv3.xml') !== false) { - $this->version = 3; + $this->version = 2; $contentFile = 'contentv3.xml'; } else { $zip->close(); @@ -276,13 +276,13 @@ public function getStrings(): array * @return array Parsed ELP file data */ /** - * Extract metadata from version 2 XML format + * Extract metadata from version 3 XML format * * @param SimpleXMLElement $xml XML document * * @return void */ - protected function extractVersion2Metadata(SimpleXMLElement $xml): void + protected function extractVersion3Metadata(SimpleXMLElement $xml): void { if (isset($xml->odeProperties)) { foreach ($xml->odeProperties->odeProperty as $property) { @@ -374,13 +374,13 @@ public function getLearningResourceType(): string } /** - * Extract metadata from version 3 XML format + * Extract metadata from version 2 XML format * * @param SimpleXMLElement $xml XML document * * @return void */ - protected function extractVersion3Metadata(SimpleXMLElement $xml): void + protected function extractVersion2Metadata(SimpleXMLElement $xml): void { if (!isset($xml->dictionary)) { return; diff --git a/tests/Fixtures/exe3-ipe1_parada2.elp b/tests/Fixtures/exe2-ipe1_parada2.elp similarity index 100% rename from tests/Fixtures/exe3-ipe1_parada2.elp rename to tests/Fixtures/exe2-ipe1_parada2.elp diff --git a/tests/Fixtures/exe3-ipe1_parada3.elp b/tests/Fixtures/exe2-ipe1_parada3.elp similarity index 100% rename from tests/Fixtures/exe3-ipe1_parada3.elp rename to tests/Fixtures/exe2-ipe1_parada3.elp diff --git a/tests/Fixtures/editado-con-2.6-sencillo.elp b/tests/Fixtures/exe26-editado-con-2.6-sencillo.elp similarity index 100% rename from tests/Fixtures/editado-con-2.6-sencillo.elp rename to tests/Fixtures/exe26-editado-con-2.6-sencillo.elp diff --git a/tests/Fixtures/editado-con-2.6-simplificado.elp b/tests/Fixtures/exe26-editado-con-2.6-simplificado.elp similarity index 100% rename from tests/Fixtures/editado-con-2.6-simplificado.elp rename to tests/Fixtures/exe26-editado-con-2.6-simplificado.elp diff --git a/tests/Fixtures/exe3-accessibility-revision.elp b/tests/Fixtures/exe3-accessibility-revision.elp new file mode 100644 index 0000000..237f41f Binary files /dev/null and b/tests/Fixtures/exe3-accessibility-revision.elp differ diff --git a/tests/Fixtures/exe2-parada-2-riesgos-de-la-ruta-itinerario-para-la-empleabilidad-i.elp b/tests/Fixtures/exe3-parada-2-riesgos-de-la-ruta-itinerario-para-la-empleabilidad-i.elp similarity index 100% rename from tests/Fixtures/exe2-parada-2-riesgos-de-la-ruta-itinerario-para-la-empleabilidad-i.elp rename to tests/Fixtures/exe3-parada-2-riesgos-de-la-ruta-itinerario-para-la-empleabilidad-i.elp diff --git a/tests/Unit/ElpParserTest.php b/tests/Unit/ElpParserTest.php index 9906c2d..570c0c1 100644 --- a/tests/Unit/ElpParserTest.php +++ b/tests/Unit/ElpParserTest.php @@ -17,8 +17,8 @@ use Exception; it( - 'can parse a version 2 ELP file', function () { - $elpFile = __DIR__ . '/../Fixtures/exe2-parada-2-riesgos-de-la-ruta-itinerario-para-la-empleabilidad-i.elp'; + 'can parse a version 3 ELP file', function () { + $elpFile = __DIR__ . '/../Fixtures/exe3-accessibility-revision.elp'; // Ensure the test file exists expect(file_exists($elpFile))->toBeTrue('Test ELP file for version 2 not found'); @@ -26,7 +26,37 @@ $parser = ELPParser::fromFile($elpFile); // Check version detection - expect($parser->getVersion())->toBe(2); + expect($parser->getVersion())->toBe(3); + + // Check metadata fields + expect($parser->getTitle())->toBe('Accessibility revision'); + expect($parser->getDescription())->toContain('vfggg'); + expect($parser->getAuthor())->toBe('The eXeLearning Team'); + expect($parser->getLicense())->toBe('propietary license'); + expect($parser->getLearningResourceType())->toBe('guided reading'); + expect($parser->getLanguage())->toBe('en'); + + // Check extracted strings + $strings = $parser->getStrings(); + expect($strings)->toBeArray(); + expect(count($strings))->toBeGreaterThan(0); + + // Optionally, check for some expected content + // expect($strings)->toContain('Some expected text from version 2 file'); + } +); + +it( + 'can parse another version 3 ELP file', function () { + $elpFile = __DIR__ . '/../Fixtures/exe3-parada-2-riesgos-de-la-ruta-itinerario-para-la-empleabilidad-i.elp'; + + // Ensure the test file exists + expect(file_exists($elpFile))->toBeTrue('Test ELP file for version 2 not found'); + + $parser = ELPParser::fromFile($elpFile); + + // Check version detection + expect($parser->getVersion())->toBe(3); // Check metadata fields expect($parser->getTitle())->toBe('Parada 2: Riesgos de la ruta | Itinerario para la empleabilidad I'); @@ -47,8 +77,8 @@ ); it( - 'can parse a version 3 ELP file', function () { - $elpFile = __DIR__ . '/../Fixtures/exe3-ipe1_parada2.elp'; + 'can parse a version 2 ELP file', function () { + $elpFile = __DIR__ . '/../Fixtures/exe2-ipe1_parada2.elp'; // Ensure the test file exists expect(file_exists($elpFile))->toBeTrue('Test ELP file for version 3 not found'); @@ -56,7 +86,7 @@ $parser = ELPParser::fromFile($elpFile); // Check version detection - expect($parser->getVersion())->toBe(3); + expect($parser->getVersion())->toBe(2); // Check metadata fields expect($parser->getTitle())->toBe('Parada 2: Riesgos de la ruta | Itinerario para la empleabilidad I'); @@ -79,7 +109,7 @@ it( 'can extract an ELP file using a temporary directory', function () { - $elpFile = __DIR__ . '/../Fixtures/exe3-ipe1_parada3.elp'; + $elpFile = __DIR__ . '/../Fixtures/exe2-ipe1_parada3.elp'; // Create a unique temporary directory $tempDir = sys_get_temp_dir() . '/elp_extracted_' . uniqid(); @@ -109,7 +139,7 @@ it( 'can parse a version v26 simple ELP file', function () { - $elpFile = __DIR__ . '/../Fixtures/editado-con-2.6-simplificado.elp'; + $elpFile = __DIR__ . '/../Fixtures/exe26-editado-con-2.6-simplificado.elp'; // Ensure the test file exists expect(file_exists($elpFile))->toBeTrue('Test ELP file for version 3 not found'); @@ -117,7 +147,7 @@ $parser = ELPParser::fromFile($elpFile); // Check version detection - expect($parser->getVersion())->toBe(3); + expect($parser->getVersion())->toBe(2); // Check metadata fields expect($parser->getTitle())->toBe('Accessibility revision'); @@ -140,7 +170,7 @@ it( 'can parse a version v26 more simple ELP file', function () { - $elpFile = __DIR__ . '/../Fixtures/editado-con-2.6-sencillo.elp'; + $elpFile = __DIR__ . '/../Fixtures/exe26-editado-con-2.6-sencillo.elp'; // Ensure the test file exists expect(file_exists($elpFile))->toBeTrue('Test ELP file for version 3 not found'); @@ -148,7 +178,7 @@ $parser = ELPParser::fromFile($elpFile); // Check version detection - expect($parser->getVersion())->toBe(3); + expect($parser->getVersion())->toBe(2); // Check metadata fields expect($parser->getTitle())->toBe('Contenido para pruebas de eXe 3');