diff --git a/src/Controller/ErnParserController.php b/src/Controller/ErnParserController.php index fdca0f4..94faa4d 100644 --- a/src/Controller/ErnParserController.php +++ b/src/Controller/ErnParserController.php @@ -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); } /** @@ -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). @@ -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); } diff --git a/src/Simplifiers/SimpleTrack.php b/src/Simplifiers/SimpleTrack.php index 07bfd7c..a0805a2 100644 --- a/src/Simplifiers/SimpleTrack.php +++ b/src/Simplifiers/SimpleTrack.php @@ -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); } /** diff --git a/tests/Controller/ParserControllerTest.php b/tests/Controller/ParserControllerTest.php index 87469ae..465ccd5 100644 --- a/tests/Controller/ParserControllerTest.php +++ b/tests/Controller/ParserControllerTest.php @@ -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()); - - } /** diff --git a/tests/Simplifiers/SimplifiersTest.php b/tests/Simplifiers/SimplifiersTest.php index aa6f6b4..a0b3a67 100644 --- a/tests/Simplifiers/SimplifiersTest.php +++ b/tests/Simplifiers/SimplifiersTest.php @@ -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()); + } }