Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pjedrzejewski committed Nov 15, 2015
1 parent d9ef077 commit f680622
Show file tree
Hide file tree
Showing 61 changed files with 410 additions and 224 deletions.
1 change: 1 addition & 0 deletions behat.yml.dist
Expand Up @@ -385,6 +385,7 @@ default:
- Behat\MinkExtension\Context\MinkContext
- Sylius\Bundle\CoreBundle\Behat\HookContext
- Sylius\Bundle\AddressingBundle\Behat\AddressingContext
- Sylius\Bundle\ChannelBundle\Behat\ChannelContext
- Sylius\Bundle\CoreBundle\Behat\CoreContext
- Sylius\Bundle\ProductBundle\Behat\ProductContext
- Sylius\Bundle\PromotionBundle\Behat\PromotionContext
Expand Down
28 changes: 27 additions & 1 deletion features/security/permission_management.feature
Expand Up @@ -5,6 +5,7 @@ Feature: Permissions management
I want to be able to manage permissions

Background:
<<<<<<< HEAD
Given store has default configuration
And there is following permission hierarchy:
| code | parent | description |
Expand All @@ -23,6 +24,30 @@ Feature: Permissions management
| code | parent | name | security roles |
| sylius.administrator | | Administrator | ROLE_ADMINISTRATION_ACCESS |
And role "Administrator" has the following permissions:
=======
Given there is default currency configured
And there is default channel configured
And there are following locales configured:
| code | enabled |
| en_US | yes |
And there is following permission hierarchy:
| code | parent | description |
| sylius.catalog | | Manage products catalog |
| sylius.product.show | sylius.catalog | View single product |
| sylius.product.index | sylius.catalog | List all products |
| sylius.product.create | sylius.catalog | Add new products |
| sylius.product.update | sylius.catalog | Edit products |
| sylius.product.delete | sylius.catalog | Delete products |
| sylius.permission.show | | View single permission |
| sylius.permission.index | | List all permissions |
| sylius.permission.create | | Add new permissions |
| sylius.permission.update | | Edit permissions |
| sylius.permission.delete | | Delete permissions |
And there is following role hierarchy:
| code | parent | name | security roles |
| sylius.administrator | | Administrator | ROLE_ADMINISTRATION_ACCESS |
And role "Administrator" has the following permissions:
>>>>>>> Fix specs
| sylius.permission.show |
| sylius.permission.index |
| sylius.permission.create |
Expand Down Expand Up @@ -58,7 +83,8 @@ Feature: Permissions management
Then I should be on the permission index page
And I should see "Permission has been successfully created."
And I should see 13 permissions in the list
And I should see permission with code "sylius.product.display_sales_stats" in that list
And show last response
And I should see "View sales statistics (sylius.product.display_sales_stats)"

Scenario: Cannot edit the parent of root node
Given I am on the permission index page
Expand Down
32 changes: 32 additions & 0 deletions features/security/role_based_access_control.feature
Expand Up @@ -5,6 +5,7 @@ Feature: Hierarchical Role based access control (HRBAC)
I want to be able to allow only certain roles to access backend

Background:
<<<<<<< HEAD
Given store has default configuration
And authorization checks are enabled
And there is following permission hierarchy:
Expand All @@ -30,6 +31,37 @@ Feature: Hierarchical Role based access control (HRBAC)
| sylius.catalog |
And role "Sales Manager" has the following permissions:
| sylius.sales |
=======
Given there is default currency configured
And there is default channel configured
And authorization checks are enabled
And there are following locales configured:
| code | enabled |
| en_US | yes |
And there is following permission hierarchy:
| code | parent | description |
| sylius.catalog | | Manage products catalog |
| sylius.product.show | sylius.catalog | View single product |
| sylius.product.index | sylius.catalog | List all products |
| sylius.product.create | sylius.catalog | Add new products |
| sylius.product.update | sylius.catalog | Edit products |
| sylius.product.delete | sylius.catalog | Delete products |
| sylius.sales | | Manage products sales |
| sylius.order.show | sylius.sales | View single order |
| sylius.order.index | sylius.sales | List all orders |
| sylius.order.create | sylius.sales | Add new orders |
| sylius.order.update | sylius.sales | Edit orders |
| sylius.order.delete | sylius.sales | Delete orders |
And there is following role hierarchy:
| code | parent | name | security roles |
| sylius.administrator | | Administrator | ROLE_ADMINISTRATION_ACCESS |
| sylius.catalog_manager | sylius.administrator | Catalog Manager | ROLE_ADMINISTRATION_ACCESS |
| sylius.sales_manager | sylius.administrator | Sales Manager | ROLE_ADMINISTRATION_ACCESS |
And role "Catalog Manager" has the following permissions:
| sylius.catalog |
And role "Sales Manager" has the following permissions:
| sylius.sales |
>>>>>>> Fix specs

