Completed
Push — dev/plugin-misc ( a55c45...1a5d52 )
by Kiyotaka
06:27
created

install_update_enable_disable_remove_local()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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