Completed
Push — dev/plugin-misc ( e8822a...ffef1c )
by Kiyotaka
27:58 queued 10:28
created

Horizon_Store::既に無効なものを無効化()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 13
loc 13
rs 9.8333
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_enable_update_disable_remove_store(\AcceptanceTester $I)
128
    {
129
        Horizon_Store::start($I)
130
            ->インストール()
131
            ->有効化()
132
            ->アップデート()
133
            ->無効化()
134
            ->削除();
135
    }
136
137
    public function install_enable_update_disable_remove_local(\AcceptanceTester $I)
138
    {
139
        Horizon_Local::start($I)
140
            ->インストール()
141
            ->有効化()
142
            ->アップデート()
143
            ->無効化()
144
            ->削除();
145
    }
146
147
    public function install_update_enable_disable_remove_local(\AcceptanceTester $I)
148
    {
149
        Horizon_Local::start($I)
150
            ->インストール()
151
            ->アップデート()
152
            ->有効化()
153
            ->無効化()
154
            ->削除();
155
    }
156
157
    public function install_update_enable_disable_remove_store(\AcceptanceTester $I)
158
    {
159
        Horizon_Store::start($I)
160
            ->インストール()
161
            ->アップデート()
162
            ->有効化()
163
            ->無効化()
164
            ->削除();
165
    }
166
167
    public function install_enable_enable(\AcceptanceTester $I)
168
    {
169
        Horizon_Store::start($I)
170
            ->インストール()
171
            ->新しいタブで開く()
172
            ->有効化()
173
            ->前のタブに戻る()
174
            ->既に有効なものを有効化();
175
    }
176
177
    public function install_disable_disable(\AcceptanceTester $I)
178
    {
179
        Horizon_Store::start($I)
180
            ->インストール()
181
            ->有効化()
182
            ->新しいタブで開く()
183
            ->無効化()
184
            ->前のタブに戻る()
185
            ->既に無効なものを無効化();
186
    }
187
188
    public function install_assets_local(\AcceptanceTester $I)
189
    {
190
        $this->publishPlugin('Assets-1.0.0.tgz');
191
192
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
193
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
194
195
        $I->assertFileNotExists($assetsPath);
196
        $I->assertFileNotExists($updatedPath);
197
198
        $ManagePage = PluginLocalInstallPage::go($I)->アップロード('plugins/Assets-1.0.0.tgz');
199
        $I->assertFileExists($assetsPath);
200
        $I->assertFileNotExists($updatedPath);
201
202
        $ManagePage->独自プラグイン_有効化('Assets');
203
        $I->assertFileExists($assetsPath);
204
        $I->assertFileNotExists($updatedPath);
205
206
        $ManagePage->独自プラグイン_無効化('Assets');
207
        $I->assertFileExists($assetsPath);
208
        $I->assertFileNotExists($updatedPath);
209
210
        $ManagePage->独自プラグイン_アップデート('Assets', 'plugins/Assets-1.0.1.tgz');
211
        $I->assertFileExists($assetsPath);
212
        $I->assertFileExists($updatedPath);
213
214
        $ManagePage->独自プラグイン_削除('Assets');
215
        $I->assertFileNotExists($assetsPath);
216
        $I->assertFileNotExists($updatedPath);
217
    }
218
219
    public function install_assets_store(\AcceptanceTester $I)
