create profile test suite
This commit is contained in:
@@ -64,6 +64,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
@@ -74,6 +76,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode()
|
||||
@@ -84,6 +88,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setChapo($chapo)
|
||||
{
|
||||
$this->chapo = $chapo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChapo()
|
||||
@@ -94,6 +100,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
@@ -104,6 +112,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
@@ -114,6 +124,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setPostscriptum($postscriptum)
|
||||
{
|
||||
$this->postscriptum = $postscriptum;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPostscriptum()
|
||||
@@ -124,6 +136,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
@@ -134,6 +148,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setResourceAccess($resourceAccess)
|
||||
{
|
||||
$this->resourceAccess = $resourceAccess;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResourceAccess()
|
||||
@@ -144,6 +160,8 @@ class ProfileEvent extends ActionEvent
|
||||
public function setModuleAccess($moduleAccess)
|
||||
{
|
||||
$this->moduleAccess = $moduleAccess;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModuleAccess()
|
||||
|
||||
154
core/lib/Thelia/Tests/Action/ProfileTest.php
Normal file
154
core/lib/Thelia/Tests/Action/ProfileTest.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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\Profile;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\Profile as ProfileModel;
|
||||
use Thelia\Core\Event\Profile\ProfileEvent;
|
||||
use Thelia\Model\ProfileQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class ProfileTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ProfileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $dispatcher;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ProfileQuery::create()
|
||||
->filterByCode('Test')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
|
||||
$event
|
||||
->setCode("Test")
|
||||
->setLocale('en_US')
|
||||
->setTitle('test profile')
|
||||
->setChapo('test chapo')
|
||||
->setDescription('test description')
|
||||
->setPostscriptum('test postscriptum')
|
||||
->setDispatcher($this->dispatcher)
|
||||
;
|
||||
|
||||
$action = new Profile();
|
||||
$action->create($event);
|
||||
|
||||
$createdProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $createdProfile);
|
||||
$this->assertFalse($createdProfile->isNew());
|
||||
|
||||
$this->assertEquals('Test', $createdProfile->getCode());
|
||||
$this->assertEquals('en_US', $createdProfile->getLocale());
|
||||
$this->assertEquals('test profile', $createdProfile->getTitle());
|
||||
$this->assertEquals('test chapo', $createdProfile->getChapo());
|
||||
$this->assertEquals('test description', $createdProfile->getDescription());
|
||||
$this->assertEquals('test postscriptum', $createdProfile->getPostscriptum());
|
||||
|
||||
return $createdProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*/
|
||||
public function testUpdate(ProfileModel $profile)
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
|
||||
$event
|
||||
->setId($profile->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update title')
|
||||
->setChapo('test update chapo')
|
||||
->setDescription('test update description')
|
||||
->setPostscriptum('test update postscriptum')
|
||||
->setDispatcher($this->dispatcher)
|
||||
;
|
||||
|
||||
$action = new Profile();
|
||||
$action->update($event);
|
||||
|
||||
$updatedProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $updatedProfile);
|
||||
|
||||
$this->assertEquals($profile->getCode(), $updatedProfile->getCode());
|
||||
$this->assertEquals('en_US', $updatedProfile->getLocale());
|
||||
$this->assertEquals('test update title', $updatedProfile->getTitle());
|
||||
$this->assertEquals('test update chapo', $updatedProfile->getChapo());
|
||||
$this->assertEquals('test update description', $updatedProfile->getDescription());
|
||||
$this->assertEquals('test update postscriptum', $updatedProfile->getPostscriptum());
|
||||
|
||||
return $updatedProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testUpdateResourceAccess(ProfileModel $profile)
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
$event
|
||||
->setId($profile->getId())
|
||||
->setResourceAccess(array(
|
||||
'admin.address' => array(AccessManager::CREATE)
|
||||
))
|
||||
->setDispatcher($this->dispatcher);
|
||||
;
|
||||
|
||||
$action = new Profile();
|
||||
$action->updateResourceAccess($event);
|
||||
|
||||
$updatedProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $updatedProfile);
|
||||
|
||||
$resources = $updatedProfile->getResources();
|
||||
|
||||
$this->assertEquals(1, count($resources));
|
||||
|
||||
$resource = $resources->getFirst();
|
||||
$this->assertEquals('admin.address', $resource->getCode());
|
||||
|
||||
$profileResource = $updatedProfile->getProfileResources()->getFirst();
|
||||
$accessManager = new AccessManager($profileResource->getAccess());
|
||||
|
||||
$this->assertTrue($accessManager->can(AccessManager::CREATE));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user