Failed Conditions
Push — dev/plugin-misc ( 791e2c...ef9c63 )
by Kiyotaka
12:12
created

EA10PluginCest::_before()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 10
loc 10
rs 9.9332
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 install_enable_enable(\AcceptanceTester $I)
50
    {
51
        Horizon_Store::start($I)
52
            ->インストール()
53
            ->新しいタブで開く()
54
            ->有効化()
55
            ->前のタブに戻る()
56
            ->既に有効なものを有効化();
57
    }
58
59
    public function install_enable_disable_enable_disable_remove_store(\AcceptanceTester $I)
60
    {
61
        Horizon_Store::start($I)
62
            ->インストール()
63
            ->有効化()
64
            ->無効化()
65
            ->有効化()
66
            ->無効化()
67
            ->削除();
68
    }
69
70
    public function install_enable_disable_enable_disable_remove_local(\AcceptanceTester $I)
71
    {
72
        Horizon_Local::start($I)
73
            ->インストール()
74
            ->有効化()
75
            ->無効化()
76
            ->有効化()
77
            ->無効化()
78
            ->削除();
79
    }
80
81
    public function install_remove_local(\AcceptanceTester $I)
82
    {
83
        Horizon_Local::start($I)
84
            ->インストール()
85
            ->削除();
86
    }
87
88
    public function install_remove_store(\AcceptanceTester $I)
89
    {
90
        Horizon_Store::start($I)
91
            ->インストール()
92
            ->削除();
93
    }
94
95
    public function install_update_remove_store(\AcceptanceTester $I)
96
    {
97
        Horizon_Store::start($I)
98
            ->インストール()
99
            ->アップデート()
100
            ->削除();
101
    }
102
103
104
105
    public function install_update_remove_local(\AcceptanceTester $I)
106
    {
107
        Horizon_Local::start($I)
108
            ->インストール()
109
            ->アップデート()
110
            ->削除();
111
    }
112
113
    public function install_enable_disable_update_enable_disable_remove_local(\AcceptanceTester $I)
114
    {
115
        Horizon_Local::start($I)
116
            ->インストール()
117
            ->有効化()
118
            ->無効化()
119
            ->アップデート()
120
            ->有効化()
121
            ->無効化()
122
            ->削除();
123
    }
124
125
    public function install_enable_disable_update_enable_disable_remove_store(\AcceptanceTester $I)
126
    {
127
        Horizon_Store::start($I)
128
            ->インストール()
129
            ->有効化()
130
            ->無効化()
131
            ->アップデート()
132
            ->有効化()
133
            ->無効化()
134
            ->削除();
135
    }
136
137
    public function install_enable_update_disable_remove_store(\AcceptanceTester $I)
138
    {
139
        Horizon_Store::start($I)
140
            ->インストール()
141
            ->有効化()
142
            ->アップデート()
143
            ->無効化()
144
            ->削除();
145
    }
146
147
    public function install_enable_update_disable_remove_local(\AcceptanceTester $I)
148
    {
149
        Horizon_Local::start($I)
150
            ->インストール()
151
            ->有効化()
152
            ->アップデート()
153
            ->無効化()
154
            ->削除();
155
    }
156
157
    public function install_update_enable_disable_remove_local(\AcceptanceTester $I)
158
    {
159
        Horizon_Local::start($I)
160
            ->インストール()
161
            ->アップデート()
162
            ->有効化()
163
            ->無効化()
164
            ->削除();
165
    }
166
167
    public function install_update_enable_disable_remove_store(\AcceptanceTester $I)
168
    {
169
        Horizon_Store::start($I)
170
            ->インストール()
171
            ->アップデート()
172
            ->有効化()
173
            ->無効化()
174
            ->削除();
175
    }
176
177
    public function install_assets_local(\AcceptanceTester $I)
178
    {
179
        $this->publishPlugin('Assets-1.0.0.tgz');
180
181
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
182
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
183
184
        $I->assertFileNotExists($assetsPath);
185
        $I->assertFileNotExists($updatedPath);
186
187
        $ManagePage = PluginLocalInstallPage::go($I)->アップロード('plugins/Assets-1.0.0.tgz');
188
        $I->assertFileExists($assetsPath);
189
        $I->assertFileNotExists($updatedPath);
190
191
        $ManagePage->独自プラグイン_有効化('Assets');
192
        $I->assertFileExists($assetsPath);
193
        $I->assertFileNotExists($updatedPath);
194
195
        $ManagePage->独自プラグイン_無効化('Assets');
196
        $I->assertFileExists($assetsPath);
197
        $I->assertFileNotExists($updatedPath);
198
199
        $ManagePage->独自プラグイン_アップデート('Assets', 'plugins/Assets-1.0.1.tgz');
200
        $I->assertFileExists($assetsPath);
201
        $I->assertFileExists($updatedPath);
202
203
        $ManagePage->独自プラグイン_削除('Assets');
204
        $I->assertFileNotExists($assetsPath);
205
        $I->assertFileNotExists($updatedPath);
206
    }