220
    {
221
        // 最初のバージョンを作成
222
        $this->publishPlugin('Assets-1.0.0.tgz');
223
224
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
225
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
226
        $I->assertFileNotExists($assetsPath);
227
        $I->assertFileNotExists($updatedPath);
228
229
        $ManagePage = PluginSearchPage::go($I)
230
            ->入手する('Assets')
231
            ->インストール();
232
        $I->assertFileNotExists($assetsPath);
233
        $I->assertFileNotExists($updatedPath);
234
235
        $ManagePage->ストアプラグイン_有効化('Assets');
236
        $I->assertFileExists($assetsPath);
237
        $I->assertFileNotExists($updatedPath);
238
239
        $ManagePage->ストアプラグイン_無効化('Assets');
240
        $I->assertFileExists($assetsPath);
241
        $I->assertFileNotExists($updatedPath);
242
243
        // 新しいバージョンを作成
244
        $this->publishPlugin('Assets-1.0.1.tgz');
245
246
        $I->reloadPage();
247
        $ManagePage->ストアプラグイン_アップデート('Assets')->アップデート();
248
        $I->assertFileExists($assetsPath);
249
        $I->assertFileExists($updatedPath);
250
251
        $ManagePage->ストアプラグイン_無効化('Assets');
252
        $I->assertFileExists($assetsPath);
253
        $I->assertFileExists($updatedPath);
254
255
        $ManagePage->ストアプラグイン_削除('Assets');
256
        $I->assertFileNotExists($assetsPath);
257
        $I->assertFileNotExists($updatedPath);
258
    }
259
260
    private function publishPlugin($fileName)
261
    {
262
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
263
    }
