fix test suite reimplementing url updating trest

This commit is contained in:
Manuel Raynaud
2013-12-16 17:29:25 +01:00
parent 0e9ac181e5
commit db2ad120b2
4 changed files with 52 additions and 4 deletions

View File

@@ -109,6 +109,8 @@ class BaseAction
throw new FormValidationException($e->getMessage(), $e->getCode());
}
$event->setObject($object);
return $object;
}
}

View File

@@ -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;
}
}

View File

@@ -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());

View File

@@ -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()));