Completed
Push — 4.0 ( 877ec9...cd9754 )
by Kiyotaka
04:46 queued 10s
created

Bundle_Store   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A 有効化() 0 6 1
A 無効化() 0 6 1
A start() 0 4 1
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 View Code Duplication
    public function test_extend_same_table_store(\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...
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)
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...
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)
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
        $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)
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...
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)
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...
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)
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...
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
    /**
440
     * @see https://github.com/EC-CUBE/ec-cube/pull/4638
441
     */
442
    public function test_enhance_plugin_entity(\AcceptanceTester $I)
443
    {
444
        $Boomerang = Boomerang_Store::start($I)
445
            ->インストール()
446
            ->有効化()
447
            ->カート作成();
448
449
        $I->see('[1]');
450
451
        Boomerang10_Store::start($I, $Boomerang)
452
            ->インストール()
453
            ->有効化();
454
455
        $Boomerang->カート一覧();
456
        $I->see('[1]');
457
    }
458
459
    public function test_bundle_install_enable_disable_remove_store(\AcceptanceTester $I)
460
    {
461
        $Bundle = Bundle_Store::start($I);
462
        $Bundle->インストール()
463
            ->有効化()
464
            ->無効化()
465
            ->削除();
466
    }
467
468
    public function test_bundle_install_update_enable_disable_remove_store(\AcceptanceTester $I)
469
    {
470
        $Bundle = Bundle_Store::start($I);
471
        $Bundle->インストール()
472
            ->有効化()
473
            ->アップデート()
474
            ->有効化()
475
            ->無効化()
476
            ->削除();
477
    }
478
479
    private function publishPlugin($fileName)
480
    {
481
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
482
    }
483
}
484
485
abstract class Abstract_Plugin
486
{
487
    /** @var AcceptanceTester */
488
    protected $I;
489
490
    /** @var EntityManager */
491
    protected $em;
492
493
    /** @var \Doctrine\DBAL\Connection */
494
    protected $conn;
495
496
    /** @var PluginRepository */
497
    protected $pluginRepository;
498
499
    /** @var EccubeConfig */
500
    protected $config;
501
502
    protected $initialized = false;
503
504
    protected $enabled = false;
505
506
    protected $removed = false;
507
508
    protected $tables = [];
509
510
    protected $columns = [];
511
512
    protected $traits = [];
513
514
    public function __construct(\AcceptanceTester $I)
515
    {
516
        $this->I = $I;
517
        $this->em = Fixtures::get('entityManager');
518
        $this->conn = $this->em->getConnection();
519
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
520
        $this->config = Fixtures::get('config');
521
    }
522
523 View Code Duplication
    public function tableExists()
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...
524
    {
525
        foreach ($this->tables as $table) {
526
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '".$table."';")->fetch()['count'] > 0;
0 ignored issues
show
Security introduced by
If $table can contain user-input, it is usually preferable to use a parameter placeholder like :paramName and pass the dynamic input as second argument array('param' => $table).

Instead of embedding dynamic parameters in SQL, Doctrine also allows you to pass them separately and insert a placeholder instead:

function findUser(Doctrine\DBAL\Connection $con, $email) {
    // Unsafe
    $con->executeQuery("SELECT * FROM users WHERE email = '".$email."'");

    // Safe
    $con->executeQuery(
        "SELECT * FROM users WHERE email = :email",
        array('email' => $email)
    );
}
Loading history...
527
            $this->I->assertTrue($exists, 'テーブルがあるはず '.$table);
528
        }
529
    }
530
531 View Code Duplication
    public function tableNotExists()
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...
532
    {
533
        foreach ($this->tables as $table) {
534
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '".$table."';")->fetch()['count'] > 0;
0 ignored issues
show
Security introduced by
If $table can contain user-input, it is usually preferable to use a parameter placeholder like :paramName and pass the dynamic input as second argument array('param' => $table).

Instead of embedding dynamic parameters in SQL, Doctrine also allows you to pass them separately and insert a placeholder instead:

function findUser(Doctrine\DBAL\Connection $con, $email) {
    // Unsafe
    $con->executeQuery("SELECT * FROM users WHERE email = '".$email."'");

    // Safe
    $con->executeQuery(
        "SELECT * FROM users WHERE email = :email",
        array('email' => $email)
    );
}
Loading history...
535
            $this->I->assertFalse($exists, 'テーブルがないはず '.$table);
536
        }
537
    }
538
539 View Code Duplication
    public function columnExists()
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
        foreach ($this->columns as $column) {
542
            list($tableName, $columnName) = explode('.', $column);
543
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
544
            $this->I->assertTrue($exists, 'カラムがあるはず '.$column);
545
        }
546
    }