264
265
    private function tableExists($tableName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
266
    {
267
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
268
    }
269
270
    private function columnExists($tableName, $columnName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
271
    {
272
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
273
    }
274
}
275
276
abstract class Abstract_Plugin
277
{
278
    /** @var AcceptanceTester */
279
    protected $I;
280
281
    /** @var EntityManager */
282
    protected $em;
283
284
    /** @var \Doctrine\DBAL\Connection */
285
    protected $conn;
286
287
    /** @var PluginRepository */
288
    protected $pluginRepository;
289
290
    /** @var EccubeConfig */
291
    protected $config;
292
293
    /**
294
     * Abstract_Plugin constructor.
295
     */
296 View Code Duplication
    public function __construct(\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...
297
    {
298
        $this->I = $I;
299
        $this->em = Fixtures::get('entityManager');
300
        $this->conn = $this->em->getConnection();
301
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
302
        $this->config = Fixtures::get('config');
303
    }
304
305
    protected function tableExists($tableName)
306
    {
307
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
308
    }
309
310
    protected function columnExists($tableName, $columnName)
311
    {
312
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
313
    }
314
315
    public function 新しいタブで開く()
316
    {
317
        $this->I->executeJS("window.open(location.href, 'other')");
318
        $this->I->switchToWindow('other');
319
        return $this;
320
    }
321
322
    public function 前のタブに戻る()
323
    {
324
        $this->I->switchToPreviousTab();
325
        return $this;
326
    }
327
}
328
329
class Horizon_Store extends Abstract_Plugin
330
{
331
    /** @var PluginManagePage */
332
    private $ManagePage;
333
334
    /** @var Plugin */
335
    private $Plugin;
336
337
    private $initialized = false;
338
339
    public static function start(AcceptanceTester $I)
340
    {
341
        return new Horizon_Store($I);
342
    }
343
344
    public function __construct(AcceptanceTester $I)
345
    {
346
        parent::__construct($I);
347
    }
348
349 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...
350
    {
351
        $this->publishPlugin('Horizon-1.0.0.tgz');
352
        /*
353
         * インストール
354
         */
355
        $this->ManagePage = PluginSearchPage::go($this->I)
356
            ->入手する('Horizon')
357
            ->インストール();
358
359
        $this->I->assertFalse($this->tableExists('dtb_dash'), 'テーブルがない');
360
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがない');
361
362
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
363
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
364
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
365
366
        return $this;
367
    }
368
369 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...
370
    {
371
        $this->ManagePage->ストアプラグイン_有効化('Horizon');
372
373
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
374
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
375
376
        $this->em->refresh($this->Plugin);
377
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
378
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
379
380
        $this->initialized = true;
381
        return $this;
382
    }
383
384 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...
385
    {
386
        $this->ManagePage->ストアプラグイン_有効化('Horizon', '「ホライゾン」は既に有効です。');
387
388
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
389
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
390
391
        $this->em->refresh($this->Plugin);
392
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
393
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
394
395
        $this->initialized = true;
396
397
398
        return $this;
399
    }
400
401 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...
402
    {
403
        $this->ManagePage->ストアプラグイン_無効化('Horizon');
404
405
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
406
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
407
408
        $this->em->refresh($this->Plugin);
409
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
410
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
411
412
        return $this;
413
    }
414
415 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...
416
    {
417
        $this->ManagePage->ストアプラグイン_無効化('Horizon', '「ホライゾン」は既に無効です。');
418
419
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
420
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
421
422
        $this->em->refresh($this->Plugin);
423
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
424
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
425
426
        return $this;
427
    }
428
429 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...
430
    {
431
        $this->ManagePage->ストアプラグイン_削除('Horizon');
432
433
        $this->I->assertFalse($this->tableExists('dtb_dash'), 'テーブルが消えている');
434
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'), 'カラムが消えている');
435
436
        $this->em->refresh($this->Plugin);
437
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
438
        $this->I->assertNull($this->Plugin, '削除されている');
439
440
        return $this;
441
    }
442
443
    public function アップデート()
444
    {
445
        $this->publishPlugin('Horizon-1.0.1.tgz');
446
447
        $this->I->reloadPage();
448
        $this->ManagePage->ストアプラグイン_アップデート('Horizon')->アップデート();
449
450
        $this->em->refresh($this->Plugin);
451
452
        if ($this->initialized) {
453
            $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
454
            $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
455
        } else {
456
            $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
457
            $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
458
        }
459
460
        return $this;
461
    }
462
463
    private function publishPlugin($fileName)
464
    {
465
        $published = copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
466
        $this->I->assertTrue($published, "公開できた ${fileName}");
467
        $output = [];
468
        exec("ls -ltra repos/", $output);
469
        echo implode(PHP_EOL, $output).PHP_EOL;
470
    }
471
}
472
473
class Horizon_Local extends Abstract_Plugin
474
{
475
    /** @var PluginManagePage */
476
    private $ManagePage;
477
478
    /** @var Plugin */
479
    private $Plugin;
480
481
    private $enabled = false;
482
483
    public static function start(AcceptanceTester $I)
484
    {
485
        return new Horizon_Local($I);
486
    }
487
488
    public function __construct(AcceptanceTester $I)
489
    {
490
        parent::__construct($I);
491
    }
492
493 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...
494
    {
495
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
496
            ->アップロード('plugins/Horizon-1.0.0.tgz');
497
498
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
499
500
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
501
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
502
503
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
504
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
505
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
506
507
        return $this;
508
    }
509
510 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...
511
    {
512
        $this->ManagePage->独自プラグイン_有効化('Horizon');
513
514
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
515
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
516
517
        $this->em->refresh($this->Plugin);
518
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
519
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
520
521
        $this->enabled = true;
522
        return $this;
523
    }
524
525 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...
526
    {
527
        $this->ManagePage->独自プラグイン_無効化('Horizon');
528
529
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
530
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
531
532
        $this->em->refresh($this->Plugin);
533
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
534
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
535
536
        return $this;
537
    }
538
539 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...
540
    {
541
        $this->ManagePage->独自プラグイン_削除('Horizon');
542
543
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
544
545
        $this->I->assertFalse($this->tableExists('dtb_dash'), 'テーブルが削除されている');
546
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'), 'カラムが削除されている');
547
548
        $this->em->refresh($this->Plugin);
549
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
550
        $this->I->assertNull($this->Plugin, '削除されている');
551
552
        return $this;
553
    }
554
555
    public function アップデート()
556
    {
557
        $this->ManagePage->独自プラグイン_アップデート('Horizon', 'plugins/Horizon-1.0.1.tgz');
558
559
        $this->em->refresh($this->Plugin);
560
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
561
562
        if ($this->enabled) {
563
            $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
564
        } else {
565
            $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
566
        }
567
568
        return $this;
569
    }
570
}