Completed
Push — dev/plugin-misc ( c06838...9b5709 )
by Kiyotaka
11:04
created

Horizon_Local::削除()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 15
loc 15
rs 9.7666
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\FileSystem;
15
use Codeception\Util\Fixtures;
16
use Doctrine\ORM\EntityManager;
17
use Eccube\Common\EccubeConfig;
18
use Eccube\Entity\Plugin;
19
use Eccube\Repository\PluginRepository;
20
use Page\Admin\PluginLocalInstallPage;
21
use Page\Admin\PluginManagePage;
22
use Page\Admin\PluginSearchPage;
23
24
class EA10PluginCest
25
{
26
    /** @var EntityManager */
27
    private $em;
28
29
    /** @var \Doctrine\DBAL\Connection */
30
    private $conn;
31
32
    /** @var PluginRepository */
33
    private $pluginRepository;
34
35
    /** @var EccubeConfig */
36
    private $config;
37
38 View Code Duplication
    public function _before(\AcceptanceTester $I)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $I->loginAsAdmin();
41
42
        $this->em = Fixtures::get('entityManager');
43
        $this->conn = $this->em->getConnection();
44
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
45
        $this->config = Fixtures::get('config');
46
        FileSystem::doEmptyDir('repos');
47
    }
48
49
    public function install_enable_disable_enable_disable_remove_store(\AcceptanceTester $I)
50
    {
51
        Horizon_Store::start($I)
52
            ->インストール()
53
            ->有効化()
54
            ->無効化()
55
            ->有効化()
56
            ->無効化()
57
            ->削除();
58
    }
59
60
    public function install_enable_disable_enable_disable_remove_local(\AcceptanceTester $I)
61
    {
62
        Horizon_Local::start($I)
63
            ->インストール()
64
            ->有効化()
65
            ->無効化()
66
            ->有効化()
67
            ->無効化()
68
            ->削除();
69
    }
70
71
    public function install_remove_local(\AcceptanceTester $I)
72
    {
73
        Horizon_Local::start($I)
74
            ->インストール()
75
            ->削除();
76
    }
77
78
    public function install_remove_store(\AcceptanceTester $I)
79
    {
80
        Horizon_Store::start($I)
81
            ->インストール()
82
            ->削除();
83
    }
84
85
    public function install_update_remove_store(\AcceptanceTester $I)
86
    {
87
        Horizon_Store::start($I)
88
            ->インストール()
89
            ->アップデート()
90
            ->削除();
91
    }
92
93
94
95
    public function install_update_remove_local(\AcceptanceTester $I)
96
    {
97
        Horizon_Local::start($I)
98
            ->インストール()
99
            ->アップデート()
100
            ->削除();
101
    }
102
103
    public function install_enable_disable_update_enable_disable_remove_local(\AcceptanceTester $I)
104
    {
105
        Horizon_Local::start($I)
106
            ->インストール()
107
            ->有効化()
108
            ->無効化()
109
            ->アップデート()
110
            ->有効化()
111
            ->無効化()
112
            ->削除();
113
    }
114
115
    public function install_enable_disable_update_enable_disable_remove_store(\AcceptanceTester $I)
116
    {
117
        Horizon_Store::start($I)
118
            ->インストール()
119
            ->有効化()
120
            ->無効化()
121
            ->アップデート()
122
            ->有効化()
123
            ->無効化()
124
            ->削除();
125
    }
126
127
    public function install_assets_local(\AcceptanceTester $I)
128
    {
129
        $this->publishPlugin('Assets-1.0.0.tgz');
130
131
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
132
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
133
134
        $I->assertFileNotExists($assetsPath);
135
        $I->assertFileNotExists($updatedPath);
136
137
        $ManagePage = PluginLocalInstallPage::go($I)->アップロード('plugins/Assets-1.0.0.tgz');
138
        $I->assertFileExists($assetsPath);
139
        $I->assertFileNotExists($updatedPath);
140
141
        $ManagePage->独自プラグイン_有効化('Assets');
142
        $I->assertFileExists($assetsPath);
143
        $I->assertFileNotExists($updatedPath);
144
145
        $ManagePage->独自プラグイン_無効化('Assets');
146
        $I->assertFileExists($assetsPath);
147
        $I->assertFileNotExists($updatedPath);
148
149
        $ManagePage->独自プラグイン_アップデート('Assets', 'plugins/Assets-1.0.1.tgz');
150
        $I->assertFileExists($assetsPath);
151
        $I->assertFileExists($updatedPath);
152
153
        $ManagePage->独自プラグイン_削除('Assets');
154
        $I->assertFileNotExists($assetsPath);
155
        $I->assertFileNotExists($updatedPath);
156
    }