547
548 View Code Duplication
    public function columnNotExists()
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...
549
    {
550
        foreach ($this->columns as $column) {
551
            list($tableName, $columnName) = explode('.', $column);
552
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
553
            $this->I->assertFalse($exists, 'カラムがないはず '.$column);
554
        }
555
    }
556
557
    public function traitExists()
558
    {
559
        foreach ($this->traits as $trait => $target) {
560
            $this->I->assertContains($trait, file_get_contents($this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php'), 'Traitがあるはず '.$trait);
561
        }
562
    }
563
564
    public function traitNotExists()
565
    {
566
        foreach ($this->traits as $trait => $target) {
567
            $file = $this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php';
568
            if (file_exists($file)) {
569
                $this->I->assertNotContains($trait, file_get_contents($file), 'Traitがないはず '.$trait);
570
            } else {
571
                $this->I->assertTrue(true, 'Traitがないはず');
572
            }
573
        }
574
    }
575
576
    public function 新しいタブで開く()
577
    {
578
        $this->I->executeJS("window.open(location.href, 'other')");
579
        $this->I->switchToWindow('other');
580
581
        return $this;
582
    }
583
584
    public function 前のタブに戻る()
585
    {
586
        $this->I->switchToPreviousTab();
587
588
        return $this;
589
    }
590
591
    public function 検証()
592
    {
593
        $this->I->wait(1);
594
        if ($this->initialized) {
595
            $this->tableExists();
596
            $this->columnExists();
597
        } else {
598
            $this->tableNotExists();
599
            $this->columnNotExists();
600
        }
601
602
        if ($this->enabled) {
603
            $this->traitExists();
604
        } else {
605
            $this->traitNotExists();
606
        }
607
608
        return $this;
609
    }
610
}
611
612
class Store_Plugin extends Abstract_Plugin
613
{
614
    /** @var PluginManagePage */
615
    protected $ManagePage;
616
617
    /** @var Plugin */
618
    protected $Plugin;
619
620
    protected $code;
621
622
    /** @var Store_Plugin */
623
    protected $dependency;
624
625
    public function __construct(AcceptanceTester $I, $code, Store_Plugin $dependency = null)
626
    {
627
        parent::__construct($I);
628
        $this->code = $code;
629
        $this->publishPlugin($this->code.'-1.0.0.tgz');
630
        if ($dependency) {
631
            $this->dependency = $dependency;
632
            $this->ManagePage = $dependency->ManagePage;
633
            $this->Plugin = $this->pluginRepository->findByCode($code);
634
        }
635
    }
636
637
    public function インストール()
638
    {
639
        /*
640
         * インストール
641
         */
642
        $this->ManagePage = PluginSearchPage::go($this->I)
643
            ->入手する($this->code)
644
            ->インストール();
645
646
        $this->検証();
647
648
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
649
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
650
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
651
652
        if ($this->dependency) {
653
            $this->dependency->ManagePage = $this->ManagePage;
654
            $this->dependency->Plugin = $this->pluginRepository->findByCode($this->dependency->code);
655
        }
656
657
        return $this;
658
    }
659
660
    public function 有効化()
661
    {
662
        $this->ManagePage->ストアプラグイン_有効化($this->code);
663
664
        $this->initialized = true;
665
        $this->enabled = true;
666
667
        $this->検証();
668
669
        $this->em->refresh($this->Plugin);
670
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
671
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
672
673
        return $this;
674
    }
675
676
    public function 既に有効なものを有効化()
677
    {
678
        $this->ManagePage->ストアプラグイン_有効化($this->code, '既に有効です。');
679
680
        $this->initialized = true;
681
        $this->enabled = true;
682
683
        $this->検証();
684
685
        $this->em->refresh($this->Plugin);
686
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
687
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
688
689
        return $this;
690
    }
691
692
    public function 無効化()
693
    {
694
        $this->ManagePage->ストアプラグイン_無効化($this->code);
695
696
        $this->enabled = false;
697
698
        $this->検証();
699
700
        $this->em->refresh($this->Plugin);
701
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
702
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
703
704
        return $this;
705
    }
706
707
    public function 既に無効なものを無効化()
708
    {
709
        $this->ManagePage->ストアプラグイン_無効化($this->code, '既に無効です。');
710
711
        $this->enabled = false;
712
713
        $this->検証();
714
715
        $this->em->refresh($this->Plugin);
716
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
717
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
718
719
        return $this;
720
    }
721
722 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...
723
    {
724
        $this->ManagePage->ストアプラグイン_削除($this->code);
725
726
        $this->initialized = false;
727
        $this->enabled = false;
728
729
        $this->検証();
730
731
        $this->em->refresh($this->Plugin);
732
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
733
        $this->I->assertNull($this->Plugin, '削除されている');
734
735
        return $this;
736
    }
737
738
    public function アップデート()
739
    {
740
        $this->publishPlugin($this->code.'-1.0.1.tgz');
741
742
        $this->I->reloadPage();
743
        $this->ManagePage->ストアプラグイン_アップデート($this->code)->アップデート();
744
745
        $this->initialized = true;
746
        $this->enabled = false;
747
748
        $this->検証();
749
750
        $this->em->refresh($this->Plugin);
751
        $this->I->assertEquals($this->initialized, $this->Plugin->isInitialized(), '初期化');
752
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
753
754
        return $this;
755
    }
756
757
    protected function publishPlugin($fileName)
758
    {
759
        $published = copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
760
        $this->I->assertTrue($published, "公開できた ${fileName}");
761
    }
762
}
763
764
class Local_Plugin extends Abstract_Plugin
765
{
766
    /** @var PluginManagePage */
767
    private $ManagePage;
768
769
    /** @var Plugin */
770
    private $Plugin;
771
772
    /** @var string */
773
    private $code;
774
775
    public function __construct(AcceptanceTester $I, $code)
776
    {
777
        parent::__construct($I);
778
        $this->code = $code;
779
    }
780
781
    public function インストール()
782
    {
783
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
784
            ->アップロード('plugins/'.$this->code.'-1.0.0.tgz');
785
786
        $this->initialized = true;
787
788
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
789
790
        $this->検証();
791
792
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
793
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
794
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
795
796
        return $this;
797
    }
798
799
    public function 有効化()
800
    {
801
        $this->ManagePage->独自プラグイン_有効化($this->code);
802
803
        $this->enabled = true;
804
805
        $this->検証();
806
807
        $this->em->refresh($this->Plugin);
808
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
809
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
810
811
        return $this;
812
    }
813
814
    public function 無効化()
815
    {
816
        $this->ManagePage->独自プラグイン_無効化($this->code);
817
818
        $this->enabled = false;
819
820
        $this->検証();
821
822
        $this->em->refresh($this->Plugin);
823
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
824
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
825
826
        return $this;
827
    }
828
829 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...
830
    {
831
        $this->ManagePage->独自プラグイン_削除($this->code);
832
833
        $this->initialized = false;
834
        $this->enabled = false;
835
836
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
837
838
        $this->検証();
839
840
        $this->em->refresh($this->Plugin);
841
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
842
        $this->I->assertNull($this->Plugin, '削除されている');
843
844
        return $this;
845
    }
846
847
    public function アップデート()
848
    {
849
        $this->ManagePage->独自プラグイン_アップデート($this->code, 'plugins/'.$this->code.'-1.0.1.tgz');
850
851
        $this->検証();
852
853
        $this->em->refresh($this->Plugin);
854
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
855
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
856
857
        return $this;
858
    }
859
}
860
861
class Horizon_Local extends Local_Plugin
862
{
863
    public function __construct(AcceptanceTester $I)
864
    {
865
        parent::__construct($I, 'Horizon');
866
        $this->tables[] = 'dtb_dash';
867
        $this->columns[] = 'dtb_cart.is_horizon';
868
        $this->columns[] = 'dtb_cart.dash_id';
869
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
870
    }
871
872
    public function アップデート()
873
    {
874
        // アップデートで新たしいカラムが追加される
875
        $this->columns[] = 'dtb_dash.new_column';
876
        return parent::アップデート();
877
    }
878
879
    public static function start(AcceptanceTester $I)
880
    {
881
        return new self($I);
882
    }
883
}
884
885
class Horizon_Store extends Store_Plugin
886
{
887
    public function __construct(AcceptanceTester $I)
888
    {
889
        parent::__construct($I, 'Horizon');
890
        $this->tables[] = 'dtb_dash';
891
        $this->columns[] = 'dtb_cart.is_horizon';
892
        $this->columns[] = 'dtb_cart.dash_id';
893
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
894
    }
895
896
    public function アップデート()
897
    {
898
        // アップデートで新たしいカラムが追加される
899
        $this->columns[] = 'dtb_dash.new_column';
900
        return parent::アップデート();
901
    }
902
903
    public static function start(AcceptanceTester $I)
904
    {
905
        $result = new self($I);
906
907
        return $result;
908
    }
909
910
    public function 依存されているのが有効なのに無効化()
911
    {
912
        $this->ManagePage->ストアプラグイン_無効化($this->code, '「ホライゾン」を無効にする前に、「エンペラー」を無効にしてください。');
913
914
        $this->検証();
915
916
        $this->em->refresh($this->Plugin);
917
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されているはず');
918
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されているはず');
919
920
        return $this;
921
    }
922
923
    public function 依存されているのが削除されていないのに削除()
924
    {
925
        $this->ManagePage->ストアプラグイン_削除($this->code, '「エンペラー」が「ホライゾン」に依存しているため削除できません。');
926
927
        $this->検証();
928
929
        $this->em->refresh($this->Plugin);
930
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
931
        $this->I->assertNotNull($this->Plugin, '削除されていない');
932
933
        return $this;
934
    }
935
}
936
937
class Emperor_Store extends Store_Plugin
938
{
939 View Code Duplication
    public function __construct(AcceptanceTester $I, Store_Plugin $dependency = null)
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...
940
    {
941
        parent::__construct($I, 'Emperor', $dependency);
942
        $this->publishPlugin('Horizon-1.0.0.tgz');
943
        $this->tables[] = 'dtb_foo';
944
        $this->columns[] = 'dtb_cart.foo_id';
945
        $this->traits['\Plugin\Emperor\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
946
    }
947
948
    public static function start(AcceptanceTester $I, Store_Plugin $dependency = null)
949
    {
950
        return new self($I, $dependency);
951
    }
952
953
    public function アップデート()
954
    {
955
        $this->tables = ['dtb_bar'];
956
        $this->columns = ['dtb_cart.bar_id'];
957
        $this->traits['\Plugin\Emperor\Entity\Cart2Trait'] = 'src/Eccube/Entity/Cart';
958
959
        return parent::アップデート();
960
    }
961
962
    public function 依存より先に有効化()
963
    {
964
        $this->ManagePage->ストアプラグイン_有効化($this->code, '「ホライゾン」を先に有効化してください。');
965
966
        $this->検証();
967
968
        $this->em->refresh($this->Plugin);
969
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていないはず');
970
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていないはず');
971
972
        return $this;
973
    }
974
}
975
976
class Boomerang_Store extends Store_Plugin
977
{
978
    public function __construct(AcceptanceTester $I)
979
    {
980
        parent::__construct($I, 'Boomerang');
981
        $this->tables[] = 'dtb_bar';
982
        $this->columns[] = 'dtb_cart.is_boomerang';
983
        $this->columns[] = 'dtb_cart.bar_id';
984
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
985
    }
986
987
    public static function start(AcceptanceTester $I)
988
    {
989
        return new self($I);
990
    }
991
992
    public function カート一覧()
993
    {
994
        $this->I->amOnPage('/boomerang');
995
    }
996
997
    public function カート作成()
998
    {
999
        $this->I->amOnPage('/boomerang/new');
1000
        $this->I->seeCurrentUrlMatches('/^\/boomerang$/');
1001
        return $this;
1002
    }
1003
}
1004
1005
class Boomerang10_Store extends Store_Plugin
1006
{
1007
    public function __construct(AcceptanceTester $I, Store_Plugin $dependency = null)
1008
    {
1009
        parent::__construct($I, 'Boomerang10', $dependency);
1010
        $this->columns[] = 'dtb_bar.mail';
1011
    }
1012
1013
    public static function start(AcceptanceTester $I, Store_Plugin $dependency = null)
0 ignored issues
show
Unused Code introduced by
The parameter $dependency is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1014
    {
1015
        return new self($I, $dependency = null);
1016
    }
1017
}
1018
1019
class Boomerang_Local extends Local_Plugin
1020
{
1021 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...
1022
    {
1023
        parent::__construct($I, 'Boomerang');
1024
        $this->tables[] = 'dtb_bar';
1025
        $this->columns[] = 'dtb_cart.is_boomerang';
1026
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'src/Eccube/Entity/Cart';
1027
    }
1028
1029
    public static function start(AcceptanceTester $I)
1030
    {
1031
        return new self($I);
1032
    }
1033
}
1034
1035
class Bundle_Store extends Store_Plugin
1036
{
1037
    public function __construct(AcceptanceTester $I)
1038
    {
1039
        parent::__construct($I, 'Bundle');
1040
        $this->tables[] = 'oauth2_client';
1041
        $this->tables[] = 'oauth2_refresh_token';
1042
        $this->tables[] = 'oauth2_access_token';
1043
        $this->tables[] = 'oauth2_authorization_code';
1044
    }
1045
1046
    public function 有効化()
1047
    {
1048
        parent::有効化();
1049
1050
        return $this;
1051
    }
1052
1053
    public function 無効化()
1054
    {
1055
        parent::無効化();
1056
1057
        return $this;
1058
    }
1059
    public static function start(AcceptanceTester $I)
1060
    {
1061
        return new self($I);
1062
    }
1063
}
1064