Completed
Push — dev/plugin-misc ( 8baca9...e25948 )
by Kiyotaka
06:19
created

EA10PluginCest::test_dependency_plugin_install()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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