Skip to content

Commit

Permalink
Merge pull request #4000 from pamil/theme-bundle-integration
Browse files Browse the repository at this point in the history
[Core] [Theme] Integration with Sylius platform
  • Loading branch information
Paweł Jędrzejewski committed Feb 29, 2016
2 parents 2e82cb9 + 157f73a commit 663ada4
Show file tree
Hide file tree
Showing 44 changed files with 1,369 additions and 53 deletions.
38 changes: 38 additions & 0 deletions app/migrations/Version20160229125721.php
@@ -0,0 +1,38 @@
<?php

namespace Sylius\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160229125721 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_channel ADD theme_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE sylius_channel ADD CONSTRAINT FK_16C8119E59027487 FOREIGN KEY (theme_id) REFERENCES sylius_theme (id) ON DELETE SET NULL');
$this->addSql('CREATE INDEX IDX_16C8119E59027487 ON sylius_channel (theme_id)');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_channel DROP FOREIGN KEY FK_16C8119E59027487');
$this->addSql('DROP INDEX IDX_16C8119E59027487 ON sylius_channel');
$this->addSql('ALTER TABLE sylius_channel DROP theme_id');
}
}
3 changes: 3 additions & 0 deletions etc/behat/services.xml
Expand Up @@ -20,6 +20,7 @@
<parameter key="sylius.behat.cookie_setter.class">Sylius\Behat\CookieSetter</parameter>
<parameter key="sylius.behat.channel_context_setter.class">Sylius\Behat\ChannelContextSetter</parameter>
<parameter key="sylius.behat.security.class">Sylius\Behat\SecurityService</parameter>
<parameter key="sylius.behat.table_manipulator.class">Sylius\Behat\TableManipulator</parameter>
<parameter key="sylius.behat.page.class">Sylius\Behat\Page\Page</parameter>
<parameter key="sylius.behat.symfony_page.class">Sylius\Behat\Page\SymfonyPage</parameter>
</parameters>
Expand All @@ -42,6 +43,8 @@
<argument>user</argument>
</service>

<service id="sylius.behat.table_manipulator" class="%sylius.behat.table_manipulator.class%" public="false" />

<service id="sylius.behat.page" class="%sylius.behat.page.class%" abstract="true" scope="scenario" public="false">
<argument type="service" id="mink.default_session" />
<argument>%mink.parameters%</argument>
Expand Down
29 changes: 29 additions & 0 deletions etc/behat/services/contexts.xml
Expand Up @@ -25,6 +25,7 @@
<parameter key="sylius.behat.context.setup.zone.class">Sylius\Behat\Context\Setup\ZoneContext</parameter>
<parameter key="sylius.behat.context.setup.tax.class">Sylius\Behat\Context\Setup\TaxContext</parameter>
<parameter key="sylius.behat.context.setup.order.class">Sylius\Behat\Context\Setup\OrderContext</parameter>
<parameter key="sylius.behat.context.setup.theme.class">Sylius\Behat\Context\Setup\ThemeContext</parameter>

<parameter key="sylius.behat.context.transform.customer.class">Sylius\Behat\Context\Transform\CustomerContext</parameter>
<parameter key="sylius.behat.context.transform.addressing.class">Sylius\Behat\Context\Transform\AddressingContext</parameter>
Expand All @@ -36,6 +37,7 @@
<parameter key="sylius.behat.context.transform.shipping.class">Sylius\Behat\Context\Transform\ShippingContext</parameter>
<parameter key="sylius.behat.context.transform.tax.class">Sylius\Behat\Context\Transform\TaxContext</parameter>
<parameter key="sylius.behat.context.transform.zone.class">Sylius\Behat\Context\Transform\ZoneContext</parameter>
<parameter key="sylius.behat.context.transform.theme.class">Sylius\Behat\Context\Transform\ThemeContext</parameter>

<parameter key="sylius.behat.context.hook.doctrine_orm.class">Sylius\Behat\Context\Hook\DoctrineORMContext</parameter>

Expand All @@ -46,6 +48,7 @@
<parameter key="sylius.behat.context.ui.product.class">Sylius\Behat\Context\Ui\ProductContext</parameter>
<parameter key="sylius.behat.context.ui.paypal.class">Sylius\Behat\Context\Ui\PaypalContext</parameter>
<parameter key="sylius.behat.context.ui.customer.class">Sylius\Behat\Context\Ui\CustomerContext</parameter>
<parameter key="sylius.behat.context.ui.theme.class">Sylius\Behat\Context\Ui\ThemeContext</parameter>

