Skip to content

Commit

Permalink
プラグインテストの自動化
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisL-meier committed Oct 2, 2023
1 parent b976142 commit 66a05b0
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/config/eccube/packages/dev/web_profiler.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
web_profiler:
toolbar: true
toolbar: false
intercept_redirects: false

framework:
Expand Down
4 changes: 2 additions & 2 deletions codeception/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ modules:
host: '%WEB_DRIVER_HOST%'
port: '%WEB_DRIVER_PORT%'
url: '%BASE_URL%' # テスト対象のurl
window_size: 1680x3000
window_size: 1920x1680
wait: 10
capabilities:
unexpectedAlertBehaviour: 'accept'
Expand Down Expand Up @@ -68,6 +68,6 @@ env:
browser: chrome
capabilities:
chromeOptions:
args: ["--headless", "--disable-gpu"]
args: ["--window-size=1920,1680", "--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]
prefs:
download.default_directory: '%PWD%/codeception/_support/_downloads'
97 changes: 97 additions & 0 deletions codeception/acceptance/Plugin/PluginVerifyCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php


namespace Plugin;

use AcceptanceTester;
use Codeception\Util\Fixtures;
use Eccube\Common\EccubeConfig;

/**
* @group plugin_verify
*/
class PluginVerifyCest
{
/** @var EccubeConfig */
private $config;
/** プラグインコード */
private $plugin_code;

public function _before(AcceptanceTester $I){
if(!file_exists(__DIR__ . "/../../../var/cache/dev/htmlpurifier")){
mkdir(__DIR__ . "/../../../var/cache/dev/htmlpurifier", 775);
}
exec("php bin/console cache:clear --no-warmup");
$this->config = Fixtures::get('test_config');
$I->loginAsAdmin();
}
public function 認証キーを入力(AcceptanceTester $I)
{
$I->amOnPage('/admin/store/plugin/authentication_setting');
$config = Fixtures::get('test_config');
$I->fillField('/html/body/div[1]/div[3]/form/div[1]/div/div[2]/div/div[2]/div[2]/div[2]/input', $config['ECCUBE_PLUGIN_VERIFY_KEY']);
$I->click("/html/body/div[1]/div[3]/form/div[2]/div/div/div[2]/div/div/button");
$I->wait(5);
$I->see('保存しました');
}
public function プラグイン_インストール(AcceptanceTester $I){
$I->amOnPage("/admin/store/plugin");
$config = Fixtures::get('test_config');
$pluginName = $config['ECCUBE_PLUGIN_VERIFY_NAME'];
$I->see($pluginName);
$span = '//*[@id="page_admin_store_plugin"]/div[1]/div[3]/div[2]/div/div/div[1]/div[2]/table/tbody/tr/td[1]/div/span[text() = "'.$pluginName.'"]';
$tr = $span . '/ancestor::tr';
$this->plugin_code= $I->grabTextFrom($tr . "/td[3]/p");
echo("プラグインコード:" . $this->plugin_code . "\n");
$button = $tr . '/td[5]/a';
$I->click($button);
$I->wait(3);
$I->see("インストール確認");
$I->click("/html/body/div[1]/div[3]/div[2]/div/div/div/div[2]/div[2]/div/button[2]");
$I->wait(1);
$I->click("/html/body/div[1]/div[3]/div[3]/div/div/div[3]/button[2]");
//インストール処理が終わるまで待機
$I->waitForJS("return $.active == 0;", 60);
$I->see("インストールが完了しました。");
$I->click("/html/body/div[1]/div[3]/div[3]/div/div/div[3]/a");
}
public function プラグイン_有効化(AcceptanceTester $I){
$I->amOnPage("/admin/store/plugin");
//ステータスを確認
$config = Fixtures::get('test_config');
$span = '//*[@id="page_admin_store_plugin"]/div[1]/div[3]/div[2]/div/div/div[1]/div[2]/table/tbody/tr/td[3]/p[text() = "'.$this->plugin_code.'"]';
$tr = $span . '/ancestor::tr';
$status = $tr . '/td[4]/span';
$status_text = $I->grabTextFrom($status);
echo("プラグインのステータス:". $status_text ."\n");
$activateButton = $tr . '/td[6]/div/div[2]/a';
$I->click($activateButton);
$I->wait(3);
$I->see("を有効にしました");
}
public function プラグイン_無効化(AcceptanceTester $I){
$I->amOnPage("/admin/store/plugin");
$span = '//*[@id="page_admin_store_plugin"]/div[1]/div[3]/div[2]/div/div/div[1]/div[2]/table/tbody/tr/td[3]/p[text() = "'.$this->plugin_code.'"]';
$tr = $span . '/ancestor::tr';
$status = $tr . '/td[4]/span';
$status_text = $I->grabTextFrom($status);
echo("プラグインのステータス:". $status_text ."\n");
$disableButton = $tr . '/td[6]/div/div[2]/a';
$I->click($disableButton);
$I->wait(3);
$I->see("を無効にしました");
}
public function プラグイン_削除(AcceptanceTester $I){
$I->amOnPage("/admin/store/plugin");
$span = '//*[@id="page_admin_store_plugin"]/div[1]/div[3]/div[2]/div/div/div[1]/div[2]/table/tbody/tr/td[3]/p[text() = "'.$this->plugin_code.'"]';
$tr = $span . '/ancestor::tr';
$uninstallButton = $tr . '/td[6]/div/div[1]/a';
$I->click($uninstallButton);
$I->wait(1);
$I->click("/html/body/div[1]/div[3]/div[2]/div/div/div[1]/div[3]/div/div/div[3]/button[2]");
$I->waitForJS("return $.active == 0;", 60);
$I->see("削除が完了しました。");
$I->click('//*[@id="officialPluginDeleteModal"]/div/div/div[3]/button[3]');
$I->wait(3);
}
}
2 changes: 2 additions & 0 deletions codeception/acceptance/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ fixture_customer_num = 10 ; 各カスタマー作成時に注文を1つづつ
fixture_product_num = 20
fixture_order_num = 25
hostname = 'eccube4' ; 対象EC-CUBE4が稼働しているサーバーのホスト名
ECCUBE_PLUGIN_VERIFY_NAME = "構造化マークアッププラグイン(4.2系)"
ECCUBE_PLUGIN_VERIFY_KEY = d285840e84bb5ab7c5650250818a75970877c761
2 changes: 1 addition & 1 deletion codeception/docker/docker-php-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

while ! nc -z ec-cube 80; do sleep 1; done; while ! nc -z chrome 4444; do sleep 1; done; ls -la && /var/www/html/vendor/bin/codecept run -d acceptance --env chrome-headless,local -g admin01
while ! nc -z ec-cube 80; do sleep 1; done; while ! nc -z chrome 4444; do sleep 1; done; ls -la && php bin/console cache:clear --no-warmup && /var/www/html/vendor/bin/codecept run -d acceptance --env chrome-headless,local -g plugin_verify

14 changes: 13 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"doctrine/persistence": "^2.5",
"easycorp/easy-log-handler": "^1.0",
"ec-cube/plugin-installer": "^2.0",
"ec-cube/relatedproduct42": "^4.2",
"egulias/email-validator": "^2.1",
"exercise/htmlpurifier-bundle": "^3.1",
"friendsofphp/php-cs-fixer": "^3.8",
Expand Down Expand Up @@ -186,7 +187,7 @@
},
"config": {
"platform": {
"php": "7.4.0"
"php": "8.1.18"
},
"preferred-install": {
"*": "dist"
Expand All @@ -199,5 +200,16 @@
"ec-cube/plugin-installer": true,
"symfony/flex": true
}
},
"repositories": {
"eccube": {
"type": "composer",
"url": "https://package-api-c2.ec-cube.net/v42",
"options": {
"http": {
"header": ["X-ECCUBE-KEY: d285840e84bb5ab7c5650250818a75970877c761"]
}
}
}
}
}
59 changes: 40 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docker-compose.codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ services:
memory: 16G
chrome:
image: selenium/standalone-chrome
volumes:
- ./codeception/_support/_downloads:/var/www/html/codeception/_support/_downloads
networks:
- backend
deploy:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
environment:
# EC-CUBE environments
APP_ENV: "dev"
APP_DEBUG: 1
APP_DEBUG: 0
DATABASE_URL: "sqlite:///var/eccube.db"
DATABASE_SERVER_VERSION: 3
DATABASE_CHARSET: 'utf8'
Expand Down
27 changes: 27 additions & 0 deletions plugin-verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
declare -r CURRENT_DIR=$PWD
echo "彩プラグイン検証ツール"
echo "----------------------"
echo "検証するプラグインの情報を入力してください。"
echo " "
read -p 'プラグイン名:' pluginname
read -p '認証キー:' key

if grep -Fq "ECCUBE_PLUGIN_VERIFY_NAME =" codeception/acceptance/config.ini
then
sed -i '/ECCUBE_PLUGIN_VERIFY_NAME =/d' codeception/acceptance/config.ini
echo "ECCUBE_PLUGIN_VERIFY_NAME = \"$pluginname\"" >> codeception/acceptance/config.ini
else
echo "ECCUBE_PLUGIN_VERIFY_NAME = \"$pluginname\"" >> codeception/acceptance/config.ini
fi

if grep -Fq "ECCUBE_PLUGIN_VERIFY_KEY =" codeception/acceptance/config.ini
then
sed -i '/ECCUBE_PLUGIN_VERIFY_KEY =/d' codeception/acceptance/config.ini
echo "ECCUBE_PLUGIN_VERIFY_KEY = $key" >> codeception/acceptance/config.ini
else
echo "ECCUBE_PLUGIN_VERIFY_KEY = $key" >> codeception/acceptance/config.ini
fi

echo "dockerコンテナを立ち上げます。少々お待ちください。"
docker compose -f docker-compose.yml -f docker-compose.mysql.yml -f docker-compose.codeception.yml up -d --build

0 comments on commit 66a05b0

Please sign in to comment.