207
208
    public function install_assets_store(\AcceptanceTester $I)
209
    {
210
        // 最初のバージョンを作成
211
        $this->publishPlugin('Assets-1.0.0.tgz');
212
213
        $assetsPath = $this->config['plugin_html_realdir'].'/Assets/assets/assets.js';
214
        $updatedPath = $this->config['plugin_html_realdir'].'/Assets/assets/updated.js';
215
        $I->assertFileNotExists($assetsPath);
216
        $I->assertFileNotExists($updatedPath);
217
218
        $ManagePage = PluginSearchPage::go($I)
219
            ->入手する('Assets')
220
            ->インストール();
221
        $I->assertFileNotExists($assetsPath);
222
        $I->assertFileNotExists($updatedPath);
223
224
        $ManagePage->ストアプラグイン_有効化('Assets');
225
        $I->assertFileExists($assetsPath);
226
        $I->assertFileNotExists($updatedPath);
227
228
        $ManagePage->ストアプラグイン_無効化('Assets');
229
        $I->assertFileExists($assetsPath);
230
        $I->assertFileNotExists($updatedPath);
231
232
        // 新しいバージョンを作成
233
        $this->publishPlugin('Assets-1.0.1.tgz');
234
235
        $I->reloadPage();
236
        $ManagePage->ストアプラグイン_アップデート('Assets')->アップデート();
237
        $I->assertFileExists($assetsPath);
238
        $I->assertFileExists($updatedPath);
239
240
        $ManagePage->ストアプラグイン_無効化('Assets');
241
        $I->assertFileExists($assetsPath);
242
        $I->assertFileExists($updatedPath);
243
244
        $ManagePage->ストアプラグイン_削除('Assets');
245
        $I->assertFileNotExists($assetsPath);
246
        $I->assertFileNotExists($updatedPath);
247
    }
248
249
    private function publishPlugin($fileName)
250
    {
251
        copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
252
    }
