Failed Conditions
Pull Request — 4.0 (#4527)
by chihiro
10:19 queued 05:25
created

codeception/acceptance/EA10PluginCest.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 View Code Duplication
    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 View Code Duplication
    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 View Code Duplication
    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 View Code Duplication
    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 View Code Duplication
    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 View Code Duplication
    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 View Code Duplication
    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
     * @param AcceptanceTester $I
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 Filesystem();
421
        $fs->mkdir($dir);
0 ignored issues
show
The method mkdir() does not seem to exist on object<Codeception\Util\FileSystem>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
422
        $fs->dumpFile($dir.'/index.twig', 'bye');
0 ignored issues
show
The method dumpFile() does not seem to exist on object<Codeception\Util\FileSystem>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
The method remove() does not seem to exist on object<Codeception\Util\FileSystem>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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