Completed
Push — dev/plugin-checker ( e6edd6 )
by Kiyotaka
06:18
created

EA10PluginCest::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Codeception\Util\FileSystem;
15
use Codeception\Util\Fixtures;
16
use Doctrine\ORM\EntityManager;
17
use Eccube\Common\EccubeConfig;
18
use Eccube\Entity\Plugin;
19
use Eccube\Repository\PluginRepository;
20
use Page\Admin\PluginLocalInstallPage;
21
use Page\Admin\PluginManagePage;
22
use Page\Admin\PluginSearchPage;
23
24
class EA10PluginCest
25
{
26
    /** @var EntityManager */
27
    private $em;
28
29
    /** @var \Doctrine\DBAL\Connection */
30
    private $conn;
31
32
    /** @var PluginRepository */
33
    private $pluginRepository;
34
35
    /** @var EccubeConfig */
36
    private $config;
37
38
    public function _before(\AcceptanceTester $I)
39
    {
40
        $I->loginAsAdmin();
41
42
        $this->em = Fixtures::get('entityManager');
43
        $this->conn = $this->em->getConnection();
44
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
45
        $this->config = Fixtures::get('config');
46
        FileSystem::doEmptyDir('repos');
47
    }
48
49
    public function test_install_enable_disable_remove_store(\AcceptanceTester $I)
50
    {
51
        Horizon_Store::start($I)
52
            ->インストール()
53
            ->有効化()
54
            ->無効化()
55
            ->削除();
56
    }
57
58
    public function test_install_enable_disable_remove_local(\AcceptanceTester $I)
59
    {
60
        Horizon_Store::start($I)
61
            ->インストール()
62
            ->有効化()
63
            ->無効化()
64
            ->削除();
65
    }
66
67
    public function test_install_enable_disable_enable_disable_remove_store(\AcceptanceTester $I)
68
    {
69
        Horizon_Store::start($I)
70
            ->インストール()
71
            ->有効化()
72
            ->無効化()
73
            ->有効化()
74
            ->無効化()
75
            ->削除();
76
    }
77
78
    public function test_install_enable_disable_enable_disable_remove_local(\AcceptanceTester $I)
79
    {
80
        Horizon_Local::start($I)
81
            ->インストール()
82
            ->有効化()
83
            ->無効化()
84
            ->有効化()
85
            ->無効化()
86
            ->削除();
87
    }
88
89
    public function test_install_remove_local(\AcceptanceTester $I)
90
    {
91
        Horizon_Local::start($I)
92
            ->インストール()
93
            ->削除();
94
    }
95
96
    public function test_install_remove_store(\AcceptanceTester $I)
97
    {
98
        Horizon_Store::start($I)
99
            ->インストール()
100
            ->削除();
101
    }
102
103
    public function test_install_update_remove_store(\AcceptanceTester $I)
104
    {
105
        Horizon_Store::start($I)
106
            ->インストール()
107
            ->アップデート()
108
            ->削除();
109
    }
110
111
112
113
    public function test_install_update_remove_local(\AcceptanceTester $I)
114
    {
115
        Horizon_Local::start($I)
116
            ->インストール()
117
            ->アップデート()
118
            ->削除();
119
    }
120
121
    public function test_install_enable_disable_update_enable_disable_remove_local(\AcceptanceTester $I)
122
    {
123
        Horizon_Local::start($I)
124
            ->インストール()
125
            ->有効化()
126
            ->無効化()
127
            ->アップデート()
128
            ->有効化()
129
            ->無効化()
130
            ->削除();
131
    }
132
133
    public function test_install_enable_disable_update_enable_disable_remove_store(\AcceptanceTester $I)
134
    {
135
        Horizon_Store::start($I)
136
            ->インストール()
137
            ->有効化()
138
            ->無効化()
139
            ->アップデート()
140
            ->有効化()
141
            ->無効化()
142
            ->削除();
143
    }
144
145
    public function test_install_enable_update_disable_remove_store(\AcceptanceTester $I)
146
    {
147
        Horizon_Store::start($I)
148
            ->インストール()
149
            ->有効化()
150
            ->アップデート()
151
            ->無効化()
152
            ->削除();
153
    }
154
155
    public function test_install_enable_update_disable_remove_local(\AcceptanceTester $I)
156
    {
157
        Horizon_Local::start($I)
158
            ->インストール()
159
            ->有効化()
160
            ->アップデート()
161
            ->無効化()
162
            ->削除();
163
    }
164
165
    public function test_install_update_enable_disable_remove_local(\AcceptanceTester $I)
166
    {
167
        Horizon_Local::start($I)
168
            ->インストール()
169
            ->アップデート()
170
            ->有効化()
171
            ->無効化()
172
            ->削除();
173
    }
174
175
    public function test_install_update_enable_disable_remove_store(\AcceptanceTester $I)
176
    {
177
        Horizon_Store::start($I)
178
            ->インストール()
179
            ->アップデート()
180
            ->有効化()
181
            ->無効化()
182
            ->削除();
183
    }
184
185
    public function test_install_enable_enable(\AcceptanceTester $I)
186
    {
187
        Horizon_Store::start($I)
188
            ->インストール()
189
            ->新しいタブで開く()
190
            ->有効化()
191
            ->前のタブに戻る()
192
            ->既に有効なものを有効化();
193
    }
194
195
    public function test_install_disable_disable(\AcceptanceTester $I)
196
    {
197
        Horizon_Store::start($I)
198
            ->インストール()
199
            ->有効化()
200
            ->新しいタブで開く()
201
            ->無効化()
202
            ->前のタブに戻る()
203
            ->既に無効なものを無効化();
204
    }
205
206
    public function test_install_assets_local(\AcceptanceTester $I)
207
    {
208
        $this->publishPlugin('Assets-1.0.0.tgz');
209
210
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
211
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
212
213
        $I->assertFileNotExists($assetsPath);
214
        $I->assertFileNotExists($updatedPath);
215
216
        $ManagePage = PluginLocalInstallPage::go($I)->アップロード('plugins/Assets-1.0.0.tgz');
217
        $I->assertFileExists($assetsPath);
218
        $I->assertFileNotExists($updatedPath);
219
220
        $ManagePage->独自プラグイン_有効化('Assets');
221
        $I->assertFileExists($assetsPath);
222
        $I->assertFileNotExists($updatedPath);
223
224
        $ManagePage->独自プラグイン_無効化('Assets');
225
        $I->assertFileExists($assetsPath);
226
        $I->assertFileNotExists($updatedPath);
227
228
        $ManagePage->独自プラグイン_アップデート('Assets', 'plugins/Assets-1.0.1.tgz');
229
        $I->assertFileExists($assetsPath);
230
        $I->assertFileExists($updatedPath);
231
232
        $ManagePage->独自プラグイン_削除('Assets');
233
        $I->assertFileNotExists($assetsPath);
234
        $I->assertFileNotExists($updatedPath);
235
    }
236
237
    public function test_install_assets_store(\AcceptanceTester $I)
238
    {
239
        // 最初のバージョンを作成
240
        $this->publishPlugin('Assets-1.0.0.tgz');
241
242
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
243
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
244
        $I->assertFileNotExists($assetsPath);
245
        $I->assertFileNotExists($updatedPath);
246
247
        $ManagePage = PluginSearchPage::go($I)
248
            ->入手する('Assets')
249
            ->インストール();
250
        $I->assertFileNotExists($assetsPath);
251
        $I->assertFileNotExists($updatedPath);
252
253
        $ManagePage->ストアプラグイン_有効化('Assets');
254
        $I->assertFileExists($assetsPath);
255
        $I->assertFileNotExists($updatedPath);
256
257
        $ManagePage->ストアプラグイン_無効化('Assets');
258
        $I->assertFileExists($assetsPath);
259
        $I->assertFileNotExists($updatedPath);
260
261
        // 新しいバージョンを作成
262
        $this->publishPlugin('Assets-1.0.1.tgz');
263
264
        $I->reloadPage();
265
        $ManagePage->ストアプラグイン_アップデート('Assets')->アップデート();
266
        $I->assertFileExists($assetsPath);
267
        $I->assertFileExists($updatedPath);
268
269
        $ManagePage->ストアプラグイン_削除('Assets');
270
        $I->assertFileNotExists($assetsPath);
271
        $I->assertFileNotExists($updatedPath);
272
    }
273
274 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...
275
    {
276
        $Horizon = Horizon_Store::start($I);
277
        $Boomerang = Boomerang_Store::start($I);
278
279
        $Horizon->インストール()->有効化();
280
        $Boomerang->インストール()->有効化();
281
282
        $Horizon->検証()->無効化()->削除();
283
        $Boomerang->検証()->無効化()->削除();
284
    }
285
286 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...
287
    {
288
        $Horizon = Horizon_Store::start($I);
289
        $Boomerang = Boomerang_Store::start($I);
290
291
        $Horizon->インストール()->有効化()->無効化();
292
        $Boomerang->インストール()->有効化()->無効化();
293
294
        $Horizon->検証()->削除();
295
        $Boomerang->検証()->削除();
296
    }
297
298 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...
299
    {
300
        $Horizon = Horizon_Local::start($I);
301
        $Boomerang = Boomerang_Local::start($I);
302
303
        $Horizon->インストール()->有効化();
304
        $Boomerang->インストール()->有効化();
305
306
        $Horizon->検証()->無効化()->削除();
307
        $Boomerang->検証()->無効化()->削除();
308
    }
309
310 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...
311
    {
312
        $Horizon = Horizon_Local::start($I);
313
        $Boomerang = Boomerang_Local::start($I);
314
315
        $Horizon->インストール()->有効化()->無効化();
316
        $Boomerang->インストール()->有効化()->無効化();
317
318
        $Horizon->検証()->削除();
319
        $Boomerang->検証()->削除();
320
    }
321
322 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...
323
    {
324
        $Horizon = Horizon_Store::start($I);
325
        $Boomerang = Boomerang_Store::start($I);
326
327
        $Horizon->インストール()->有効化()->無効化();
328
        $Boomerang->インストール()->有効化();
329
330
        $Horizon->検証()->削除();
331
        $Boomerang->検証()->無効化()->削除();
332
    }
333
334 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...
335
    {
336
        $Horizon = Horizon_Local::start($I);
337
        $Boomerang = Boomerang_Local::start($I);
338
339
        $Horizon->インストール()->有効化()->無効化();
340
        $Boomerang->インストール()->有効化();
341
342
        $Horizon->検証()->削除();
343
        $Boomerang->検証()->無効化()->削除();
344
    }
345
346
    public function test_dependency_each_install_plugin(\AcceptanceTester $I)
347
    {
348
        $Horizon = Horizon_Store::start($I);
349
        $Emperor = Emperor_Store::start($I);
350
351
        $Horizon->インストール()->有効化();
352
        $Emperor->インストール()->有効化();
353
    }
354
355
    public function test_dependency_plugin_install(\AcceptanceTester $I)
356
    {
357
        $Horizon = Horizon_Store::start($I);
358
        $Emperor = Emperor_Store::start($I, $Horizon);
359
360
        $Emperor->インストール()
361
            ->依存より先に有効化();
362
363
        $Horizon->有効化();
364
365
        $Emperor->有効化();
366
367
        $Horizon->依存されているのが有効なのに無効化();
368
        $Emperor->無効化();
369
        $Horizon->無効化();
370
371
        $Horizon->依存されているのが削除されていないのに削除();
372
        $Emperor->削除();
373
        $Horizon->削除();
374
    }
375
376
    public function test_dependency_plugin_update(\AcceptanceTester $I)
377
    {
378
        $Horizon = Horizon_Store::start($I);
379
        $Emperor = Emperor_Store::start($I, $Horizon);
380
381
        $Emperor->インストール();
382
383
        $Horizon->検証()
384
            ->有効化();
385
386
        $Emperor
387
            ->有効化()
388
            ->無効化()
389
            ->アップデート();
390
391
        $Horizon->検証();
392
    }
393
394
    public function test_install_error(\AcceptanceTester $I)
395
    {
396
        $this->publishPlugin('InstallError.tgz');
397
        $Horizon = Horizon_Store::start($I);
398
399
        PluginSearchPage::go($I)
400
            ->入手する('InstallError')
401
            ->インストール('システムエラーが発生しました。');
402
403
        // エラー後に他のプラグインがインストールできる
404
        $Horizon->インストール();
405
    }
406
407
    public function check(\AcceptanceTester $I)
408
    {
409
        $code = getenv('ECCUBE_TARGET_PLUGIN');
410
        $plugin = new Store_Plugin($I, $code);
411
        $plugin->インストール()
412
            ->有効化()
413
            ->無効化()
414
            ->削除();
415
    }
416
417
    private function publishPlugin($fileName)
418
    {
419
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
420
    }
421
}
422
423
abstract class Abstract_Plugin
424
{
425
    /** @var AcceptanceTester */
426
    protected $I;
427
428
    /** @var EntityManager */
429
    protected $em;
430
431
    /** @var \Doctrine\DBAL\Connection */
432
    protected $conn;
433
434
    /** @var PluginRepository */
435
    protected $pluginRepository;
436
437
    /** @var EccubeConfig */
438
    protected $config;
439
440
    protected $initialized = false;
441
442
    protected $enabled = false;
443
444
    protected $removed = false;
445
446
    protected $tables = [];
447
448
    protected $columns = [];
449
450
    protected $traits = [];
451
452
    public function __construct(\AcceptanceTester $I)
453
    {
454
        $this->I = $I;
455
        $this->em = Fixtures::get('entityManager');
456
        $this->conn = $this->em->getConnection();
457
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
458
        $this->config = Fixtures::get('config');
459
    }
460
461 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...
462
    {
463
        foreach ($this->tables as $table) {
464
            $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...
465
            $this->I->assertTrue($exists, 'テーブルがあるはず '.$table);
466
        }
467
    }
468
469 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...
470
    {
471
        foreach ($this->tables as $table) {
472
            $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...
473
            $this->I->assertFalse($exists, 'テーブルがないはず '.$table);
474
        }
475
    }
476
477 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...
478
    {
479
        foreach ($this->columns as $column) {
480
            list($tableName, $columnName) = explode('.', $column);
481
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
482
            $this->I->assertTrue($exists, 'カラムがあるはず '.$column);
483
        }
484
    }
485
486 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...
487
    {
488
        foreach ($this->columns as $column) {
489
            list($tableName, $columnName) = explode('.', $column);
490
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
491
            $this->I->assertFalse($exists, 'カラムがないはず '.$column);
492
        }
493
    }
494
495
    public function traitExists()
496
    {
497
        foreach ($this->traits as $trait => $target) {
498
            $this->I->assertContains($trait, file_get_contents($this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php'), 'Traitがあるはず '.$trait);
499
        }
500
    }
501
502
    public function traitNotExists()
503
    {
504
        foreach ($this->traits as $trait => $target) {
505
            $file = $this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php';
506
            if (file_exists($file)) {
507
                $this->I->assertNotContains($trait, file_get_contents($file), 'Traitがないはず '.$trait);
508
            } else {
509
                $this->I->assertTrue(true, 'Traitがないはず');
510
            }
511
        }
512
    }
513
514
    public function 新しいタブで開く()
515
    {
516
        $this->I->executeJS("window.open(location.href, 'other')");
517
        $this->I->switchToWindow('other');
518
        return $this;
519
    }
520
521
    public function 前のタブに戻る()
522
    {
523
        $this->I->switchToPreviousTab();
524
        return $this;
525
    }
526
527
    public function 検証()
528
    {
529
        if ($this->initialized) {
530
            $this->tableExists();
531
            $this->columnExists();
532
        } else {
533
            $this->tableNotExists();
534
            $this->columnNotExists();
535
        }
536
537
        if ($this->enabled) {
538
            $this->traitExists();
539
        } else {
540
            $this->traitNotExists();
541
        }
542
543
        return $this;
544
    }
545
}
546
547
class Store_Plugin extends Abstract_Plugin
548
{
549
    /** @var PluginManagePage */
550
    protected $ManagePage;
551
552
    /** @var Plugin */
553
    protected $Plugin;
554
555
    protected $code;
556
557
    /** @var Store_Plugin */
558
    protected $dependency;
559
560
    public function __construct(AcceptanceTester $I, $code, Store_Plugin $dependency = null)
561
    {
562
        parent::__construct($I);
563
        $this->code = $code;
564
        $this->publishPlugin($this->code.'-1.0.0.tgz');
565
        if ($dependency) {
566
            $this->dependency = $dependency;
567
            $this->ManagePage = $dependency->ManagePage;
568
            $this->Plugin = $this->pluginRepository->findByCode($code);
569
        }
570
    }
571
572
    public function インストール()
573
    {
574
        /*
575
         * インストール
576
         */
577
        $this->ManagePage = PluginSearchPage::go($this->I)
578
            ->入手する($this->code)
579
            ->インストール();
580
581
        $this->検証();
582
583
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
584
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
585
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
586
587
        if ($this->dependency) {
588
            $this->dependency->ManagePage = $this->ManagePage;
589
            $this->dependency->Plugin = $this->pluginRepository->findByCode($this->dependency->code);
590
        }
591
592
        return $this;
593
    }
594
595 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...
596
    {
597
        $this->ManagePage->ストアプラグイン_有効化($this->code);
598
599
        $this->initialized = true;
600
        $this->enabled = true;
601
602
        $this->検証();
603
604
        $this->em->refresh($this->Plugin);
605
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
606
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
607
608
        return $this;
609
    }
610
611
    public function 既に有効なものを有効化()
612
    {
613
        $this->ManagePage->ストアプラグイン_有効化($this->code, '既に有効です。');
614
615
        $this->initialized = true;
616
        $this->enabled = true;
617
618
        $this->検証();
619
620
        $this->em->refresh($this->Plugin);
621
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
622
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
623
624
625
        return $this;
626
    }
627
628 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...
629
    {
630
        $this->ManagePage->ストアプラグイン_無効化($this->code);
631
632
        $this->enabled = false;
633
634
        $this->検証();
635
636
        $this->em->refresh($this->Plugin);
637
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
638
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
639
640
        return $this;
641
    }
642
643 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...
644
    {
645
        $this->ManagePage->ストアプラグイン_無効化($this->code, '既に無効です。');
646
647
        $this->enabled = false;
648
649
        $this->検証();
650
651
        $this->em->refresh($this->Plugin);
652
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
653
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
654
655
        return $this;
656
    }
657
658 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...
659
    {
660
        $this->ManagePage->ストアプラグイン_削除($this->code);
661
662
        $this->initialized = false;
663
        $this->enabled = false;
664
665
        $this->検証();
666
667
        $this->em->refresh($this->Plugin);
668
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
669
        $this->I->assertNull($this->Plugin, '削除されている');
670
671
        return $this;
672
    }
673
674
    public function アップデート()
675
    {
676
        $this->publishPlugin($this->code.'-1.0.1.tgz');
677
678
        $this->I->reloadPage();
679
        $this->ManagePage->ストアプラグイン_アップデート($this->code)->アップデート();
680
681
        $this->initialized = true;
682
683
        $this->検証();
684
685
        $this->em->refresh($this->Plugin);
686
        $this->I->assertEquals($this->initialized, $this->Plugin->isInitialized(), '初期化');
687
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
688
689
        return $this;
690
    }
691
692
    protected function publishPlugin($fileName)
693
    {
694
        $published = copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
695
        $this->I->assertTrue($published, "公開できた ${fileName}");
696
    }
697
}
698
699
class Local_Plugin extends Abstract_Plugin
700
{
701
    /** @var PluginManagePage */
702
    private $ManagePage;
703
704
    /** @var Plugin */
705
    private $Plugin;
706
707
    /** @var string */
708
    private $code;
709
710
    public function __construct(AcceptanceTester $I, $code)
711
    {
712
        parent::__construct($I);
713
        $this->code = $code;
714
    }
715
716
    public function インストール()
717
    {
718
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
719
            ->アップロード('plugins/'.$this->code.'-1.0.0.tgz');
720
721
        $this->initialized = true;
722
723
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
724
725
        $this->検証();
726
727
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
728
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
729
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
730
731
        return $this;
732
    }
733
734 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...
735
    {
736
        $this->ManagePage->独自プラグイン_有効化($this->code);
737
738
        $this->enabled = true;
739
740
        $this->検証();
741
742
        $this->em->refresh($this->Plugin);
743
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
744
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
745
        return $this;
746
    }
747
748 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...
749
    {
750
        $this->ManagePage->独自プラグイン_無効化($this->code);
751
752
        $this->enabled = false;
753
754
        $this->検証();
755
756
        $this->em->refresh($this->Plugin);
757
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
758
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
759
760
        return $this;
761
    }
762
763 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...
764
    {
765
        $this->ManagePage->独自プラグイン_削除($this->code);
766
767
        $this->initialized = false;
768
        $this->enabled = false;
769
770
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
771
772
        $this->検証();
773
774
        $this->em->refresh($this->Plugin);
775
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
776
        $this->I->assertNull($this->Plugin, '削除されている');
777
778
        return $this;
779
    }
780
781
    public function アップデート()
782
    {
783
        $this->ManagePage->独自プラグイン_アップデート($this->code, 'plugins/'.$this->code.'-1.0.1.tgz');
784
785
        $this->検証();
786
787
        $this->em->refresh($this->Plugin);
788
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
789
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
790
791
        return $this;
792
    }
793
}
794
795 View Code Duplication
class Horizon_Local extends Local_Plugin
0 ignored issues
show
Duplication introduced by
This class 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...
796
{
797
    public function __construct(AcceptanceTester $I)
798
    {
799
        parent::__construct($I, 'Horizon');
800
        $this->tables[] = 'dtb_dash';
801
        $this->columns[] = 'dtb_cart.is_horizon';
802
        $this->columns[] = 'dtb_cart.dash_id';
803
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'Cart';
804
    }
805
806
    public static function start(AcceptanceTester $I)
807
    {
808
        return new self($I);
809
    }
810
}
811
812
class Horizon_Store extends Store_Plugin
813
{
814
    public function __construct(AcceptanceTester $I)
815
    {
816
        parent::__construct($I, 'Horizon');
817
        $this->tables[] = 'dtb_dash';
818
        $this->columns[] = 'dtb_cart.is_horizon';
819
        $this->columns[] = 'dtb_cart.dash_id';
820
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'Cart';
821
    }
822
823
    public static function start(AcceptanceTester $I)
824
    {
825
        $result = new self($I);
826
        return $result;
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->検証();
834
835
        $this->em->refresh($this->Plugin);
836
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されているはず');
837
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されているはず');
838
        return $this;
839
    }
840
841
    public function 依存されているのが削除されていないのに削除()
842
    {
843
        $this->ManagePage->ストアプラグイン_削除($this->code, '「エンペラー」が「ホライゾン」に依存しているため削除できません。');
844
845
        $this->検証();
846
847
        $this->em->refresh($this->Plugin);
848
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
849
        $this->I->assertNotNull($this->Plugin, '削除されていない');
850
851
        return $this;
852
    }
853
854
}
855
856
class Emperor_Store extends Store_Plugin
857
{
858 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...
859
    {
860
        parent::__construct($I, 'Emperor', $dependency);
861
        $this->publishPlugin('Horizon-1.0.0.tgz');
862
        $this->tables[] = 'dtb_foo';
863
        $this->columns[] = 'dtb_cart.foo_id';
864
        $this->traits['\Plugin\Emperor\Entity\CartTrait'] = 'Cart';
865
    }
866
867
    public static function start(AcceptanceTester $I, Store_Plugin $dependency = null)
868
    {
869
        return new self($I, $dependency);
870
    }
871
872
    public function アップデート()
873
    {
874
        $this->tables = ['dtb_bar'];
875
        $this->columns = ['dtb_cart.bar_id'];
876
        $this->traits['\Plugin\Emperor\Entity\Cart2Trait'] = 'Cart';
877
        return parent::アップデート();
878
    }
879
880
881 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...
882
    {
883
        $this->ManagePage->ストアプラグイン_有効化($this->code, '「ホライゾン」を先に有効化してください。');
884
885
        $this->検証();
886
887
        $this->em->refresh($this->Plugin);
888
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていないはず');
889
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていないはず');
890
        return $this;
891
    }
892
}
893
894 View Code Duplication
class Boomerang_Store extends Store_Plugin
0 ignored issues
show
Duplication introduced by
This class 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...
895
{
896
    public function __construct(AcceptanceTester $I)
897
    {
898
        parent::__construct($I, 'Boomerang');
899
        $this->tables[] = 'dtb_bar';
900
        $this->columns[] = 'dtb_cart.is_boomerang';
901
        $this->columns[] = 'dtb_cart.bar_id';
902
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'Cart';
903
    }
904
905
    public static function start(AcceptanceTester $I)
906
    {
907
        return new self($I);
908
    }
909
}
910
911
class Boomerang_Local extends Local_Plugin
912
{
913 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...
914
    {
915
        parent::__construct($I, 'Boomerang');
916
        $this->tables[] = 'dtb_bar';
917
        $this->columns[] = 'dtb_cart.is_boomerang';
918
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'Cart';
919
    }
920
921
    public static function start(AcceptanceTester $I)
922
    {
923
        return new self($I);
924
    }
925
}