253
254
    private function tableExists($tableName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
255
    {
256
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
257
    }
258
259
    private function columnExists($tableName, $columnName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
260
    {
261
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
262
    }
263
}
264
265
abstract class Abstract_Plugin
266
{
267
    /** @var AcceptanceTester */
268
    protected $I;
269
270
    /** @var EntityManager */
271
    protected $em;
272
273
    /** @var \Doctrine\DBAL\Connection */
274
    protected $conn;
275
276
    /** @var PluginRepository */
277
    protected $pluginRepository;
278
279
    /** @var EccubeConfig */
280
    protected $config;
281
282
    /**
283
     * Abstract_Plugin constructor.
284
     */
285 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...
286
    {
287
        $this->I = $I;
288
        $this->em = Fixtures::get('entityManager');
289
        $this->conn = $this->em->getConnection();
290
        $this->pluginRepository = $this->em->getRepository(Plugin::class);
291
        $this->config = Fixtures::get('config');
292
    }
293
294
    protected function tableExists($tableName)
295
    {
296
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}';")->fetch()['count'] > 0;
297
    }
298
299
    protected function columnExists($tableName, $columnName)
300
    {
301
        return $this->conn->executeQuery("SELECT count(*) AS count FROM information_schema.columns WHERE table_name = '${tableName}' AND column_name = '${columnName}';")->fetch()['count'] == 1;
302
    }
303
304
    public function 新しいタブで開く()
305
    {
306
        $this->I->executeJS("window.open(location.href, 'other')");
307
        $this->I->switchToWindow('other');
308
        return $this;
309
    }
310
311
    public function 前のタブに戻る()
312
    {
313
        $this->I->switchToPreviousTab();
314
        return $this;
315
    }
316
}
317
318
class Horizon_Store extends Abstract_Plugin
319
{
320
    /** @var PluginManagePage */
321
    private $ManagePage;
322
323
    /** @var Plugin */
324
    private $Plugin;
325
326
    private $initialized = false;
327
328
    public static function start(AcceptanceTester $I)
329
    {
330
        return new Horizon_Store($I);
331
    }
332
333
    public function __construct(AcceptanceTester $I)
334
    {
335
        parent::__construct($I);
336
    }
337
338 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...
339
    {
340
        $this->publishPlugin('Horizon-1.0.0.tgz');
341
        /*
342
         * インストール
343
         */
344
        $this->ManagePage = PluginSearchPage::go($this->I)
345
            ->入手する('Horizon')
346
            ->インストール();
347
348
        $this->I->assertFalse($this->tableExists('dtb_dash'), 'テーブルがない');
349
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがない');
350
351
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
352
        $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
353
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
354
355
        return $this;
356
    }
357
358 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...
359
    {
360
        $this->ManagePage->ストアプラグイン_有効化('Horizon');
361
362
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
363
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
364
365
        $this->em->refresh($this->Plugin);
366
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
367
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
368
369
        $this->initialized = true;
370
        return $this;
371
    }
372
373 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...
374
    {
375
        $this->ManagePage->ストアプラグイン_有効化('Horizon', '「ホライゾン」は既に有効です。');
376
377
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
378
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
379
380
        $this->em->refresh($this->Plugin);
381
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
382
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
383
384
        $this->initialized = true;
385
386
387
        return $this;
388
    }
389
390 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...
391
    {
392
        $this->ManagePage->ストアプラグイン_無効化('Horizon');
393
394
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
395
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
396
397
        $this->em->refresh($this->Plugin);
398
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
399
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
400
401
        return $this;
402
    }
403
404 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...
405
    {
406
        $this->ManagePage->ストアプラグイン_削除('Horizon');
407
408
        $this->I->assertFalse($this->tableExists('dtb_dash'), 'テーブルが消えている');
409
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'), 'カラムが消えている');
410
411
        $this->em->refresh($this->Plugin);
412
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
413
        $this->I->assertNull($this->Plugin, '削除されている');
414
415
        return $this;
416
    }
417
418
    public function アップデート()
419
    {
420
        $this->publishPlugin('Horizon-1.0.1.tgz');
421
422
        $this->I->reloadPage();
423
        $this->ManagePage->ストアプラグイン_アップデート('Horizon')->アップデート();
424
425
        $this->em->refresh($this->Plugin);
426
427
        if ($this->initialized) {
428
            $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
429
            $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
430
        } else {
431
            $this->I->assertFalse($this->Plugin->isInitialized(), '初期化されていない');
432
            $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
433
        }
434
435
        return $this;
436
    }
437
438
    private function publishPlugin($fileName)
439
    {
440
        $published = copy(codecept_data_dir().'/'.'plugins/'.$fileName, codecept_root_dir().'/repos/'.$fileName);
441
        $this->I->assertTrue($published, "公開できた ${fileName}");
442
    }
443
}
444
445
class Horizon_Local extends Abstract_Plugin
446
{
447
    /** @var PluginManagePage */
448
    private $ManagePage;
449
450
    /** @var Plugin */
451
    private $Plugin;
452
453
    private $enabled = false;
454
455
    public static function start(AcceptanceTester $I)
456
    {
457
        return new Horizon_Local($I);
458
    }
459
460
    public function __construct(AcceptanceTester $I)
461
    {
462
        parent::__construct($I);
463
    }
464
465 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...
466
    {
467
        $this->ManagePage = PluginLocalInstallPage::go($this->I)
468
            ->アップロード('plugins/Horizon-1.0.0.tgz');
469
470
        $this->I->see('プラグインをインストールしました。', PluginManagePage::完了メーッセージ);
471
472
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
473
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
474
475
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
476
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されていない');
477
        $this->I->assertFalse($this->Plugin->isEnabled(), '有効化されていない');
478
479
        return $this;
480
    }
481
482 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...
483
    {
484
        $this->ManagePage->独自プラグイン_有効化('Horizon');
485
486
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
487
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
488
489
        $this->em->refresh($this->Plugin);
490
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
491
        $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
492
493
        $this->enabled = true;
494
        return $this;
495
    }
496
497 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...
498
    {
499
        $this->ManagePage->独自プラグイン_無効化('Horizon');
500
501
        $this->I->assertTrue($this->tableExists('dtb_dash'), 'テーブルがある');
502
        $this->I->assertTrue($this->columnExists('dtb_cart', 'is_horizon'), 'カラムがある');
503
504
        $this->em->refresh($this->Plugin);
505
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
506
        $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
507
508
        return $this;
509
    }
510
511 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...
512
    {
513
        $this->ManagePage->独自プラグイン_削除('Horizon');
514
515
        $this->I->see('プラグインを削除しました。', PluginManagePage::完了メーッセージ);
516
517
        $this->I->assertFalse($this->tableExists('dtb_dash'), 'テーブルが削除されている');
518
        $this->I->assertFalse($this->columnExists('dtb_cart', 'is_horizon'), 'カラムが削除されている');
519
520
        $this->em->refresh($this->Plugin);
521
        $this->Plugin = $this->pluginRepository->findByCode('Horizon');
522
        $this->I->assertNull($this->Plugin, '削除されている');
523
524
        return $this;
525
    }
526
527
    public function アップデート()
528
    {
529
        $this->ManagePage->独自プラグイン_アップデート('Horizon', 'plugins/Horizon-1.0.1.tgz');
530
531
        $this->em->refresh($this->Plugin);
532
        $this->I->assertTrue($this->Plugin->isInitialized(), '初期化されている');
533
534
        if ($this->enabled) {
535
            $this->I->assertTrue($this->Plugin->isEnabled(), '有効化されている');
536
        } else {
537
            $this->I->assertFalse($this->Plugin->isEnabled(), '無効化されている');
538
        }
539
540
        return $this;
541
    }
542
}