157
158
    public function install_assets_store(\AcceptanceTester $I)
159
    {
160
        // 最初のバージョンを作成
161
        $this->publishPlugin('Assets-1.0.0.tgz');
162
163
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
164
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
165
        $I->assertFileNotExists($assetsPath);
166
        $I->assertFileNotExists($updatedPath);
167
168
        $ManagePage = PluginSearchPage::go($I)
169
            ->入手する('Assets')
170
            ->インストール();
171
        $I->assertFileNotExists($assetsPath);
172
        $I->assertFileNotExists($updatedPath);
173
174
        $ManagePage->ストアプラグイン_有効化('Assets');
175
        $I->assertFileExists($assetsPath);
176
        $I->assertFileNotExists($updatedPath);
177
178
        $ManagePage->ストアプラグイン_無効化('Assets');
179
        $I->assertFileExists($assetsPath);
180
        $I->assertFileNotExists($updatedPath);
181
182
        // 新しいバージョンを作成
183
        $this->publishPlugin('Assets-1.0.1.tgz');
184
185
        $I->reloadPage();
186
        $ManagePage->ストアプラグイン_アップデート('Assets')->アップデート();
187
        $I->assertFileExists($assetsPath);
188
        $I->assertFileExists($updatedPath);
189
190
        $ManagePage->ストアプラグイン_無効化('Assets');
191
        $I->assertFileExists($assetsPath);
192
        $I->assertFileExists($updatedPath);
193
194
        $ManagePage->ストアプラグイン_削除('Assets');
195
        $I->assertFileNotExists($assetsPath);
196
        $I->assertFileNotExists($updatedPath);
197
    }
198
199
    private function publishPlugin($fileName)
200
    {
201
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
202
    }
