Completed
Push — dev/plugin-misc ( 4f3c5e...424dc8 )
by Kiyotaka
07:58
created

Emperor_Store   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 36.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A start() 0 4 1
A 依存より先に有効化() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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_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...
287
    {
288
        $Horizon = Horizon_Local::start($I);
289
        $Boomerang = Boomerang_Local::start($I);
290
291
        $Horizon->インストール()->有効化();
292
        $Boomerang->インストール()->有効化();
293
294
        $Horizon->検証()->無効化()->削除();
295
        $Boomerang->検証()->無効化()->削除();
296
    }
297
298 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...
299
    {
300
        $Horizon = Horizon_Store::start($I);
301
        $Boomerang = Boomerang_Store::start($I);
302
303
        $Horizon->インストール()->有効化()->無効化();
304
        $Boomerang->インストール()->有効化();
305
306
        $Horizon->検証()->削除();
307
        $Boomerang->検証()->無効化()->削除();
308
    }
309
310 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...
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
    public function test_dependency_each_install_plugin(\AcceptanceTester $I)
323
    {
324
        Horizon_Store::start($I)
325
            ->インストール();
326
327
//        Emperor_Store::start($I)
328
//            ->インストール();
329
    }
330
331
    public function test_dependency_plugin(\AcceptanceTester $I)
332
    {
333
        $Emperor = Emperor_Store::start($I)
334
            ->インストール()
335
            ->依存より先に有効化();
336
337
        Horizon_Store::start($I, $Emperor)
338
            ->有効化();
339
340
        $Emperor->有効化();
341
    }
342
343
    private function publishPlugin($fileName)
344
    {
345
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
346
    }
