remove container from administrator listener and create test for this

event. #198
This commit is contained in:
Manuel Raynaud
2014-01-31 12:02:45 +01:00
parent bf49aa24dd
commit 58ae3bb619
5 changed files with 86 additions and 5 deletions

View File

@@ -30,7 +30,7 @@ use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Admin as AdminModel; use Thelia\Model\Admin as AdminModel;
use Thelia\Model\AdminQuery; use Thelia\Model\AdminQuery;
class Administrator extends BaseAction implements EventSubscriberInterface class Administrator implements EventSubscriberInterface
{ {
/** /**
* @param AdministratorEvent $event * @param AdministratorEvent $event
@@ -40,7 +40,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface
$administrator = new AdminModel(); $administrator = new AdminModel();
$administrator $administrator
->setDispatcher($this->getDispatcher()) ->setDispatcher($event->getDispatcher())
->setFirstname($event->getFirstname()) ->setFirstname($event->getFirstname())
->setLastname($event->getLastname()) ->setLastname($event->getLastname())
->setLogin($event->getLogin()) ->setLogin($event->getLogin())
@@ -62,7 +62,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface
if (null !== $administrator = AdminQuery::create()->findPk($event->getId())) { if (null !== $administrator = AdminQuery::create()->findPk($event->getId())) {
$administrator $administrator
->setDispatcher($this->getDispatcher()) ->setDispatcher($event->getDispatcher())
->setFirstname($event->getFirstname()) ->setFirstname($event->getFirstname())
->setLastname($event->getLastname()) ->setLastname($event->getLastname())
->setLogin($event->getLogin()) ->setLogin($event->getLogin())

View File

@@ -155,7 +155,6 @@
</service> </service>
<service id="thelia.action.administrator" class="Thelia\Action\Administrator"> <service id="thelia.action.administrator" class="Thelia\Action\Administrator">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </service>

View File

@@ -62,6 +62,8 @@ class AdministratorEvent extends ActionEvent
public function setId($id) public function setId($id)
{ {
$this->id = $id; $this->id = $id;
return $this;
} }
public function getId() public function getId()
@@ -72,6 +74,8 @@ class AdministratorEvent extends ActionEvent
public function setFirstname($firstname) public function setFirstname($firstname)
{ {
$this->firstname = $firstname; $this->firstname = $firstname;
return $this;
} }
public function getFirstname() public function getFirstname()
@@ -82,6 +86,8 @@ class AdministratorEvent extends ActionEvent
public function setLastname($lastname) public function setLastname($lastname)
{ {
$this->lastname = $lastname; $this->lastname = $lastname;
return $this;
} }
public function getLastname() public function getLastname()
@@ -92,6 +98,8 @@ class AdministratorEvent extends ActionEvent
public function setLogin($login) public function setLogin($login)
{ {
$this->login = $login; $this->login = $login;
return $this;
} }
public function getLogin() public function getLogin()
@@ -102,6 +110,8 @@ class AdministratorEvent extends ActionEvent
public function setPassword($password) public function setPassword($password)
{ {
$this->password = $password; $this->password = $password;
return $this;
} }
public function getPassword() public function getPassword()
@@ -112,6 +122,8 @@ class AdministratorEvent extends ActionEvent
public function setProfile($profile) public function setProfile($profile)
{ {
$this->profile = $profile; $this->profile = $profile;
return $this;
} }
public function getProfile() public function getProfile()

View File

@@ -109,7 +109,7 @@ class AddressTest extends \PHPUnit_Framework_TestCase
$addressEvent->setAddress($address); $addressEvent->setAddress($address);
$addressEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); $addressEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$actionAddress = new Address($this->getContainer()); $actionAddress = new Address();
$actionAddress->update($addressEvent); $actionAddress->update($addressEvent);
$updatedAddress = $addressEvent->getAddress(); $updatedAddress = $addressEvent->getAddress();

View File

@@ -0,0 +1,70 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program 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 General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Action;
use Thelia\Action\Administrator;
use Thelia\Core\Event\Administrator\AdministratorEvent;
use Thelia\Model\LangQuery;
/**
* Class AdministratorTest
* @package Thelia\Tests\Action
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AdministratorTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$login = 'thelia'.uniqid();
$locale = LangQuery::create()->findOne()->getLocale();
$adminEvent = new AdministratorEvent();
$adminEvent
->setFirstname('thelia')
->setLastname('thelia')
->setLogin($login)
->setPassword('azerty')
->setLocale($locale)
->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"))
;
$admin = new Administrator();
$admin->create($adminEvent);
$createdAdmin = $adminEvent->getAdministrator();
$this->assertInstanceOf("Thelia\Model\Admin", $createdAdmin);
$this->assertFalse($createdAdmin->isNew());
$this->assertEquals($adminEvent->getFirstname(), $createdAdmin->getFirstname());
$this->assertEquals($adminEvent->getLastname(), $createdAdmin->getLastname());
$this->assertEquals($adminEvent->getLogin(), $createdAdmin->getLogin());
$this->assertEquals($adminEvent->getLocale(), $createdAdmin->getLocale());
$this->assertEquals($adminEvent->getProfile(), $createdAdmin->getProfileId());
$this->assertTrue(password_verify($adminEvent->getPassword(), $createdAdmin->getPassword()));
}
}