remove container from administrator listener and create test for this
event. #198
This commit is contained in:
@@ -30,7 +30,7 @@ use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Admin as AdminModel;
|
||||
use Thelia\Model\AdminQuery;
|
||||
|
||||
class Administrator extends BaseAction implements EventSubscriberInterface
|
||||
class Administrator implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @param AdministratorEvent $event
|
||||
@@ -40,7 +40,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface
|
||||
$administrator = new AdminModel();
|
||||
|
||||
$administrator
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setDispatcher($event->getDispatcher())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setLogin($event->getLogin())
|
||||
@@ -62,7 +62,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface
|
||||
if (null !== $administrator = AdminQuery::create()->findPk($event->getId())) {
|
||||
|
||||
$administrator
|
||||
->setDispatcher($this->getDispatcher())
|
||||
->setDispatcher($event->getDispatcher())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setLogin($event->getLogin())
|
||||
|
||||
@@ -155,7 +155,6 @@
|
||||
</service>
|
||||
|
||||
<service id="thelia.action.administrator" class="Thelia\Action\Administrator">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ class AdministratorEvent extends ActionEvent
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
@@ -72,6 +74,8 @@ class AdministratorEvent extends ActionEvent
|
||||
public function setFirstname($firstname)
|
||||
{
|
||||
$this->firstname = $firstname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstname()
|
||||
@@ -82,6 +86,8 @@ class AdministratorEvent extends ActionEvent
|
||||
public function setLastname($lastname)
|
||||
{
|
||||
$this->lastname = $lastname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastname()
|
||||
@@ -92,6 +98,8 @@ class AdministratorEvent extends ActionEvent
|
||||
public function setLogin($login)
|
||||
{
|
||||
$this->login = $login;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLogin()
|
||||
@@ -102,6 +110,8 @@ class AdministratorEvent extends ActionEvent
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword()
|
||||
@@ -112,6 +122,8 @@ class AdministratorEvent extends ActionEvent
|
||||
public function setProfile($profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProfile()
|
||||
|
||||
@@ -109,7 +109,7 @@ class AddressTest extends \PHPUnit_Framework_TestCase
|
||||
$addressEvent->setAddress($address);
|
||||
$addressEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
|
||||
|
||||
$actionAddress = new Address($this->getContainer());
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->update($addressEvent);
|
||||
|
||||
$updatedAddress = $addressEvent->getAddress();
|
||||
|
||||
70
core/lib/Thelia/Tests/Action/AdministratorTest.php
Normal file
70
core/lib/Thelia/Tests/Action/AdministratorTest.php
Normal 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()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user