<parameter key="sylius.behat.context.domain.order.class">Sylius\Behat\Context\Domain\OrderContext</parameter>
</parameters>
Expand Down Expand Up @@ -155,6 +158,15 @@
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.setup.theme" class="%sylius.behat.context.setup.theme.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.repository.theme" container="symfony" />
<argument type="service" id="sylius.factory.theme" container="symfony" />
<argument type="service" id="sylius.repository.channel" container="symfony" />
<argument type="service" id="sylius.manager.channel" container="symfony" />
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.transform.customer" class="%sylius.behat.context.transform.customer.class%" scope="scenario">
<argument type="service" id="sylius.repository.customer" container="symfony" />
<argument type="service" id="sylius.factory.customer" container="symfony" />
Expand Down Expand Up @@ -207,6 +219,11 @@
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.transform.theme" class="%sylius.behat.context.transform.theme.class%" scope="scenario">
<argument type="service" id="sylius.repository.theme" container="symfony" />
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.hook.doctrine_orm" class="%sylius.behat.context.hook.doctrine_orm.class%">
<argument type="service" id="doctrine.orm.entity_manager" container="symfony_shared" />
<tag name="sylius.behat.context" />
Expand Down Expand Up @@ -245,7 +262,11 @@
</service>

<service id="sylius.behat.context.ui.channel" class="%sylius.behat.context.ui.channel.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony"/>
<argument type="service" id="sylius.behat.channel_context_setter" />
<argument type="service" id="sylius.repository.channel" container="symfony"/>
<argument type="service" id="sylius.behat.page.channel_create" />
<argument type="service" id="sylius.behat.page.home" />
<tag name="sylius.behat.context" />
</service>

Expand All @@ -260,6 +281,14 @@
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.ui.theme" class="%sylius.behat.context.ui.theme.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony"/>
<argument type="service" id="sylius.behat.page.channel_index" />
<argument type="service" id="sylius.behat.page.channel_update" />
<argument type="service" id="sylius.behat.page.home" />
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.domain.order" class="%sylius.behat.context.domain.order.class%" scope="scenario">
<argument type="service" id="sylius.repository.order" container="symfony"/>
<tag name="sylius.behat.context" />
Expand Down
8 changes: 8 additions & 0 deletions etc/behat/services/pages.xml
Expand Up @@ -18,6 +18,9 @@
<parameter key="sylius.behat.page.customer_show.class">Sylius\Behat\Page\Customer\CustomerShowPage</parameter>
<parameter key="sylius.behat.page.login.class">Sylius\Behat\Page\User\LoginPage</parameter>
<parameter key="sylius.behat.page.home.class">Sylius\Behat\Page\Shop\HomePage</parameter>
<parameter key="sylius.behat.page.channel_create.class">Sylius\Behat\Page\Channel\ChannelCreatePage</parameter>
<parameter key="sylius.behat.page.channel_update.class">Sylius\Behat\Page\Channel\ChannelUpdatePage</parameter>
<parameter key="sylius.behat.page.channel_index.class">Sylius\Behat\Page\Channel\ChannelIndexPage</parameter>

<parameter key="sylius.behat.page.checkout_addressing.class">Sylius\Behat\Page\Checkout\CheckoutAddressingStep</parameter>
<parameter key="sylius.behat.page.checkout_finalize.class">Sylius\Behat\Page\Checkout\CheckoutFinalizeStep</parameter>
Expand All @@ -34,6 +37,11 @@
<service id="sylius.behat.page.customer_show" class="%sylius.behat.page.customer_show.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.login" class="%sylius.behat.page.login.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.home" class="%sylius.behat.page.home.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.channel_create" class="%sylius.behat.page.channel_create.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.channel_update" class="%sylius.behat.page.channel_update.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.channel_index" class="%sylius.behat.page.channel_index.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false">
<argument type="service" id="sylius.behat.table_manipulator" />
</service>

<service id="sylius.behat.page.checkout_addressing" class="%sylius.behat.page.checkout_addressing.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.checkout_finalize" class="%sylius.behat.page.checkout_finalize.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
Expand Down
1 change: 1 addition & 0 deletions etc/behat/suites.yml
Expand Up @@ -35,6 +35,7 @@ imports:
- suites/ui_channel.yml
- suites/ui_checkout.yml
- suites/ui_promotion.yml
- suites/ui_theme.yml
- suites/ui_user.yml

- suites/domain_order.yml
22 changes: 22 additions & 0 deletions etc/behat/suites/ui_theme.yml
@@ -0,0 +1,22 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
ui_theme:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.theme

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.security
- sylius.behat.context.setup.theme

