diff --git a/library/Class/FRBR/Link.php b/library/Class/FRBR/Link.php index 5ec13109d31a00a58b4302edb86d31213356cdd3..54309276c1292950328699fd1efead23883a4068 100644 --- a/library/Class/FRBR/Link.php +++ b/library/Class/FRBR/Link.php @@ -49,6 +49,16 @@ class Class_FRBR_Link extends Storm_Model_Abstract { ->validateAttribute('source', 'Zend_Validate_NotEmpty', $this->_('Un libellé objet A est requis')) ->validateAttribute('target', 'Zend_Validate_NotEmpty', $this->_('Un libellé objet B est requis')); } + + + public function beforeSave() { + parent::beforeSave(); + if (false === strpos($this->getSource(), '/clef/')) + return; + + $parts = explode('/', $this->getSource()); + $this->setSource($parts[array_search('clef', $parts) + 1]); + } } ?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php b/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php index 46a99083bf712dc753b25c7e96b9cb291777fe02..58d4479b9ce30b5f51db808f5a02c5654bfa5352 100644 --- a/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php +++ b/tests/application/modules/admin/controllers/FrbrLinkControllerTest.php @@ -133,8 +133,7 @@ class Admin_FrbrLinkControllerEditSuiteTest extends Admin_FrbrLinkControllerTest } - -class Admin_FrbrLinkControllerEditSuiteValidPostTest extends Admin_FrbrLinkControllerTestCase { +abstract class Admin_FrbrLinkControllerEditSuiteValidPostTestCase extends Admin_FrbrLinkControllerTestCase { public function setUp() { parent::setUp(); @@ -145,10 +144,6 @@ class Admin_FrbrLinkControllerEditSuiteValidPostTest extends Admin_FrbrLinkContr Storm_Test_ObjectWrapper::onLoaderOfModel('Class_FRBR_LinkType') ->whenCalled('getComboList') ->answers([3 => 'Suite']); - - $this->postDispatch('/admin/frbr-link/edit/id/2', - ['type_id' => 3, 'source' => 'TOTOALAPLAGE', 'target' => 'TOTOFAITDUTUBA'], - true); } @@ -162,4 +157,38 @@ class Admin_FrbrLinkControllerEditSuiteValidPostTest extends Admin_FrbrLinkContr public function shouldRedirect() { $this->assertRedirect(); } +} + + + +class Admin_FrbrLinkControllerEditSuiteValidPostTest extends Admin_FrbrLinkControllerEditSuiteValidPostTestCase { + public function setUp() { + parent::setUp(); + + $this->postDispatch('/admin/frbr-link/edit/id/2', + ['type_id' => 3, 'source' => 'TOTOALAPLAGE', 'target' => 'TOTOFAITDUTUBA'], + true); + } +} + + + +class Admin_FrbrLinkControllerEditSuiteValidWithFullURLPostTest extends Admin_FrbrLinkControllerEditSuiteValidPostTestCase { + public function setUp() { + parent::setUp(); + + $this->postDispatch('/admin/frbr-link/edit/id/2', + ['type_id' => 3, + 'source' => 'http://localhost/afi-opac3-ce/recherche/viewnotice/clef/LES1000MOTSDELINFO-POURMIEUXCOMPRENDREE-COMBRESE--GALLIMARDJEUNESSE-2003-1/type_doc/1/id/44275', + 'target' => 'TOTOFAITDUTUBA'], + true); + } + + + /** @test */ + public function sourceShouldContainOnlyKey() { + $model = Class_FRBR_Link::find(2); + $this->assertEquals('LES1000MOTSDELINFO-POURMIEUXCOMPRENDREE-COMBRESE--GALLIMARDJEUNESSE-2003-1', + $model->getSource()); + } } \ No newline at end of file