Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4000 from pamil/theme-bundle-integration
[Core] [Theme] Integration with Sylius platform
- Loading branch information
Showing
44 changed files
with
1,369 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
14 changes: 6 additions & 8 deletions
14
...rendering_themed_channel_websites.feature → ...displaying_themed_channel_website.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.