- sylius.behat.context.ui.channel
- sylius.behat.context.ui.theme

filters:
tags: @theme && @ui
@@ -1,22 +1,20 @@
@theme @ui
Feature: Displaying themed channel website
In order to allow customizing channels' appearance
As an Administrator
I want to be able to set theme per channel
In order to easily distinguish stores
As an Visitor
I want to see a different user interface on each one

Background:
Given the store operates on a channel named "France"
Given the store operates on a single channel in "France"
And the store has "Maverick Meerkat" theme
And this theme changes homepage template contents to "Onions and bananas"

@todo
Scenario: Displaying default shop homepage
Given channel "France" does not use any theme
When I visit this channel's homepage
Then I should not see "Onions and bananas"
Then I should not see a homepage from "Maverick Meerkat" theme

@todo
Scenario: Displaying themed shop homepage
Given channel "France" uses "Maverick Meerkat" theme
When I visit this channel's homepage
Then I should see "Onions and bananas"
Then I should see a homepage from that theme
26 changes: 26 additions & 0 deletions features/channel/managing_themes_per_channel.feature
@@ -0,0 +1,26 @@
@theme
Feature: Managing themes per channel
In order to allow customizing channels' appearance
As a store owner
I want to be able to set theme per channel

Background:
Given the store operates on a channel named "France"
And the store has "Maverick Meerkat" theme
And I am logged in as administrator

@ui
Scenario: None of the themes are used by default
When I create a new channel "Poland"
Then that channel should not use any theme

@ui
Scenario: Setting a theme on a channel
When I set "France" channel theme to "Maverick Meerkat"
Then that channel should use that theme

@ui
Scenario: Unsetting a channel theme
Given channel "France" uses "Maverick Meerkat" theme
When I unset theme on that channel
Then that channel should not use any theme
130 changes: 130 additions & 0 deletions src/Sylius/Behat/Context/Setup/ThemeContext.php
@@ -0,0 +1,130 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface;
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;

/**
* @author Kamil Kokot <kamil.kokot@lakion.com>
*/
final class ThemeContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;

/**
* @var ThemeRepositoryInterface
*/
private $themeRepository;

/**
* @var ThemeFactoryInterface
*/
private $themeFactory;

/**
* @var ChannelRepositoryInterface
*/
private $channelRepository;

/**
* @var ObjectManager
*/
private $channelManager;

/**
* @param SharedStorageInterface $sharedStorage
* @param ThemeRepositoryInterface $themeRepository
* @param ThemeFactoryInterface $themeFactory
* @param ChannelRepositoryInterface $channelRepository
* @param ObjectManager $channelManager
*/
public function __construct(
SharedStorageInterface $sharedStorage,
ThemeRepositoryInterface $themeRepository,
ThemeFactoryInterface $themeFactory,
ChannelRepositoryInterface $channelRepository,
ObjectManager $channelManager
) {
$this->sharedStorage = $sharedStorage;
$this->themeRepository = $themeRepository;
$this->themeFactory = $themeFactory;
$this->channelRepository = $channelRepository;
$this->channelManager = $channelManager;
}

/**
* @Given the store has :themeName theme
*/
public function storeHasTheme($themeName)
{
$theme = $this->themeFactory->createNamed($themeName);
$theme->setTitle($themeName);
$theme->setPath(sys_get_temp_dir() . '/theme-' . $theme->getCode() . time() . '/');

if (!file_exists($theme->getPath())) {
mkdir($theme->getPath(), 0777, true);
}

$this->themeRepository->add($theme);
$this->sharedStorage->set('theme', $theme);
}

/**
* @Given channel :channel uses :theme theme
*/
public function channelUsesTheme(ChannelInterface $channel, ThemeInterface $theme)
{
$channel->setTheme($theme);

$this->channelManager->flush();

$this->sharedStorage->set('channel', $channel);
$this->sharedStorage->set('theme', $theme);
}

/**
* @Given channel :channel does not use any theme
*/
public function channelDoesNotUseAnyTheme(ChannelInterface $channel)
{
$channel->setTheme(null);

$this->channelManager->flush();

$this->sharedStorage->set('channel', $channel);
}

/**
* @Given /^(this theme) changes homepage template contents to "([^"]+)"$/
*/
public function themeChangesHomepageTemplateContents(ThemeInterface $theme, $contents)
{
$file = rtrim($theme->getPath(), '/') . '/SyliusWebBundle/views/Frontend/Homepage/main.html.twig';
$dir = dirname($file);

if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}

file_put_contents($file, $contents);
}
}

0 comments on commit 663ada4

Please sign in to comment.