Skip to content

Commit

Permalink
Merge pull request #10 from miqwit/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
miqwit authored Oct 27, 2021
2 parents 9e9759f + 4a3f525 commit 84545ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/Controller/ErnParserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ private function instanciateClass($class_name) {
if ($class_name === "\DateInterval") {
// For DateInterval can't instanciate with null
return new DateInterval("PT0M0S"); // will be erased
} else if ($class_name === "\DedexBundle\Entity\Ern382\EventDateTimeType") {
return new \DedexBundle\Entity\Ern382\EventDateTimeType(new \DateTime()); // TODO
}

return $this->instanciateTypeFromDoc($class_name, '__construct', null);
return new $class_name(null);
}

/**
Expand Down Expand Up @@ -437,7 +439,7 @@ private function setCurrentElement($value) {
if (!empty($this->lastElement) && $this->lastElement[0] === $elem && $this->lastElement[1] === $tag) {
$value = $this->lastElement[2] . $value;
}
$func_name = $this->getValidFunctionName("set", $tag, $elem);
[$func_name, $elem] = $this->getValidFunctionName("set", $tag, $elem);

// It's possible we're trying to set a text but it's expecting an
// object (where text should be placed in value).
Expand Down Expand Up @@ -469,7 +471,7 @@ private function getValidFunctionName($prefix, $tag, $value = null) {

// If type is complex, always start at previous than end,
// as end will be itself
if ($value != null && !in_array(get_class($value), ["string", "int", "bool", "float", "mixed"])) {
if ($value != null && !$this->set_to_parent && !in_array(get_class($value), ["string", "int", "bool", "float", "mixed"])) {
$elem = prev($this->pile);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Simplifiers/SimpleTrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ public function getFileName() {
* @return string Concatenation of path and name, as we would normally use this
*/
public function getFullPath() {
return empty($this->getFilePath()) ? $this->getFileName() : $this->getFilePath() . DIRECTORY_SEPARATOR . $this->getFileName();
if (empty($this->getFilePath())) {
return $this->getFileName();
}

$ds = DIRECTORY_SEPARATOR;
return trim(preg_replace('#('.$ds.'{2,})#', $ds, $this->getFilePath() . DIRECTORY_SEPARATOR . $this->getFileName()), $ds);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Controller/ParserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ public function testSample016Utf8Artist() {
/* @var $resource_three \DedexBundle\Entity\Ern382\SoundRecordingType */
$resource_three = $ddex->getResourceList()->getSoundRecording()[3];
$this->assertEquals("Šumadijsko lagano kolo", $resource_three->getReferenceTitle()->getTitleText());


}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Simplifiers/SimplifiersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ public function testSimpleAlbum() {
// Track deal
$this->assertContains("PayAsYouGoModel", $track->getDeal()->getCommercialModelTypes());
}

public function testResourcePath() {
$parser = new ErnParserController();
$ern = $parser->parse("tests/samples/016_utf8_artists.xml");

$album = new SimpleAlbum($ern);
$this->assertEquals("resources/763331950658_01_01.mp3", $album->getTracksPerCd()[1][1]->getFullPath());
}
}

0 comments on commit 84545ad

Please sign in to comment.