Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions src/ElpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Binary file added tests/Fixtures/exe3-accessibility-revision.elp
Binary file not shown.
52 changes: 41 additions & 11 deletions tests/Unit/ElpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,46 @@
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');

$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');
Expand All @@ -47,16 +77,16 @@
);

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');

$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');
Expand All @@ -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();
Expand Down Expand Up @@ -109,15 +139,15 @@

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');

$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');
Expand All @@ -140,15 +170,15 @@

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');

$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');
Expand Down