Completed
Push — dev/plugin-assets ( 1918e3 )
by Kiyotaka
06:51
created

EA10PluginCest::installStorePluginWithAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 37
rs 9.328
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Codeception\Util\Fixtures;
15
use Doctrine\ORM\EntityManager;
16
use Eccube\Common\EccubeConfig;
17
use Eccube\Entity\Plugin;
18
use Eccube\Repository\PluginRepository;
19
use Page\Admin\PluginLocalInstallPage;
20
use Page\Admin\PluginManagePage;
21
use Page\Admin\PluginSearchPage;
22
23
class EA10PluginCest
24
{
25
    /** @var EntityManager */
26
    private $em;
27
28
    /** @var \Doctrine\DBAL\Connection */
29
    private $conn;
30
31
    /** @var PluginRepository */
32
    private $pluginRepository;
33
34
    /** @var EccubeConfig */
35
    private $config;
36
37
    public function _before(\AcceptanceTester $I)
38
    {
39
        $I->loginAsAdmin();
40
41
        $this->em = Fixtures::get('entityManager');
42
        $this->conn = $this->em->getConnection();
43
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
44
        $this->config = Fixtures::get('config');
45
    }
46
47
    public function installFromStore(\AcceptanceTester $I)
48
    {
49
        /*
50
         * インストール
51
         */
52
53
        $ManagePage = PluginSearchPage::go($I)
54
            ->入手する('SamplePayment')
55
            ->インストール();
56
57
        $I->assertFalse($this->tableExists('plg_sample_payment_config'));
58
        $I->assertFalse($this->columnExists('dtb_customer', 'sample_payment_cards'));
59
60
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
61
        $I->assertFalse($Plugin->isInitialized(), '初期化されていない');
62
        $I->assertFalse($Plugin->isEnabled(), '有効化されていない');
63
64
        /*
65
         * 有効化
66
         */
67
        $ManagePage->ストアプラグイン_有効化('SamplePayment');
68
69
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
70
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
71
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
72
73
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 60 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
74
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
75
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
76
77
        /*
78
         * 無効化
79
         */
80
        $ManagePage->ストアプラグイン_無効化('SamplePayment');
81
82
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
83
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
84
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
85
86
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 60 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
87
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
88
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
89
90
        /*
91
         * 再度有効化
92
         */
93
        $ManagePage->ストアプラグイン_有効化('SamplePayment');
94
95
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
96
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
97
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
98
99
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 60 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
100
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
101
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
102
103
        /*
104
         * 再度無効化
105
         */
106
        $ManagePage->ストアプラグイン_無効化('SamplePayment');
107
108
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
109
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
110
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
111
112
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 60 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
113
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
114
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
115
116
        /*
117
         * 削除
118
         */
119
        $ManagePage->ストアプラグイン_削除('SamplePayment');
120
121
        $I->assertFalse($this->tableExists('plg_sample_payment_config'));
122
        $I->assertFalse($this->columnExists('dtb_customer', 'sample_payment_cards'));
123
124
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 60 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
125
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
126
        $I->assertNull($Plugin);
127
    }
128
129
    public function installFromLocal(\AcceptanceTester $I)
130
    {
131
        /*
132
         * インストール
133
         */
134
        $ManagePage = PluginLocalInstallPage::go($I)
135
            ->アップロード('SamplePayment-1.0.0-beta-1.tgz');
136
137
        $I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
138
139
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
140
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
141
142
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
143
        $I->assertTrue($Plugin->isInitialized(), '初期化されていない');
144
        $I->assertFalse($Plugin->isEnabled(), '有効化されていない');
145
146
        /*
147
         * 有効化
148
         */
149
        $ManagePage->独自プラグイン_有効化('SamplePayment');
150
151
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
152
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
153
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
154
155
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 142 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
156
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
157
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
158
159
        /*
160
         * 無効化
161
         */
162
        $ManagePage->独自プラグイン_無効化('SamplePayment');
163
164
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
165
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
166
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
167
168
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 142 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
169
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
170
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
171
172
        /*
173
         * 再度有効化
174
        */
175
        $ManagePage->独自プラグイン_有効化('SamplePayment');
176
177
        $I->see('「EC-CUBE Payment Sample Plugin」を有効にしました。', PluginManagePage::完了メーッセージ);
178
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
179
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
180
181
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 142 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
182
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
183
        $I->assertTrue($Plugin->isEnabled(), '有効化されている');
184
185
        /*
186
         * 再度無効化
187
         */
188
        $ManagePage->独自プラグイン_無効化('SamplePayment');
189
190
        $I->see('「EC-CUBE Payment Sample Plugin」を無効にしました。', PluginManagePage::完了メーッセージ);
191
        $I->assertTrue($this->tableExists('plg_sample_payment_config'));
192
        $I->assertTrue($this->columnExists('dtb_customer', 'sample_payment_cards'));
193
194
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 142 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
195
        $I->assertTrue($Plugin->isInitialized(), '初期化されている');
196
        $I->assertFalse($Plugin->isEnabled(), '無効化されている');
197
198
        /*
199
         * 削除
200
         */
201
        $ManagePage->独自プラグイン_削除('SamplePayment');
202
203
        $I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
204
205
        $I->assertFalse($this->tableExists('plg_sample_payment_config'));
206
        $I->assertFalse($this->columnExists('dtb_customer', 'sample_payment_cards'));
207
208
        $this->em->refresh($Plugin);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository-...ByCode('SamplePayment') on line 142 can be null; however, Doctrine\ORM\EntityManager::refresh() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
209
        $Plugin = $this->pluginRepository->findByCode('SamplePayment');
210
        $I->assertNull($Plugin);
211
    }
212
213
    public function installLocalPluginWithAssets(\AcceptanceTester $I)
214
    {
215
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
216
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
217
218
        $I->assertFileNotExists($assetsPath);
219
        $I->assertFileNotExists($updatedPath);
220
221
        $ManagePage = PluginLocalInstallPage::go($I)->アップロード('plugins/Assets-1.0.0.tgz');
222
        $I->assertFileExists($assetsPath);
223
        $I->assertFileNotExists($updatedPath);
224
225
        $ManagePage->独自プラグイン_有効化('Assets');
226
        $I->assertFileExists($assetsPath);
227
        $I->assertFileNotExists($updatedPath);
228
229
        $ManagePage->独自プラグイン_無効化('Assets');
230
        $I->assertFileExists($assetsPath);
231
        $I->assertFileNotExists($updatedPath);
232
233
        $ManagePage->独自プラグイン_アップデート('Assets', 'plugins/Assets-1.0.1.tgz');
234
        $I->assertFileExists($assetsPath);
235
        $I->assertFileExists($updatedPath);
236
237
        $ManagePage->独自プラグイン_削除('Assets');
238
        $I->assertFileNotExists($assetsPath);
239
        $I->assertFileNotExists($updatedPath);
240
    }
241
242
    public function installStorePluginWithAssets(\AcceptanceTester $I)
243
    {
244
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
245
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
246
        $I->assertFileNotExists($assetsPath);
247
        $I->assertFileNotExists($updatedPath);
248
249
        $ManagePage = PluginSearchPage::go($I)
250
            ->入手する('Assets')
251
            ->インストール();
252
        $I->assertFileNotExists($assetsPath);
253
        $I->assertFileNotExists($updatedPath);
254
255
        $ManagePage->ストアプラグイン_有効化('Assets');
256
        $I->assertFileExists($assetsPath);
257
        $I->assertFileNotExists($updatedPath);
258
259
        $ManagePage->ストアプラグイン_無効化('Assets');
260
        $I->assertFileExists($assetsPath);
261
        $I->assertFileNotExists($updatedPath);
262
263
        // 新しいバージョンを作成
264
        copy(codecept_data_dir().'/'.'plugins/Assets-1.0.1.tgz', codecept_root_dir().'/repos/Assets-1.0.1.tgz');
265
266
        $I->reloadPage();
267
        $ManagePage->ストアプラグイン_アップデート('Assets')->アップデート();
268
        $I->assertFileExists($assetsPath);
269
        $I->assertFileExists($updatedPath);
270
271
        $ManagePage->ストアプラグイン_無効化('Assets');
272
        $I->assertFileExists($assetsPath);
273
        $I->assertFileExists($updatedPath);
274
275
        $ManagePage->ストアプラグイン_削除('Assets');
276
        $I->assertFileNotExists($assetsPath);
277
        $I->assertFileNotExists($updatedPath);
278
    }
279
280
    private function tableExists($tableName)
281
    {
282
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
283
    }
284
285
    private function columnExists($tableName, $columnName)
286
    {
287
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
288
    }
289
}
290