Completed
Push — master ( 155c16...880d18 )
by Kamil
26:05
created

ThemeContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Behat\Context\Ui;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\Page\Channel\ChannelIndexPage;
16
use Sylius\Behat\Page\Channel\ChannelUpdatePage;
17
use Sylius\Behat\Page\Shop\HomePage;
18
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
19
use Sylius\Component\Core\Model\ChannelInterface;
20
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
21
22
/**
23
 * @author Kamil Kokot <[email protected]>
24
 */
25
final class ThemeContext implements Context
26
{
27
    /**
28
     * @var SharedStorageInterface
29
     */
30
    private $sharedStorage;
31
32
    /**
33
     * @var ChannelIndexPage
34
     */
35
    private $channelIndexPage;
36
37
    /**
38
     * @var ChannelUpdatePage
39
     */
40
    private $channelUpdatePage;
41
42
    /**
43
     * @var HomePage
44
     */
45
    private $homePage;
46
47
    /**
48
     * @param SharedStorageInterface $sharedStorage
49
     * @param ChannelIndexPage $channelIndexPage
50
     * @param ChannelUpdatePage $channelUpdatePage
51
     * @param HomePage $homePage
52
     */
53
    public function __construct(
54
        SharedStorageInterface $sharedStorage,
55
        ChannelIndexPage $channelIndexPage,
56
        ChannelUpdatePage $channelUpdatePage,
57
        HomePage $homePage
58
    ) {
59
        $this->sharedStorage = $sharedStorage;
60
        $this->channelIndexPage = $channelIndexPage;
61
        $this->channelUpdatePage = $channelUpdatePage;
62
        $this->homePage = $homePage;
63
    }
64
65
    /**
66
     * @When I set :channel channel theme to :theme
67
     */
68
    public function iSetChannelThemeTo(ChannelInterface $channel, ThemeInterface $theme)
69
    {
70
        $this->channelUpdatePage->open(['id' => $channel->getId()]);
71
        $this->channelUpdatePage->setTheme($theme);
72
        $this->channelUpdatePage->update();
73
74
        $this->sharedStorage->set('channel', $channel);
75
        $this->sharedStorage->set('theme', $theme);
76
    }
77
78
    /**
79
     * @When /^I unset theme on (that channel)$/
80
     */
81
    public function iUnsetThemeOnChannel(ChannelInterface $channel)
82
    {
83
        $this->channelUpdatePage->open(['id' => $channel->getId()]);
84
        $this->channelUpdatePage->unsetTheme();
85
        $this->channelUpdatePage->update();
86
    }
87
88
    /**
89
     * @Then /^(that channel) should not use any theme$/
90
     */
91
    public function channelShouldNotUseAnyTheme(ChannelInterface $channel)
92
    {
93
        $this->channelIndexPage->open();
94
95
        expect($this->channelIndexPage->getUsedThemeName($channel->getCode()))->toBe('');
96
    }
97
98
    /**
99
     * @Then /^(that channel) should use (that theme)$/
100
     */
101
    public function channelShouldUseTheme(ChannelInterface $channel, ThemeInterface $theme)
102
    {
103
        $this->channelIndexPage->open();
104
105
        expect($this->channelIndexPage->getUsedThemeName($channel->getCode()))->toBe($theme->getName());
106
    }
107
108
    /**
109
     * @Then /^I should see a homepage from ((?:this|that) theme)$/
110
     */
111
    public function iShouldSeeThemedHomepage(ThemeInterface $theme)
112
    {
113
        $content = file_get_contents(rtrim($theme->getPath(), '/') . '/SyliusWebBundle/views/Frontend/Homepage/main.html.twig');
114
115
        expect($this->homePage->getContents())->toBe($content);
116
    }
117
118
    /**
119
     * @Then I should not see a homepage from :theme theme
120
     */
121
    public function iShouldNotSeeThemedHomepage(ThemeInterface $theme)
122
    {
123
        $content = file_get_contents(rtrim($theme->getPath(), '/') . '/SyliusWebBundle/views/Frontend/Homepage/main.html.twig');
124
125
        expect($this->homePage->getContents())->notToBe($content);
126
    }
127
}
128