diff --git a/.gitattributes b/.gitattributes index 64f6ef3233c4a30b9221ecc196751be3df5108b8..8ace69d46d4484dd48148568b1663d978e5b30cb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3757,6 +3757,7 @@ tests/library/Class/CompositeBuilderTreeTestCase.php -text tests/library/Class/DecodageUnimarcTest.php -text tests/library/Class/DynamicUserGroupTest.php -text tests/library/Class/EADTest.php -text +tests/library/Class/FRBR/LinkTest.php -text tests/library/Class/File/MimeTest.php -text tests/library/Class/FileWriterTest.php -text tests/library/Class/Folder/ManagerTest.php -text diff --git a/library/Class/FRBR/Link.php b/library/Class/FRBR/Link.php index 4993689e5f7ac548e7583c704802b934fa0422eb..676a78d440b57e444870da484764cf1dfcdcf6d9 100644 --- a/library/Class/FRBR/Link.php +++ b/library/Class/FRBR/Link.php @@ -142,10 +142,19 @@ class Class_FRBR_Link extends Storm_Model_Abstract { public function getEntityFor($type) { if (self::TYPE_EXTERNAL == $this->{'get'. ucfirst($type) . 'Type'}()) return; - + + if (!self::TYPE_NOTICE) + return; + $attribute = '_' . $type .'_entity'; if (!$this->$attribute) { - $key = $this->_extractKeyFromUrl($this->{'get'. ucfirst($type)}()); + + try { + $key = $this->_extractKeyFromUrl($this->{'get'. ucfirst($type)}()); + } catch(Zend_Uri_Exception $e) { + return $this->$attribute = null; + } + $this->$attribute = Class_Notice::getLoader()->getNoticeByClefAlpha($key); } return $this->$attribute; diff --git a/tests/library/Class/FRBR/LinkTest.php b/tests/library/Class/FRBR/LinkTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8ae51e17504e037de2a464101caeece6bebfb32c --- /dev/null +++ b/tests/library/Class/FRBR/LinkTest.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class FRBR_LinkWrongAttributesTest extends Storm_Test_ModelTestCase { + public function setUp() { + parent::setUp(); + + $this->link = Class_FRBR_Link::newInstanceWithId(34) + ->setSource('zork') + ->setTarget('grouik') + ->setSourceType(Class_FRBR_Link::TYPE_NOTICE) + ->setTargetType('http://localhost/notice/view/clef/TINTIN') + ->setLinkType(Class_FRBR_LinkType::newInstanceWithId(4) + ->setLibelle('synonyme') + ->setFromSource('est un synonyme de') + ->setFromTarget('est un synonyme de')); + + } + + + /** @test */ + public function getSourceNoticeShouldReturnNullWithInvalidScheme() { + $this->assertEquals(null, $this->link->getSourceNotice()); + } + + + /** @test */ + public function getTargetNoticeShouldReturnNullWithInvalidType() { + $this->assertEquals(null, $this->link->getTargetNotice()); + } +} + +?> \ No newline at end of file