203
204
    private function tableExists($tableName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
205
    {
206
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
207
    }
208
209
    private function columnExists($tableName, $columnName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
210
    {
211
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
212
    }
213
}
214
215
abstract class Abstract_Plugin
216
{
217
    /** @var EntityManager */
218
    protected $em;
219
220
    /** @var \Doctrine\DBAL\Connection */
221
    protected $conn;
222
223
    /** @var PluginRepository */
224
    protected $pluginRepository;
225
226
    /** @var EccubeConfig */
227
    protected $config;
228
229
    /**
230
     * Abstract_Plugin constructor.
231
     */
232 View Code Duplication
    public function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
233
    {
234
        $this->em = Fixtures::get('entityManager');
235
        $this->conn = $this->em->getConnection();
236
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
237
        $this->config = Fixtures::get('config');
238
    }
239
240
    protected function tableExists($tableName)
241
    {
242
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
243
    }
244
245
    protected function columnExists($tableName, $columnName)
246
    {
247
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
248
    }
249
}
250
251
class Horizon_Store extends Abstract_Plugin
252
{
253
    /** @var AcceptanceTester */
254
    private $I;
255
256
    /** @var PluginManagePage */
257
    private $ManagePage;
258
259
    /** @var Plugin */
260
    private $Plugin;
261
262
    public static function start(AcceptanceTester $I)
263
    {
264
        return new Horizon_Store($I);
265
    }
266
267
    public function __construct(AcceptanceTester $I)
268
    {
269
        parent::__construct();
270
        $this->I = $I;
271
    }
272
273 View Code Duplication
    public function インストール()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
    {
275
        $this->publishPlugin('Horizon-1.0.0.tgz');
276
        /*
277
         * インストール
278
         */
279
        $this->ManagePage = PluginSearchPage::go($this->I)
280
            ->入手する('Horizon')
281
            ->インストール();
282
283
        $this->I->assertFalse($this->tableExists('dtb_dash'));
284
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'));
285
286
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
287
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
288
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
289
290
        return $this;
291
    }
292
293 View Code Duplication
    public function 有効化()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
294
    {
295
        $this->ManagePage->ストアプラグイン_有効化('Horizon');
296
297
        $this->I->assertTrue($this->tableExists('dtb_dash'));
298
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'));
299
300
        $this->em->refresh($this->Plugin);
301
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
302
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
303
304
        return $this;
305
    }
306
307 View Code Duplication
    public function 無効化()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
308
    {
309
        $this->ManagePage->ストアプラグイン_無効化('Horizon');
310
311
        $this->I->assertTrue($this->tableExists('dtb_dash'));
312
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'));
313
314
        $this->em->refresh($this->Plugin);
315
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
316
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
317
318
        return $this;
319
    }
320
321 View Code Duplication
    public function 削除()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
322
    {
323
        $this->ManagePage->ストアプラグイン_削除('Horizon');
324
325
        $this->I->assertFalse($this->tableExists('dtb_dash'));
326
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'));
327
328
        $this->em->refresh($this->Plugin);
329
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
330
        $this->I->assertNull($this->Plugin);
331
332
        return $this;
333
    }
334
335 View Code Duplication
    public function アップデート()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
336
    {
337
        $this->I->reloadPage();
338
        $this->ManagePage->ストアプラグイン_アップデート('Horizon')->アップデート();
339
340
        $this->em->refresh($this->Plugin);
341
        $this->I->assertFalse($this->Plugin->isInitialized());
342
        $this->I->assertFalse($this->Plugin->isEnabled());
343
344
        return $this;
345
    }
346
347
    private function publishPlugin($fileName)
348
    {
349
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
350
    }
351
}
352
353
class Horizon_Local extends Abstract_Plugin
354
{
355
    /** @var AcceptanceTester */
356
    private $I;
357
358
    /** @var PluginManagePage */
359
    private $ManagePage;
360
361
    /** @var Plugin */
362
    private $Plugin;
363
364
    public static function start(AcceptanceTester $I)
365
    {
366
        return new Horizon_Local($I);
367
    }
368
369
    public function __construct(AcceptanceTester $I)
370
    {
371
        parent::__construct();
372
        $this->I = $I;
373
    }
374
375 View Code Duplication
    public function インストール()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
376
    {
377
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
378
            ->アップロード('plugins/Horizon-1.0.0.tgz');
379
380
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
381
382
        $this->I->assertTrue($this->tableExists('dtb_dash'));
383
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'));
384
385
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
386
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
387
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
388
389
        return $this;
390
    }
391
392 View Code Duplication
    public function 有効化()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
393
    {
394
        $this->ManagePage->独自プラグイン_有効化('Horizon');
395
396
        $this->I->assertTrue($this->tableExists('dtb_dash'));
397
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'));
398
399
        $this->em->refresh($this->Plugin);
400
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
401
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
402
403
        return $this;
404
    }
405
406 View Code Duplication
    public function 無効化()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
407
    {
408
        $this->ManagePage->独自プラグイン_無効化('Horizon');
409
410
        $this->I->assertTrue($this->tableExists('dtb_dash'));
411
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'));
412
413
        $this->em->refresh($this->Plugin);
414
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
415
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
416
417
        return $this;
418
    }
419
420 View Code Duplication
    public function 削除()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
421
    {
422
        $this->ManagePage->独自プラグイン_削除('Horizon');
423
424
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
425
426
        $this->I->assertFalse($this->tableExists('dtb_dash'));
427
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'));
428
429
        $this->em->refresh($this->Plugin);
430
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
431
        $this->I->assertNull($this->Plugin);
432
433
        return $this;
434
    }
435
436 View Code Duplication
    public function アップデート()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
437
    {
438
        $this->ManagePage->独自プラグイン_アップデート('Horizon', 'plugins/Horizon-1.0.1.tgz');
439
440
        $this->em->refresh($this->Plugin);
441
        $this->I->assertTrue($this->Plugin->isInitialized());
442
        $this->I->assertFalse($this->Plugin->isEnabled());
443
444
        return $this;
445
    }
446
}