Completed
Push — dev/plugin-misc ( 2b845e...8786ba )
by Kiyotaka
05:38
created

Emperor_Store::アップデート()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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