347
}
348
349
abstract class Abstract_Plugin
350
{
351
    /** @var AcceptanceTester */
352
    protected $I;
353
354
    /** @var EntityManager */
355
    protected $em;
356
357
    /** @var \Doctrine\DBAL\Connection */
358
    protected $conn;
359
360
    /** @var PluginRepository */
361
    protected $pluginRepository;
362
363
    /** @var EccubeConfig */
364
    protected $config;
365
366
    protected $initialized = false;
367
368
    protected $enabled = false;
369
370
    protected $removed = false;
371
372
    protected $tables = [];
373
374
    protected $columns = [];
375
376
    protected $traits = [];
377
378
    public function __construct(\AcceptanceTester $I)
379
    {
380
        $this->I = $I;
381
        $this->em = Fixtures::get('entityManager');
382
        $this->conn = $this->em->getConnection();
383
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
384
        $this->config = Fixtures::get('config');
385
    }
386
387 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...
388
    {
389
        foreach ($this->tables as $table) {
390
            $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...
391
            $this->I->assertTrue($exists, 'テーブルがあるはず '.$table);
392
        }
393
    }
394
395 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...
396
    {
397
        foreach ($this->tables as $table) {
398
            $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...
399
            $this->I->assertFalse($exists, 'テーブルがないはず '.$table);
400
        }
401
    }
402
403 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...
404
    {
405
        foreach ($this->columns as $column) {
406
            list($tableName, $columnName) = explode('.', $column);
407
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
408
            $this->I->assertTrue($exists, 'カラムがあるはず '.$column);
409
        }
410
    }
411
412 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...
413
    {
414
        foreach ($this->columns as $column) {
415
            list($tableName, $columnName) = explode('.', $column);
416
            $exists = $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
417
            $this->I->assertFalse($exists, 'カラムがないはず '.$column);
418
        }
419
    }
420
421
    public function traitExists()
422
    {
423
        foreach ($this->traits as $trait => $target) {
424
            $this->I->assertContains($trait, file_get_contents($this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php'), 'Traitがあるはず '.$trait);
425
        }
426
    }
427
428
    public function traitNotExists()
429
    {
430
        foreach ($this->traits as $trait => $target) {
431
            $file = $this->config['kernel.project_dir'].'/app/proxy/entity/'.$target.'.php';
432
            if (file_exists($file)) {
433
                $this->I->assertNotContains($trait, file_get_contents($file), 'Traitがないはず '.$trait);
434
            } else {
435
                $this->I->assertTrue(true, 'Traitがないはず');
436
            }
437
        }
438
    }
439
440
    public function 新しいタブで開く()
441
    {
442
        $this->I->executeJS("window.open(location.href, 'other')");
443
        $this->I->switchToWindow('other');
444
        return $this;
445
    }
446
447
    public function 前のタブに戻る()
448
    {
449
        $this->I->switchToPreviousTab();
450
        return $this;
451
    }
452
453
    public function 検証()
454
    {
455
        if ($this->initialized) {
456
            $this->tableExists();
457
            $this->columnExists();
458
        } else {
459
            $this->tableNotExists();
460
            $this->columnNotExists();
461
        }
462
463
        if ($this->enabled) {
464
            $this->traitExists();
465
        } else {
466
            $this->traitNotExists();
467
        }
468
469
        return $this;
470
    }
471
}
472
473
class Store_Plugin extends Abstract_Plugin
474
{
475
    /** @var PluginManagePage */
476
    protected $ManagePage;
477
478
    /** @var Plugin */
479
    protected $Plugin;
480
481
    protected $code;
482
483
    public function __construct(AcceptanceTester $I, $code)
484
    {
485
        parent::__construct($I);
486
        $this->code = $code;
487
        $this->publishPlugin($this->code.'-1.0.0.tgz');
488
    }
489
490
    public function インストール()
491
    {
492
        /*
493
         * インストール
494
         */
495
        $this->ManagePage = PluginSearchPage::go($this->I)
496
            ->入手する($this->code)
497
            ->インストール();
498
499
        $this->検証();
500
501
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
502
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
503
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
504
505
        return $this;
506
    }
507
508 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...
509
    {
510
        $this->ManagePage->ストアプラグイン_有効化($this->code);
511
512
        $this->initialized = true;
513
        $this->enabled = true;
514
515
        $this->検証();
516
517
        $this->em->refresh($this->Plugin);
518
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
519
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
520
        return $this;
521
    }
522
523
    public function 既に有効なものを有効化()
524
    {
525
        $this->ManagePage->ストアプラグイン_有効化($this->code, '既に有効です。');
526
527
        $this->initialized = true;
528
        $this->enabled = true;
529
530
        $this->検証();
531
532
        $this->em->refresh($this->Plugin);
533
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
534
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
535
536
537
        return $this;
538
    }
539
540 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...
541
    {
542
        $this->ManagePage->ストアプラグイン_無効化($this->code);
543
544
        $this->enabled = false;
545
546
        $this->検証();
547
548
        $this->em->refresh($this->Plugin);
549
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
550
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
551
552
        return $this;
553
    }
554
555 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...
556
    {
557
        $this->ManagePage->ストアプラグイン_無効化($this->code, '既に無効です。');
558
559
        $this->enabled = false;
560
561
        $this->検証();
562
563
        $this->em->refresh($this->Plugin);
564
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
565
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
566
567
        return $this;
568
    }
569
570 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...
571
    {
572
        $this->ManagePage->ストアプラグイン_削除($this->code);
573
574
        $this->initialized = false;
575
        $this->enabled = false;
576
577
        $this->検証();
578
579
        $this->em->refresh($this->Plugin);
580
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
581
        $this->I->assertNull($this->Plugin, '削除されている');
582
583
        return $this;
584
    }
585
586
    public function アップデート()
587
    {
588
        $this->publishPlugin($this->code.'-1.0.1.tgz');
589
590
        $this->I->reloadPage();
591
        $this->ManagePage->ストアプラグイン_アップデート($this->code)->アップデート();
592
593
        $this->initialized = true;
594
595
        $this->検証();
596
597
        $this->em->refresh($this->Plugin);
598
        $this->I->assertEquals($this->initialized, $this->Plugin->isInitialized(), '初期化');
599
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
600
601
        return $this;
602
    }
603
604
    protected function publishPlugin($fileName)
605
    {
606
        $published = copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
607
        $this->I->assertTrue($published, "公開できた ${fileName}");
608
        $output = [];
609
        exec("ls -ltra repos/", $output);
610
        echo implode(PHP_EOL, $output).PHP_EOL;
611
    }
612
}
613
614
class Local_Plugin extends Abstract_Plugin
615
{
616
    /** @var PluginManagePage */
617
    private $ManagePage;
618
619
    /** @var Plugin */
620
    private $Plugin;
621
622
    /** @var string */
623
    private $code;
624
625
    public function __construct(AcceptanceTester $I, $code)
626
    {
627
        parent::__construct($I);
628
        $this->code = $code;
629
    }
630
631
    public function インストール()
632
    {
633
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
634
            ->アップロード('plugins/'.$this->code.'-1.0.0.tgz');
635
636
        $this->initialized = true;
637
638
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
639
640
        $this->検証();
641
642
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
643
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
644
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
645
646
        return $this;
647
    }
648
649 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...
650
    {
651
        $this->ManagePage->独自プラグイン_有効化($this->code);
652
653
        $this->enabled = true;
654
655
        $this->検証();
656
657
        $this->em->refresh($this->Plugin);
658
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
659
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
660
        return $this;
661
    }
662
663 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...
664
    {
665
        $this->ManagePage->独自プラグイン_無効化($this->code);
666
667
        $this->enabled = false;
668
669
        $this->検証();
670
671
        $this->em->refresh($this->Plugin);
672
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
673
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
674
675
        return $this;
676
    }
677
678 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...
679
    {
680
        $this->ManagePage->独自プラグイン_削除($this->code);
681
682
        $this->initialized = false;
683
        $this->enabled = false;
684
685
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
686
687
        $this->検証();
688
689
        $this->em->refresh($this->Plugin);
690
        $this->Plugin = $this->pluginRepository->findByCode($this->code);
691
        $this->I->assertNull($this->Plugin, '削除されている');
692
693
        return $this;
694
    }
695
696
    public function アップデート()
697
    {
698
        $this->ManagePage->独自プラグイン_アップデート($this->code, 'plugins/'.$this->code.'-1.0.1.tgz');
699
700
        $this->検証();
701
702
        $this->em->refresh($this->Plugin);
703
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
704
        $this->I->assertEquals($this->enabled, $this->Plugin->isEnabled(), '有効/無効');
705
706
        return $this;
707
    }
708
}
709
710
class Horizon_Local extends Local_Plugin
711
{
712 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...
713
    {
714
        parent::__construct($I, 'Horizon');
715
        $this->tables[] = 'dtb_dash';
716
        $this->columns[] = 'dtb_cart.is_horizon';
717
        $this->columns[] = 'dtb_cart.dash_id';
718
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'Cart';
719
    }
720
721
    public static function start(AcceptanceTester $I)
722
    {
723
        return new self($I);
724
    }
725
}
726
727
class Horizon_Store extends Store_Plugin
728
{
729 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...
730
    {
731
        parent::__construct($I, 'Horizon');
732
        $this->tables[] = 'dtb_dash';
733
        $this->columns[] = 'dtb_cart.is_horizon';
734
        $this->columns[] = 'dtb_cart.dash_id';
735
        $this->traits['\Plugin\Horizon\Entity\CartTrait'] = 'Cart';
736
    }
737
738
    public static function start(AcceptanceTester $I, Store_Plugin $dependency = null)
739
    {
740
        $result = new self($I);
741
        if ($dependency) {
742
            $result->ManagePage = $dependency->ManagePage;
743
        }
744
        return $result;
745
    }
746
}
747
748
class Emperor_Store extends Store_Plugin
749
{
750
    public function __construct(AcceptanceTester $I)
751
    {
752
        parent::__construct($I, 'Emperor');
753
        $this->publishPlugin('Horizon-1.0.0.tgz');
754
        $this->tables[] = 'dtb_foo';
755
        $this->columns[] = 'dtb_cart.foo_id';
756
        $this->columns[] = 'dtb_dash.is_emperor';
757
        $this->traits['\Plugin\Emperor\Entity\CartTrait'] = 'Cart';
758
        $this->traits['\Plugin\Emperor\Entity\DashTrait'] = 'Dash';
759
    }
760
761
    public static function start(AcceptanceTester $I)
762
    {
763
        return new self($I);
764
    }
765
766 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...
767
    {
768
        $this->ManagePage->ストアプラグイン_有効化($this->code, '「ホライゾン」を先に有効化してください。');
769
770
        $this->検証();
771
772
        $this->em->refresh($this->Plugin);
773
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていないはず');
774
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていないはず');
775
        return $this;
776
    }
777
}
778
779 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...
780
{
781
    public function __construct(AcceptanceTester $I)
782
    {
783
        parent::__construct($I, 'Boomerang');
784
        $this->columns[] = 'dtb_cart.is_boomerang';
785
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'Cart';
786
    }
787
788
    public static function start(AcceptanceTester $I)
789
    {
790
        return new self($I);
791
    }
792
}
793
794 View Code Duplication
class Boomerang_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...
795
{
796
    public function __construct(AcceptanceTester $I)
797
    {
798
        parent::__construct($I, 'Boomerang');
799
        $this->columns[] = 'dtb_cart.is_boomerang';
800
        $this->traits['\Plugin\Boomerang\Entity\CartTrait'] = 'Cart';
801
    }
802
803
    public static function start(AcceptanceTester $I)
804
    {
805
        return new self($I);
806
    }
807
}