Scenario: Only selected menus are visible for Sales Manager
Given I am logged in as "Sales Manager"
Expand Down
9 changes: 9 additions & 0 deletions features/security/role_management.feature
Expand Up @@ -5,8 +5,17 @@ Feature: Roles management
I want to be able to manage user roles

Background:
<<<<<<< HEAD
Given store has default configuration
And there is following permission hierarchy:
=======
Given there is default currency configured
And there is default channel configured
And there are following locales configured:
| code | enabled |
| en_US | yes |
And there is following permission hierarchy:
>>>>>>> Fix specs
| code | parent | description |
| sylius.catalog | | Manage products catalog |
| sylius.product.show | sylius.catalog | View single product |
Expand Down
Expand Up @@ -11,7 +11,7 @@

namespace Sylius\Bundle\AddressingBundle\Form\EventListener;

use Doctrine\Common\Persistence\ObjectRepository;
use Sylius\Component\Resource\Repository\ResourceRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
Expand All @@ -25,7 +25,7 @@
class BuildAddressFormSubscriber implements EventSubscriberInterface
{
/**
* @var ObjectRepository
* @var ResourceRepositoryInterface
*/
private $countryRepository;

Expand All @@ -39,10 +39,10 @@ class BuildAddressFormSubscriber implements EventSubscriberInterface
/**
* Constructor.
*
* @param ObjectRepository $countryRepository
* @param ResourceRepositoryInterface $countryRepository
* @param FormFactoryInterface $factory
*/
public function __construct(ObjectRepository $countryRepository, FormFactoryInterface $factory)
public function __construct(ResourceRepositoryInterface $countryRepository, FormFactoryInterface $factory)
{
$this->countryRepository = $countryRepository;
$this->factory = $factory;
Expand Down
Expand Up @@ -11,12 +11,12 @@

namespace spec\Sylius\Bundle\AddressingBundle\Form\EventListener;

use Doctrine\Common\Persistence\ObjectRepository;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Addressing\Model\AddressInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ProvinceInterface;
use Sylius\Component\Resource\Repository\ResourceRepositoryInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
Expand All @@ -27,7 +27,7 @@
*/
class BuildAddressFormSubscriberSpec extends ObjectBehavior
{
function let(ObjectRepository $countryRepository, FormFactoryInterface $factory)
function let(ResourceRepositoryInterface $countryRepository, FormFactoryInterface $factory)
{
$this->beConstructedWith($countryRepository, $factory);
}
Expand Down Expand Up @@ -86,10 +86,10 @@ function it_adds_or_removes_provinces_on_pre_submit(
) {
$event->getForm()->shouldBeCalled()->willReturn($form);
$event->getData()->shouldBeCalled()->willReturn(array(
'country' => 'France'
'country' => 'FR'
));

$countryRepository->find('France')->shouldBeCalled()->willReturn($country);
$countryRepository->find('FR')->shouldBeCalled()->willReturn($country);
$country->hasProvinces()->willReturn(true);

$factory->createNamed('province', 'sylius_province_choice', null, Argument::withKey('country'))
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Model/AccessToken.php
Expand Up @@ -18,6 +18,6 @@
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class AccessToken extends BaseAccessToken
class AccessToken extends BaseAccessToken implements AccessTokenInterface
{
}
3 changes: 2 additions & 1 deletion src/Sylius/Bundle/ApiBundle/Model/AccessTokenInterface.php
Expand Up @@ -12,12 +12,13 @@
namespace Sylius\Bundle\ApiBundle\Model;

use FOS\OAuthServerBundle\Model\AccessTokenInterface as BaseAccessTokenInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

/**
* API access token interface.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface AccessTokenInterface extends BaseAccessTokenInterface
interface AccessTokenInterface extends BaseAccessTokenInterface, ResourceInterface
{
}
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Model/AuthCode.php
Expand Up @@ -18,6 +18,6 @@
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class AuthCode extends BaseAuthCode
class AuthCode extends BaseAuthCode implements AuthCodeInterface
{
}
3 changes: 2 additions & 1 deletion src/Sylius/Bundle/ApiBundle/Model/AuthCodeInterface.php
Expand Up @@ -12,12 +12,13 @@
namespace Sylius\Bundle\ApiBundle\Model;

use FOS\OAuthServerBundle\Model\AuthCodeInterface as BaseAuthCodeInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

/**
* API auth code interface.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface AuthCodeInterface extends BaseAuthCodeInterface
interface AuthCodeInterface extends BaseAuthCodeInterface, ResourceInterface
{
}
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Model/Client.php
Expand Up @@ -18,7 +18,7 @@
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class Client extends BaseClient
class Client extends BaseClient implements ClientInterface
{
/**
* {@inheritdoc}
Expand Down
3 changes: 2 additions & 1 deletion src/Sylius/Bundle/ApiBundle/Model/ClientInterface.php
Expand Up @@ -12,12 +12,13 @@
namespace Sylius\Bundle\ApiBundle\Model;

use FOS\OAuthServerBundle\Model\ClientInterface as BaseClientInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

/**
* API client interface.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface ClientInterface extends BaseClientInterface
interface ClientInterface extends BaseClientInterface, ResourceInterface
{
}
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/Model/RefreshToken.php
Expand Up @@ -18,6 +18,6 @@
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class RefreshToken extends BaseRefreshToken
class RefreshToken extends BaseRefreshToken implements RefreshTokenInterface
{
}
3 changes: 2 additions & 1 deletion src/Sylius/Bundle/ApiBundle/Model/RefreshTokenInterface.php
Expand Up @@ -12,12 +12,13 @@
namespace Sylius\Bundle\ApiBundle\Model;

use FOS\OAuthServerBundle\Model\RefreshTokenInterface as BaseRefreshTokenInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

/**
* API refresh token interface.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface RefreshTokenInterface extends BaseRefreshTokenInterface
interface RefreshTokenInterface extends BaseRefreshTokenInterface, ResourceInterface
{
}
Expand Up @@ -35,6 +35,22 @@ public function load(array $config, ContainerBuilder $container)

$this->registerResources('sylius', $config['driver'], $this->resolveResources($config['resources'], $container), $container);

foreach ($config['resources'] as $subjectName => $subjectConfig) {
foreach ($subjectConfig as $resourceName => $resourceConfig) {
if (!is_array($resourceConfig)) {
continue;
}

$formDefinition = $container->getDefinition('sylius.form.type.'.$subjectName.'_'.$resourceName);
$formDefinition->addArgument($subjectName);

if (isset($resourceConfig['translation'])) {
$formTranslationDefinition = $container->getDefinition('sylius.form.type.'.$subjectName.'_'.$resourceName.'_translation');
$formTranslationDefinition->addArgument($subjectName);
}
}
}

$configFiles = array(
'services.xml',
);
Expand Down
Expand Up @@ -43,6 +43,8 @@ function it_should_add_a_item_to_a_cart_from_event(CartItemEvent $event, CartInt
$event->getItem()->willReturn($cartItem);
$cart->addItem($cartItem)->shouldBeCalled();

$cart->calculateTotal()->shouldBeCalled();

$this->addItem($event);
}

Expand All @@ -52,6 +54,8 @@ function it_should_remove_a_item_to_a_cart_from_event(CartItemEvent $event, Cart
$event->getItem()->willReturn($cartItem);
$cart->removeItem($cartItem)->shouldBeCalled();

$cart->calculateTotal()->shouldBeCalled();

$this->removeItem($event);
}

Expand Down Expand Up @@ -85,6 +89,9 @@ function it_should_not_save_an_invalid_cart(
) {
$constraintList->count()->willReturn(1);
$event->getCart()->willReturn($cart);

$cart->calculateTotal()->shouldBeCalled();

$validator->validate($cart)->shouldBeCalled()->willReturn($constraintList);

$manager->persist($cart)->shouldNotBeCalled();
Expand Down

0 comments on commit f680622

Please sign in to comment.