Failed Conditions
Pull Request — 4.0 (#4660)
by
unknown
04:35
created

Emperor_Store   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 21.05 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 8
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.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\CacheManagePage;
21
use Page\Admin\PluginLocalInstallPage;
22
use Page\Admin\PluginManagePage;
23
use Page\Admin\PluginSearchPage;
24
25
class EA10PluginCest
26
{
27
    /** @var EntityManager */
28
    private $em;
29
30
    /** @var \Doctrine\DBAL\Connection */
31
    private $conn;
32
33
    /** @var PluginRepository */
34
    private $pluginRepository;
35
36
    /** @var EccubeConfig */
37
    private $config;
38
39
    public function _before(\AcceptanceTester $I)
40
    {
41
        $I->loginAsAdmin();
42
43
        $this->em = Fixtures::get('entityManager');
44
        $this->conn = $this->em->getConnection();
45
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
46
        $this->config = Fixtures::get('config');
47
        FileSystem::doEmptyDir('repos');
48
    }
49
50
    public function test_install_enable_disable_remove_store(\AcceptanceTester $I)
51
    {
52
        Horizon_Store::start($I)
53
            ->インストール()
54
            ->有効化()
55
            ->無効化()
56
            ->削除();
57
    }
58
59
    public function test_install_enable_disable_remove_local(\AcceptanceTester $I)
60
    {
61
        Horizon_Store::start($I)
62
            ->インストール()
63
            ->有効化()
64
            ->無効化()
65
            ->削除();
66
    }
67
68
    public function test_install_enable_disable_enable_disable_remove_store(\AcceptanceTester $I)
69
    {
70
        Horizon_Store::start($I)
71
            ->インストール()
72
            ->有効化()
73
            ->無効化()
74
            ->有効化()
75
            ->無効化()
76
            ->削除();
77
    }
78
79
    public function test_install_enable_disable_enable_disable_remove_local(\AcceptanceTester $I)
80
    {
81
        Horizon_Local::start($I)
82
            ->インストール()
83
            ->有効化()
84
            ->無効化()
85
            ->有効化()
86
            ->無効化()
87
            ->削除();
88
    }
89
90
    public function test_install_remove_local(\AcceptanceTester $I)
91
    {
92
        Horizon_Local::start($I)
93
            ->インストール()
94
            ->削除();
95
    }
96
97
    public function test_install_remove_store(\AcceptanceTester $I)
98
    {
99
        Horizon_Store::start($I)
100
            ->インストール()
101
            ->削除();
102
    }
103
104
    public function test_install_update_remove_store(\AcceptanceTester $I)
105
    {
106
        Horizon_Store::start($I)
107
            ->インストール()
108
            ->アップデート()
109
            ->削除();
110
    }
111
112
    public function test_install_update_remove_local(\AcceptanceTester $I)
113
    {
114
        Horizon_Local::start($I)
115
            ->インストール()
116
            ->アップデート()
117
            ->削除();
118
    }
119
120
    public function test_install_enable_disable_update_enable_disable_remove_local(\AcceptanceTester $I)
121
    {
122
        Horizon_Local::start($I)
123
            ->インストール()
124
            ->有効化()
125
            ->無効化()
126
            ->アップデート()
127
            ->有効化()
128
            ->無効化()
129
            ->削除();
130
    }
131
132
    public function test_install_enable_disable_update_enable_disable_remove_store(\AcceptanceTester $I)
133
    {
134
        Horizon_Store::start($I)
135
            ->インストール()
136
            ->有効化()
137
            ->無効化()
138
            ->アップデート()
139
            ->有効化()
140
            ->無効化()
141
            ->削除();
142
    }
143
144
    public function test_install_enable_update_disable_remove_store(\AcceptanceTester $I)
145
    {
146
        Horizon_Store::start($I)
147
            ->インストール()
148
            ->有効化()
149
            ->アップデート()
150
            ->削除();
151
    }
152
153
    public function test_install_enable_update_disable_remove_local(\AcceptanceTester $I)
154
    {
155
        Horizon_Local::start($I)
156
            ->インストール()
157
            ->有効化()
158
            ->アップデート()
159
            ->無効化()
160
            ->削除();
161
    }
162
163
    public function test_install_update_enable_disable_remove_local(\AcceptanceTester $I)
164
    {
165
        Horizon_Local::start($I)
166
            ->インストール()
167
            ->アップデート()
168
            ->有効化()
169
            ->無効化()
170
            ->削除();
171
    }
172
173
    public function test_install_update_enable_disable_remove_store(\AcceptanceTester $I)
174
    {
175
        Horizon_Store::start($I)
176
            ->インストール()
177
            ->アップデート()
178
            ->有効化()
179
            ->無効化()
180
            ->削除();
181
    }
182
183
    public function test_install_enable_enable(\AcceptanceTester $I)
184
    {
185
        Horizon_Store::start($I)
186
            ->インストール()
187
            ->新しいタブで開く()
188
            ->有効化()
189
            ->前のタブに戻る()
190
            ->既に有効なものを有効化();
191
    }
192
193
    public function test_install_disable_disable(\AcceptanceTester $I)
194
    {
195
        Horizon_Store::start($I)
196
            ->インストール()
197
            ->有効化()
198
            ->新しいタブで開く()
199
            ->無効化()
200
            ->前のタブに戻る()
201
            ->既に無効なものを無効化();
202
    }
203
204
    public function test_install_assets_local(\AcceptanceTester $I)
205
    {
206
        $this->publishPlugin('Assets-1.0.0.tgz');
207
208
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
209
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
210
211
        $I->assertFileNotExists($assetsPath);
212
        $I->assertFileNotExists($updatedPath);
213
214
        $ManagePage = PluginLocalInstallPage::go($I)->アップロード('plugins/Assets-1.0.0.tgz');
215
        $I->assertFileExists($assetsPath);
216
        $I->assertFileNotExists($updatedPath);
217
218
        $ManagePage->独自プラグイン_有効化('Assets');
219
        $I->assertFileExists($assetsPath);
220
        $I->assertFileNotExists($updatedPath);
221
222
        $ManagePage->独自プラグイン_無効化('Assets');
223
        $I->assertFileExists($assetsPath);
224
        $I->assertFileNotExists($updatedPath);
225
226
        $ManagePage->独自プラグイン_アップデート('Assets', 'plugins/Assets-1.0.1.tgz');
227
        $I->assertFileExists($assetsPath);
228
        $I->assertFileExists($updatedPath);
229
230
        $ManagePage->独自プラグイン_削除('Assets');
231
        $I->assertFileNotExists($assetsPath);
232
        $I->assertFileNotExists($updatedPath);
233
    }
234
235
    public function test_install_assets_store(\AcceptanceTester $I)
236
    {
237
        // 最初のバージョンを作成
238
        $this->publishPlugin('Assets-1.0.0.tgz');
239
240
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
241
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
242
        $I->assertFileNotExists($assetsPath);
243
        $I->assertFileNotExists($updatedPath);
244
245
        $ManagePage = PluginSearchPage::go($I)
246
            ->入手する('Assets')
247
            ->インストール();
248
        $I->assertFileNotExists($assetsPath);
249
        $I->assertFileNotExists($updatedPath);
250
251
        $ManagePage->ストアプラグイン_有効化('Assets');
252
        $I->assertFileExists($assetsPath);
253
        $I->assertFileNotExists($updatedPath);
254
255
        $ManagePage->ストアプラグイン_無効化('Assets');
256
        $I->assertFileExists($assetsPath);
257
        $I->assertFileNotExists($updatedPath);
258
259
        // 新しいバージョンを作成
260
        $this->publishPlugin('Assets-1.0.1.tgz');
261
262
        $I->reloadPage();
263
        $ManagePage->ストアプラグイン_アップデート('Assets')->アップデート();
264
        $I->assertFileExists($assetsPath);
265
        $I->assertFileExists($updatedPath);
266
267
        $ManagePage->ストアプラグイン_削除('Assets');
268
        $I->assertFileNotExists($assetsPath);
269
        $I->assertFileNotExists($updatedPath);
270
    }
271
272
    public function test_extend_same_table_store(\AcceptanceTester $I)
273
    {
274
        $Horizon = Horizon_Store::start($I);
275
        $Boomerang = Boomerang_Store::start($I);
276
277
        $Horizon->インストール()->有効化();
278
        $Boomerang->インストール()->有効化();
279
280
        $Horizon->検証()->無効化()->削除();
281
        $Boomerang->検証()->無効化()->削除();
282
    }
283
284
    public function test_extend_same_table_disabled_remove_store(\AcceptanceTester $I)
285
    {
286
        $Horizon = Horizon_Store::start($I);
287
        $Boomerang = Boomerang_Store::start($I);
288
289
        $Horizon->インストール()->有効化()->無効化();
290
        $Boomerang->インストール()->有効化()->無効化();
291
292
        $Horizon->検証()->削除();
293
        $Boomerang->検証()->削除();
294
    }
295
296
    public function test_extend_same_table_local(\AcceptanceTester $I)
297
    {
298
        $Horizon = Horizon_Local::start($I);
299
        $Boomerang = Boomerang_Local::start($I);
300
301
        $Horizon->インストール()->有効化();
302
        $Boomerang->インストール()->有効化();
303
304
        $Horizon->検証()->無効化()->削除();
305
        $Boomerang->検証()->無効化()->削除();
306
    }
307
308
    public function test_extend_same_table_disabled_remove_local(\AcceptanceTester $I)
309
    {
310
        $Horizon = Horizon_Local::start($I);
311
        $Boomerang = Boomerang_Local::start($I);
312
313
        $Horizon->インストール()->有効化()->無効化();
314
        $Boomerang->インストール()->有効化()->無効化();
315
316
        $Horizon->検証()->削除();
317
        $Boomerang->検証()->削除();
318
    }
319
320
    public function test_extend_same_table_crossed_store(\AcceptanceTester $I)
321
    {
322
        $Horizon = Horizon_Store::start($I);
323
        $Boomerang = Boomerang_Store::start($I);
324
325
        $Horizon->インストール()->有効化()->無効化();
326
        $Boomerang->インストール()->有効化();
327
328
        $Horizon->検証()->削除();
329
        $Boomerang->検証()->無効化()->削除();
330
    }
331
332
    public function test_extend_same_table_crossed_local(\AcceptanceTester $I)
333
    {
334
        $Horizon = Horizon_Local::start($I);
335
        $Boomerang = Boomerang_Local::start($I);
336
337
        $Horizon->インストール()->有効化()->無効化();
338
        $Boomerang->インストール()->有効化();
339
340
        $Horizon->検証()->削除();
341
        $Boomerang->検証()->無効化()->削除();
342
    }
343
344
    public function test_dependency_each_install_plugin(\AcceptanceTester $I)
345
    {
346
        $Horizon = Horizon_Store::start($I);
347
        $Emperor = Emperor_Store::start($I);
348
349
        $Horizon->インストール()->有効化();
350
        $Emperor->インストール()->有効化();
351
    }
352
353
    public function test_dependency_plugin_install(\AcceptanceTester $I)
354
    {
355
        $Horizon = Horizon_Store::start($I);
356
        $Emperor = Emperor_Store::start($I, $Horizon);
357
358
        $Emperor->インストール()
359
            ->依存より先に有効化();
360
361
        $Horizon->有効化();
362
363
        $Emperor->有効化();
364
365
        $Horizon->依存されているのが有効なのに無効化();
366
        $Emperor->無効化();
367
        $Horizon->無効化();
368
369
        $Horizon->依存されているのが削除されていないのに削除();
370
        $Emperor->削除();
371
        $Horizon->削除();
372
    }
373
374
    public function test_dependency_plugin_update(\AcceptanceTester $I)
375
    {
376
        $Horizon = Horizon_Store::start($I);
377
        $Emperor = Emperor_Store::start($I, $Horizon);
378
379
        $Emperor->インストール();
380
381
        $Horizon->検証()
382
            ->有効化();
383
384
        $Emperor
385
            ->有効化()
386
            ->無効化()
387
            ->アップデート();
388
389
        $Horizon->検証();
390
    }
391
392
    public function test_install_error(\AcceptanceTester $I)
393
    {
394
        $this->publishPlugin('InstallError.tgz');
395
        $Horizon = Horizon_Store::start($I);
396
397
        PluginSearchPage::go($I)
398
            ->入手する('InstallError')
399
            ->インストール('システムエラーが発生しました。');
400
401
        // エラー後に他のプラグインがインストールできる
402
        $Horizon->インストール();
403
    }
404
405
    /**
406
     * @see https://github.com/EC-CUBE/ec-cube/pull/4527
407
     */
408
    public function test_template_overwrite(\AcceptanceTester $I)
409
    {
410
        $plugin = new Local_Plugin($I, 'Template');
411
        $plugin->インストール();
412
        $plugin->有効化();
413
414
        // テンプレートの確認
415
        $I->amOnPage('/template');
416
        $I->see('hello');
417
418
        // テンプレートをapp/template/plugin/[Plugin Code]に設置
419
        $dir = $this->config->get('eccube_theme_app_dir').'/plugin/Template';
420
        $fs = new \Symfony\Component\Filesystem\Filesystem();
421
        $fs->mkdir($dir);
422
        $fs->dumpFile($dir.'/index.twig', 'bye');
423
424
        // キャッシュ削除すると反映される
425
        $page = CacheManagePage::go($I);
426
        $page->キャッシュ削除();
427
428
        // 上書きされていることを確認
429
        $I->amOnPage('/template');
430
        $I->see('bye');
431
432
        $I->amOnPage('/'.$this->config->get('eccube_admin_route').'/store/plugin');
433
        $plugin->無効化();
434
        $plugin->削除();
435
436
        $fs->remove($dir);
437
    }
438
439
<<<<<<< HEAD
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_SL, expecting T_FUNCTION or T_CONST
Loading history...
440
    public function test_bundle_install_enable_disable_remove_store(\AcceptanceTester $I)
441
    {
442
        $Bundle = Bundle_Store::start($I);
443
        $Bundle->インストール()
444
            ->有効化()
445
            ->無効化()
446
            ->削除();
447
    }
448
449
    public function test_bundle_install_update_enable_disable_remove_store(\AcceptanceTester $I)
450
    {
451
        $Bundle = Bundle_Store::start($I);
452
        $Bundle->インストール()
453
            ->有効化()
454
            ->アップデート()
455
            ->有効化()
456
            ->無効化()
457
            ->削除();
458
=======
459
    /**
460
     * @see https://github.com/EC-CUBE/ec-cube/pull/4638
461
     */
462
    public function test_enhance_plugin_entity(\AcceptanceTester $I)
463
    {
464
        $Boomerang = Boomerang_Store::start($I)
465
            ->インストール()
466
            ->有効化()
467
            ->カート作成();
468
469
        $I->see('[1]');
470
471
        Boomerang10_Store::start($I, $Boomerang)
472
            ->インストール()
473
            ->有効化();
474
475
        $Boomerang->カート一覧();
476
        $I->see('[1]');
477
>>>>>>> 9c8a0d2fe53739ed81bdc60aa82cdf3779666c53
478
    }
479
480
    private function publishPlugin($fileName)
481
    {
482
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
483
    }
484
}
485
486
abstract class Abstract_Plugin
487
{
488
    /** @var AcceptanceTester */
489
    protected $I;
490
491
    /** @var EntityManager */
492
    protected $em;
493
494
    /** @var \Doctrine\DBAL\Connection */
495
    protected $conn;
496
497
    /** @var PluginRepository */
498
    protected $pluginRepository;
499
500
    /** @var EccubeConfig */
501
    protected $config;
502
503
    protected $initialized = false;
504
505
    protected $enabled = false;
506
507
    protected $removed = false;
508
509
    protected $tables = [];
510
511
    protected $columns = [];
512
513
    protected $traits = [];
514
515
    public function __construct(\AcceptanceTester $I)
516
    {
517
        $this->I = $I;
518
        $this->em = Fixtures::get('entityManager');
519
        $this->conn = $this->em->getConnection();
520
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
521
        $this->config = Fixtures::get('config');
522
    }
523
524
    public function tableExists()
525
    {
526
        foreach ($this->tables as $table) {
527
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '".$table."';")->fetch()['count'] > 0;
528
            $this->I->assertTrue($exists, 'テーブルがあるはず '.$table);
529
        }
530
    }
531
532
    public function tableNotExists()
533
    {
534
        foreach ($this->tables as $table) {
535
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '".$table."';")->fetch()['count'] > 0;
536
            $this->I->assertFalse($exists, 'テーブルがないはず '.$table);
537
        }
538
    }
539
540
    public function columnExists()
541
    {
542
        foreach ($this->columns as $column) {
543
            list($tableName, $columnName) = explode('.', $column);
544
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
545
            $this->I->assertTrue($exists, 'カラムがあるはず '.$column);
546
        }
547
    }
548
549
    public function columnNotExists()
550
    {
551
        foreach ($this->columns as $column) {
552
            list($tableName, $columnName) = explode('.', $column);
553
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
554
            $this->I->assertFalse($exists, 'カラムがないはず '.$column);
555
        }
556
    }
557
558
    public function traitExists()
559
    {
560
        foreach ($this->traits as $trait => $target) {
561
            $this->I->assertContains($trait, file_get_contents($this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php'), 'Traitがあるはず '.$trait);
562
        }
563
    }
564
565
    public function traitNotExists()
566
    {
567
        foreach ($this->traits as $trait => $target) {
568
            $file = $this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php';
569
            if (file_exists($file)) {
570
                $this->I->assertNotContains($trait, file_get_contents($file), 'Traitがないはず '.$trait);
571
            } else {
572
                $this->I->assertTrue(true, 'Traitがないはず');
573
            }
574
        }
575
    }
576
577
    public function 新しいタブで開く()
578
    {
579
        $this->I->executeJS("window.open(location.href, 'other')");
580
        $this->I->switchToWindow('other');
581
582
        return $this;
583
    }
584
585
    public function 前のタブに戻る()
586
    {
587
        $this->I->switchToPreviousTab();
588
589
        return $this;
590
    }
591
592
    public function 検証()
593
    {
594
        $this->I->wait(1);
595
        if ($this->initialized) {
596
            $this->tableExists();
597
            $this->columnExists();
598
        } else {
599
            $this->tableNotExists();
600
            $this->columnNotExists();
601
        }
602
603
        if ($this->enabled) {
604
            $this->traitExists();
605
        } else {
606
            $this->traitNotExists();
607
        }
608
609
        return $this;
610
    }
611
}
612
613
class Store_Plugin extends Abstract_Plugin
614
{
615
    /** @var PluginManagePage */
616
    protected $ManagePage;
617
618
    /** @var Plugin */
619
    protected $Plugin;
620
621
    protected $code;
622
623
    /** @var Store_Plugin */
624
    protected $dependency;
625
626
    public function __construct(AcceptanceTester $I, $code, Store_Plugin $dependency = null)
627
    {
628
        parent::__construct($I);
629
        $this->code = $code;
630
        $this->publishPlugin($this->code.'-1.0.0.tgz');
631
        if ($dependency) {
632
            $this->dependency = $dependency;
633
            $this->ManagePage = $dependency->ManagePage;
634
            $this->Plugin = $this->pluginRepository->findByCode($code);
635
        }
636
    }
637
638
    public function インストール()
639
    {
640
        /*
641
         * インストール
642
         */
643
        $this->ManagePage = PluginSearchPage::go($this->I)
644
            ->入手する($this->code)
645
            ->インストール();
646
647
        $this->検証();
648
649
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
650
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
651
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
652
653
        if ($this->dependency) {
654
            $this->dependency->ManagePage = $this->ManagePage;
655
            $this->dependency->Plugin = $this->pluginRepository->findByCode($this->dependency->code);
656
        }
657
658
        return $this;
659
    }
660
661
    public function 有効化()
662
    {
663
        $this->ManagePage->ストアプラグイン_有効化($this->code);
664
665
        $this->initialized = true;
666
        $this->enabled = true;
667
668
        $this->検証();
669
670
        $this->em->refresh($this->Plugin);
671
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
672
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
673
674
        return $this;
675
    }
676
677
    public function 既に有効なものを有効化()
678
    {
679
        $this->ManagePage->ストアプラグイン_有効化($this->code, '既に有効です。');
680
681
        $this->initialized = true;
682
        $this->enabled = true;
683
684
        $this->検証();
685
686
        $this->em->refresh($this->Plugin);
687
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
688
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
689
690
        return $this;
691
    }
692
693
    public function 無効化()
694
    {
695
        $this->ManagePage->ストアプラグイン_無効化($this->code);
696
697
        $this->enabled = false;
698
699
        $this->検証();
700
701
        $this->em->refresh($this->Plugin);
702
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
703
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
704
705
        return $this;
706
    }
707
708
    public function 既に無効なものを無効化()
709
    {
710
        $this->ManagePage->ストアプラグイン_無効化($this->code, '既に無効です。');
711
712
        $this->enabled = false;
713
714
        $this->検証();
715
716
        $this->em->refresh($this->Plugin);
717
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
718
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
719
720
        return $this;
721
    }
722
723
    public function 削除()
724
    {
725
        $this->ManagePage->ストアプラグイン_削除($this->code);
726
727
        $this->initialized = false;
728
        $this->enabled = false;
729
730
        $this->検証();
731
732
        $this->em->refresh($this->Plugin);
733
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
734
        $this->I->assertNull($this->Plugin, '削除されている');
735
736
        return $this;
737
    }
738
739
    public function アップデート()
740
    {
741
        $this->publishPlugin($this->code.'-1.0.1.tgz');
742
743
        $this->I->reloadPage();
744
        $this->ManagePage->ストアプラグイン_アップデート($this->code)->アップデート();
745
746
        $this->initialized = true;
747
        $this->enabled = false;
748
749
        $this->検証();
750
751
        $this->em->refresh($this->Plugin);
752
        $this->I->assertEquals($this->initialized, $this->Plugin->isInitialized(), '初期化');
753
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
754
755
        return $this;
756
    }
757
758
    protected function publishPlugin($fileName)
759
    {
760
        $published = copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
761
        $this->I->assertTrue($published, "公開できた ${fileName}");
762
    }
763
}
764
765
class Local_Plugin extends Abstract_Plugin
766
{
767
    /** @var PluginManagePage */
768
    private $ManagePage;
769
770
    /** @var Plugin */
771
    private $Plugin;
772
773
    /** @var string */
774
    private $code;
775
776
    public function __construct(AcceptanceTester $I, $code)
777
    {
778
        parent::__construct($I);
779
        $this->code = $code;
780
    }
781
782
    public function インストール()
783
    {
784
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
785
            ->アップロード('plugins/'.$this->code.'-1.0.0.tgz');
786
787
        $this->initialized = true;
788
789
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
790
791
        $this->検証();
792
793
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
794
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
795
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
796
797
        return $this;
798
    }
799
800
    public function 有効化()
801
    {
802
        $this->ManagePage->独自プラグイン_有効化($this->code);
803
804
        $this->enabled = true;
805
806
        $this->検証();
807
808
        $this->em->refresh($this->Plugin);
809
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
810
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
811
812
        return $this;
813
    }
814
815
    public function 無効化()
816
    {
817
        $this->ManagePage->独自プラグイン_無効化($this->code);
818
819
        $this->enabled = false;
820
821
        $this->検証();
822
823
        $this->em->refresh($this->Plugin);
824
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
825
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
826
827
        return $this;
828
    }
829
830
    public function 削除()
831
    {
832
        $this->ManagePage->独自プラグイン_削除($this->code);
833
834
        $this->initialized = false;
835
        $this->enabled = false;
836
837
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
838
839
        $this->検証();
840
841
        $this->em->refresh($this->Plugin);
842
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
843
        $this->I->assertNull($this->Plugin, '削除されている');
844
845
        return $this;
846
    }
847
848
    public function アップデート()
849
    {
850
        $this->ManagePage->独自プラグイン_アップデート($this->code, 'plugins/'.$this->code.'-1.0.1.tgz');
851
852
        $this->検証();
853
854
        $this->em->refresh($this->Plugin);
855
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
856
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
857
858
        return $this;
859
    }
860
}
861
862
class Horizon_Local extends Local_Plugin
863
{
864
    public function __construct(AcceptanceTester $I)
865
    {
866
        parent::__construct($I, 'Horizon');
867
        $this->tables[] = 'dtb_dash';
868
        $this->columns[] = 'dtb_cart.is_horizon';
869
        $this->columns[] = 'dtb_cart.dash_id';
870
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
871
    }
872
873
    public function アップデート()
874
    {
875
        // アップデートで新たしいカラムが追加される
876
        $this->columns[] = 'dtb_dash.new_column';
877
        return parent::アップデート();
878
    }
879
880
    public static function start(AcceptanceTester $I)
881
    {
882
        return new self($I);
883
    }
884
}
885
886
class Horizon_Store extends Store_Plugin
887
{
888
    public function __construct(AcceptanceTester $I)
889
    {
890
        parent::__construct($I, 'Horizon');
891
        $this->tables[] = 'dtb_dash';
892
        $this->columns[] = 'dtb_cart.is_horizon';
893
        $this->columns[] = 'dtb_cart.dash_id';
894
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
895
    }
896
897
    public function アップデート()
898
    {
899
        // アップデートで新たしいカラムが追加される
900
        $this->columns[] = 'dtb_dash.new_column';
901
        return parent::アップデート();
902
    }
903
904
    public static function start(AcceptanceTester $I)
905
    {
906
        $result = new self($I);
907
908
        return $result;
909
    }
910
911
    public function 依存されているのが有効なのに無効化()
912
    {
913
        $this->ManagePage->ストアプラグイン_無効化($this->code, '「ホライゾン」を無効にする前に、「エンペラー」を無効にしてください。');
914
915
        $this->検証();
916
917
        $this->em->refresh($this->Plugin);
918
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されているはず');
919
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されているはず');
920
921
        return $this;
922
    }
923
924
    public function 依存されているのが削除されていないのに削除()
925
    {
926
        $this->ManagePage->ストアプラグイン_削除($this->code, '「エンペラー」が「ホライゾン」に依存しているため削除できません。');
927
928
        $this->検証();
929
930
        $this->em->refresh($this->Plugin);
931
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
932
        $this->I->assertNotNull($this->Plugin, '削除されていない');
933
934
        return $this;
935
    }
936
}
937
938
class Emperor_Store extends Store_Plugin
939
{
940
    public function __construct(AcceptanceTester $I, Store_Plugin $dependency = null)
941
    {
942
        parent::__construct($I, 'Emperor', $dependency);
943
        $this->publishPlugin('Horizon-1.0.0.tgz');
944
        $this->tables[] = 'dtb_foo';
945
        $this->columns[] = 'dtb_cart.foo_id';
946
        $this->traits['\Plugin\Emperor\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
947
    }
948
949
    public static function start(AcceptanceTester $I, Store_Plugin $dependency = null)
950
    {
951
        return new self($I, $dependency);
952
    }
953
954
    public function アップデート()
955
    {
956
        $this->tables = ['dtb_bar'];
957
        $this->columns = ['dtb_cart.bar_id'];
958
        $this->traits['\Plugin\Emperor\Entity\Cart2Trait'] = 'src/Eccube/Entity/Cart';
959
960
        return parent::アップデート();
961
    }
962
963
    public function 依存より先に有効化()
964
    {
965
        $this->ManagePage->ストアプラグイン_有効化($this->code, '「ホライゾン」を先に有効化してください。');
966
967
        $this->検証();
968
969
        $this->em->refresh($this->Plugin);
970
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていないはず');
971
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていないはず');
972
973
        return $this;
974
    }
975
}
976
977
class Boomerang_Store extends Store_Plugin
978
{
979
    public function __construct(AcceptanceTester $I)
980
    {
981
        parent::__construct($I, 'Boomerang');
982
        $this->tables[] = 'dtb_bar';
983
        $this->columns[] = 'dtb_cart.is_boomerang';
984
        $this->columns[] = 'dtb_cart.bar_id';
985
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
986
    }
987
988
    public static function start(AcceptanceTester $I)
989
    {
990
        return new self($I);
991
    }
992
993
    public function カート一覧()
994
    {
995
        $this->I->amOnPage('/boomerang');
996
    }
997
998
    public function カート作成()
999
    {
1000
        $this->I->amOnPage('/boomerang/new');
1001
        $this->I->seeCurrentUrlMatches('/^\/boomerang$/');
1002
        return $this;
1003
    }
1004
}
1005
1006
class Boomerang10_Store extends Store_Plugin
1007
{
1008
    public function __construct(AcceptanceTester $I, Store_Plugin $dependency = null)
1009
    {
1010
        parent::__construct($I, 'Boomerang10', $dependency);
1011
        $this->columns[] = 'dtb_bar.mail';
1012
    }
1013
1014
    public static function start(AcceptanceTester $I, Store_Plugin $dependency = null)
1015
    {
1016
        return new self($I, $dependency = null);
1017
    }
1018
}
1019
1020
class Boomerang_Local extends Local_Plugin
1021
{
1022
    public function __construct(AcceptanceTester $I)
1023
    {
1024
        parent::__construct($I, 'Boomerang');
1025
        $this->tables[] = 'dtb_bar';
1026
        $this->columns[] = 'dtb_cart.is_boomerang';
1027
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
1028
    }
1029
1030
    public static function start(AcceptanceTester $I)
1031
    {
1032
        return new self($I);
1033
    }
1034
}
1035
1036
class Bundle_Store extends Store_Plugin
1037
{
1038
    public function __construct(AcceptanceTester $I)
1039
    {
1040
        parent::__construct($I, 'Bundle');
1041
        $this->tables[] = 'oauth2_client';
1042
        $this->tables[] = 'oauth2_refresh_token';
1043
        $this->tables[] = 'oauth2_access_token';
1044
        $this->tables[] = 'oauth2_authorization_code';
1045
    }
1046
1047
    public function 有効化()
1048
    {
1049
        parent::有効化();
1050
1051
        return $this;
1052
    }
1053
1054
    public function 無効化()
1055
    {
1056
        parent::無効化();
1057
1058
        return $this;
1059
    }
1060
    public static function start(AcceptanceTester $I)
1061
    {
1062
        return new self($I);
1063
    }
1064
}
1065