Failed Conditions
Push — dev/local-plugin-cache ( 16070e )
by Kiyotaka
08:36 queued 47s
created

EA10PluginCest::test_install_error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Codeception\Util\FileSystem;
15
use Codeception\Util\Fixtures;
16
use Doctrine\ORM\EntityManager;
17
use Eccube\Common\EccubeConfig;
18
use Eccube\Entity\Plugin;
19
use Eccube\Repository\PluginRepository;
20
use Page\Admin\PluginLocalInstallPage;
21
use Page\Admin\PluginManagePage;
22
use Page\Admin\PluginSearchPage;
23
24
class EA10PluginCest
25
{
26
    /** @var EntityManager */
27
    private $em;
28
29
    /** @var \Doctrine\DBAL\Connection */
30
    private $conn;
31
32
    /** @var PluginRepository */
33
    private $pluginRepository;
34
35
    /** @var EccubeConfig */
36
    private $config;
37
38 View Code Duplication
    public function _before(\AcceptanceTester $I)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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