From db2ad120b2c408792ffd6da89291bfd3cf5b9bdd Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 16 Dec 2013 17:29:25 +0100 Subject: [PATCH] fix test suite reimplementing url updating trest --- core/lib/Thelia/Action/BaseAction.php | 2 ++ core/lib/Thelia/Core/Event/UpdateSeoEvent.php | 20 ++++++++++++++++ core/lib/Thelia/Tests/Action/FolderTest.php | 24 +++++++++++++++++++ .../Tests/Action/RewrittenUrlTestTrait.php | 10 ++++---- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index b81864a2d..1f04e12f6 100755 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -109,6 +109,8 @@ class BaseAction throw new FormValidationException($e->getMessage(), $e->getCode()); } + $event->setObject($object); + return $object; } } diff --git a/core/lib/Thelia/Core/Event/UpdateSeoEvent.php b/core/lib/Thelia/Core/Event/UpdateSeoEvent.php index 0c81a3469..caf46c1aa 100644 --- a/core/lib/Thelia/Core/Event/UpdateSeoEvent.php +++ b/core/lib/Thelia/Core/Event/UpdateSeoEvent.php @@ -165,4 +165,24 @@ class UpdateSeoEvent extends ActionEvent return $this; } + + /** + * @param mixed $object + */ + public function setObject($object) + { + $this->object = $object; + + return $this; + } + + /** + * @return mixed + */ + public function getObject() + { + return $this->object; + } + + } diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index 7fec70dc4..09307edd5 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -30,6 +30,7 @@ use Thelia\Core\Event\Folder\FolderDeleteEvent; use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent; use Thelia\Core\Event\Folder\FolderUpdateEvent; use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\UpdateSeoEvent; use Thelia\Model\FolderQuery; use Thelia\Tests\TestCaseWithURLToolSetup; @@ -62,6 +63,29 @@ class FolderTest extends TestCaseWithURLToolSetup return $event; } + public function getUpdateSeoEvent(&$folder) + { + if(!$folder instanceof \Thelia\Model\Folder) { + $folder = $this->getRandomFolder(); + } + + $event = new UpdateSeoEvent($folder->getId()); + + $event + ->setLocale($folder->getLocale()) + ->setMetaTitle($folder->getMetaTitle()) + ->setMetaDescription($folder->getMetaDescription()) + ->setMetaKeywords($folder->getMetaKeywords()); + + return $event; + } + + public function processUpdateSeoAction($event) + { + $contentAction = new Folder($this->getContainer()); + return $contentAction->updateSeo($event); + } + public function processUpdateAction($event) { $contentAction = new Folder($this->getContainer()); diff --git a/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php b/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php index 34719fe3e..e5899dbc5 100644 --- a/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php +++ b/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php @@ -18,7 +18,9 @@ use Thelia\Tools\URL; trait RewrittenUrlTestTrait { abstract public function getUpdateEvent(&$object); + abstract public function getUpdateSeoEvent(&$object); abstract public function processUpdateAction($event); + abstract public function processUpdateSeoAction($event); /** * @expectedException \Thelia\Form\Exception\FormValidationException @@ -27,7 +29,7 @@ trait RewrittenUrlTestTrait public function testUpdateExistingUrl() { $object = null; - $event = $this->getUpdateEvent($object); + $event = $this->getUpdateSeoEvent($object); /* get an existing url */ $existingUrl = RewritingUrlQuery::create() @@ -42,13 +44,13 @@ trait RewrittenUrlTestTrait $event->setUrl($existingUrl->getUrl()); - $this->processUpdateAction($event); + $this->processUpdateSeoAction($event); } public function testUpdateUrl() { $object = null; - $event = $this->getUpdateEvent($object); + $event = $this->getUpdateSeoEvent($object); $currentUrl = $object->getRewrittenUrl($object->getLocale()); @@ -70,7 +72,7 @@ trait RewrittenUrlTestTrait $event->setUrl($newUrl); - $updatedObject = $this->processUpdateAction($event); + $updatedObject = $this->processUpdateSeoAction($event); /* new URL is updated */ $this->assertEquals($newUrl, $updatedObject->getRewrittenUrl($object->getLocale()));