Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/tar-6.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess authored Apr 19, 2024
2 parents 6166b19 + 4988b8f commit bf56277
Show file tree
Hide file tree
Showing 40 changed files with 679 additions and 533 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:
# run: |
# sudo apt-fast install -y sharutils
# echo "ADMIN_DIR=$(head -c 10 < /dev/random | uuencode -m - | tail -n 2 |head -n 1 | sed 's,[/+],_,g' | head -c10)/" >> $GITHUB_ENV
- name: Setup environment
run: echo "COMPOSE_FILE=docker-compose.yml:docker-compose.pgsql.yml:docker-compose.dev.yml:docker-compose.owaspzap.yml:docker-compose.owaspzap.daemon.yml" >> $GITHUB_ENV

- name: Setup environment
env:
Expand All @@ -59,7 +57,7 @@ jobs:
PATTERN: ${{ matrix.pattern }}
GROUP: ${{ matrix.group }}
run: |
echo "COMPOSE_FILE=docker-compose.yml:docker-compose.${DB}.yml:docker-compose.dev.yml:docker-compose.owaspzap.yml:docker-compose.owaspzap.daemon.yml" >> $GITHUB_ENV
echo "COMPOSE_FILE=docker-compose.yml:docker-compose.${DB}.yml:docker-compose.dev.yml" >> $GITHUB_ENV
echo "IMAGE_NAME=${OWNER,,}/ec-cube2-php" >> $GITHUB_ENV
if [ $EVENT_NAME = "pull_request" ]; then
echo "TAG=${PHP}-apache-${BASE_REF}" >> $GITHUB_ENV
Expand All @@ -73,8 +71,6 @@ jobs:

- name: Setup to EC-CUBE
run: |
sudo chown -R 1001:1000 zap
sudo chmod -R g+w zap
docker compose up -d --wait
docker compose exec -T ec-cube composer install
docker compose exec -T ec-cube composer require ec-cube2/cli "dev-master@dev" -W
Expand All @@ -99,8 +95,6 @@ jobs:
env:
GROUP: ${{ matrix.group }}
PATTERN: ${{ matrix.pattern }}
HTTPS_PROXY: 'localhost:8090'
HTTP_PROXY: 'localhost:8090'
CI: 1
FORCE_COLOR: 1
run: yarn ${PATTERN} e2e-tests/${GROUP}
Expand Down Expand Up @@ -156,7 +150,7 @@ jobs:
DB: ${{ matrix.db }}
PHP: ${{ matrix.php }}
run: |
echo "COMPOSE_FILE=docker-compose.yml:docker-compose.${DB}.yml:docker-compose.dev.yml:docker-compose.owaspzap.yml:docker-compose.owaspzap.daemon.yml" >> $GITHUB_ENV
echo "COMPOSE_FILE=docker-compose.yml:docker-compose.${DB}.yml:docker-compose.dev.yml" >> $GITHUB_ENV
echo "IMAGE_NAME=${OWNER,,}/ec-cube2-php" >> $GITHUB_ENV
if [ $EVENT_NAME = "pull_request" ]; then
echo "TAG=${PHP}-apache-${BASE_REF}" >> $GITHUB_ENV
Expand All @@ -166,8 +160,6 @@ jobs:
- name: Setup to EC-CUBE
env:
HTTP_URL: https://127.0.0.1:8085/
HTTPS_URL: https://127.0.0.1:8085/
PHP_VERSION_TAG: ${{ matrix.php }}
run: |
sudo chown -R 1001:1000 zap
Expand Down Expand Up @@ -202,8 +194,6 @@ jobs:
- name: Run to E2E testing
env:
HTTP_PROXY: 'localhost:8090'
HTTPS_PROXY: 'localhost:8090'
CI: 1
FORCE_COLOR: 1
DB_TYPE: ${{ matrix.db }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ jobs:
- run: |
docker compose up -d --wait
docker compose exec -T ec-cube composer install
- run: sleep 10
- name: Run to PHPUnit
run: docker compose exec -T ec-cube php data/vendor/bin/phpunit --exclude-group classloader,mysql_prepare
- name: Run to PHPUnit classloader
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ services:
MYSQL_PASSWORD: password
networks:
- backend
healthcheck:
test: mysqladmin ping
interval: 3s
timeout: 3s
retries: 3
5 changes: 5 additions & 0 deletions docker-compose.pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ services:
- pg-database:/var/lib/postgresql/data
networks:
- backend
healthcheck:
test: pg_isready -U eccube_db_user
interval: 3s
timeout: 3s
retries: 3
4 changes: 4 additions & 0 deletions e2e-tests/config/default.config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const ADMIN_DIR = process.env.ADMIN_DIR ? process.env.ADMIN_DIR : 'admin/';
export const ECCUBE_ADMIN_USER = process.env.ECCUBE_ADMIN_USER ? process.env.ECCUBE_ADMIN_USER : 'admin';
export const ECCUBE_ADMIN_PASS = process.env.ECCUBE_ADMIN_PASS ? process.env.ECCUBE_ADMIN_PASS : 'password';
export const ECCUBE_DEFAULT_USER = process.env.ECCUBE_DEFAULT_USER ? process.env.ECCUBE_DEFAULT_USER : 'zap_user@example.com';
export const ECCUBE_DEFAULT_PASS = process.env.ECCUBE_DEFAULT_PASS ? process.env.ECCUBE_DEFAULT_PASS : 'password';
33 changes: 33 additions & 0 deletions e2e-tests/fixtures/admin_login.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test as base, expect } from "@playwright/test";
import { AdminLoginPage } from "../pages/admin/login.page";
import { Mode, ContextType } from '../utils/ZapClient';
import { ECCUBE_ADMIN_USER, ECCUBE_ADMIN_PASS, ADMIN_DIR } from "../config/default.config";
import PlaywrightConfig from '../../playwright.config';

type LoginFixtures = {
loginPage: AdminLoginPage;
};

export const test = base.extend<LoginFixtures>({
loginPage: async ({ page }, use) => {
const loginPage = new AdminLoginPage(page);
if (PlaywrightConfig.use?.proxy === undefined) {
await page.goto(`/${ ADMIN_DIR }`);
await loginPage.login(ECCUBE_ADMIN_USER, ECCUBE_ADMIN_PASS);
} else {
const zapClient = loginPage.getZapClient();
await zapClient.setMode(Mode.Protect);
await zapClient.newSession('/zap/wrk/sessions/admin', true);
await zapClient.importContext(ContextType.Admin);

if (!await zapClient.isForcedUserModeEnabled()) {
await zapClient.setForcedUserModeEnabled();
expect(await zapClient.isForcedUserModeEnabled()).toBeTruthy();
}
await page.goto(`/${ ADMIN_DIR }home.php`);
}
await use(loginPage);
}
});

export { expect } from "@playwright/test";
4 changes: 2 additions & 2 deletions e2e-tests/fixtures/cartin.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test as base } from '@playwright/test';
import { test as base } from '../fixtures/mypage_login.fixture';
import PlaywrightConfig from '../../playwright.config';
import { ProductsDetailPage } from '../pages/products/detail.page';
import { CartPage } from '../pages/cart.page';

/** 商品をカートに入れて購入手続きへ進むフィクスチャ. */
export const test = base.extend({
page: async ({ page }, use) => {
await page.goto(PlaywrightConfig.use.baseURL); // トップへ遷移しないと、スキャン後にカートが空になってしまう
await page.goto(PlaywrightConfig.use?.baseURL ?? "/"); // トップへ遷移しないと、スキャン後にカートが空になってしまう
const productsDetailPage = new ProductsDetailPage(page);
await productsDetailPage.goto(1);
await productsDetailPage.cartIn(2, '抹茶', 'S');
Expand Down
29 changes: 29 additions & 0 deletions e2e-tests/fixtures/mypage_login.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test as base, expect } from "@playwright/test";
import { MypageLoginPage } from "../pages/mypage/login.page";
import { Mode, ContextType } from '../utils/ZapClient';
import { ECCUBE_DEFAULT_USER, ECCUBE_DEFAULT_PASS } from "../config/default.config";
import PlaywrightConfig from '../../playwright.config';

export const test = base.extend({
page: async ({ page }, use) => {
const loginPage = new MypageLoginPage(page);
if (PlaywrightConfig.use?.proxy === undefined) {
await loginPage.goto();
await loginPage.login(ECCUBE_DEFAULT_USER, ECCUBE_DEFAULT_PASS);
} else {
const zapClient = loginPage.getZapClient();
await zapClient.setMode(Mode.Protect);
await zapClient.newSession('/zap/wrk/sessions/front_login', true);
await zapClient.importContext(ContextType.FrontLogin);

if (!await zapClient.isForcedUserModeEnabled()) {
await zapClient.setForcedUserModeEnabled();
expect(await zapClient.isForcedUserModeEnabled()).toBeTruthy();
}
await page.goto(`/mypage/index.php`);
}
use(page);
}
});

export { expect } from "@playwright/test";
41 changes: 41 additions & 0 deletions e2e-tests/pages/admin/login.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Locator, Page } from "@playwright/test";
import { ADMIN_DIR } from "../../config/default.config";
import { ZapClient } from '../../utils/ZapClient';

export class AdminLoginPage {
readonly page: Page;
readonly url: string;

readonly loginId: Locator;
readonly password: Locator;
readonly loginButton: Locator;
zapClient: ZapClient;

constructor(page: Page) {
this.page = page;
this.url = `/${ ADMIN_DIR }index.php`;

this.loginId = page.locator('input[name=login_id]');
this.password = page.locator('input[name=password]');
this.loginButton = page.getByRole('link', { name: 'LOGIN' });
this.zapClient = new ZapClient();
}

async goto() {
await this.page.goto(this.url);
}

async login(loginId: string, password: string) {
await this.loginId.fill(loginId);
await this.password.fill(password);
await this.loginButton.click();
}

async logout() {
await this.page.goto(`/${ ADMIN_DIR }/logout.php`);
}

getZapClient() {
return this.zapClient;
}
}
15 changes: 11 additions & 4 deletions e2e-tests/pages/cart.page.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Locator, Page } from '@playwright/test';
import PlaywrightConfig from '../../playwright.config';
import { ZapClient } from '../utils/ZapClient';

export class CartPage {
readonly page: Page;
readonly url: string;

readonly nextButton: Locator;
zapClient: ZapClient;

constructor(page: Page) {
this.page = page;
this.url = `${PlaywrightConfig.use.baseURL}/cart/index.php`;
this.url = `${ PlaywrightConfig.use?.baseURL ?? "" }/cart/index.php`;
this.nextButton = page.locator('input[name=confirm][alt=購入手続きへ]');
this.zapClient = new ZapClient();
}

async goto() {
Expand All @@ -22,15 +25,15 @@ export class CartPage {
}

getAdditionButton(row?: number) {
return this.page.locator(`table[summary=商品情報] >> tr >> nth=${row ?? 1} >> td >> nth=4 >> [alt="+"]`);
return this.page.locator(`table[summary=商品情報] >> tr >> nth=${ row ?? 1 } >> td >> nth=4 >> [alt="+"]`);
}

getSubtructionButton(row?: number) {
return this.page.locator(`table[summary=商品情報] >> tr >> nth=${row ?? 1} >> td >> nth=4 >> [alt="-"]`);
return this.page.locator(`table[summary=商品情報] >> tr >> nth=${ row ?? 1 } >> td >> nth=4 >> [alt="-"]`);
}

getQuantity(row?: number) {
return this.page.locator(`table[summary=商品情報] >> tr >> nth=${row ?? 1} >> td >> nth=4`);
return this.page.locator(`table[summary=商品情報] >> tr >> nth=${ row ?? 1 } >> td >> nth=4`);
}

async addition(row?: number) {
Expand All @@ -40,4 +43,8 @@ export class CartPage {
async subtruction(row?: number) {
await this.getSubtructionButton(row).click();
}

getZapClient() {
return this.zapClient;
}
}
90 changes: 90 additions & 0 deletions e2e-tests/pages/contact.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { test, expect } from '../fixtures/mypage_login.fixture';
import { Locator, Page } from '@playwright/test';
import PlaywrightConfig from '../../playwright.config';
import { ZapClient } from '../utils/ZapClient';

export class ContactPage {
readonly page: Page;
readonly url: string;

readonly confirmButton: Locator;
readonly submitButton: Locator;
readonly name01: Locator;
readonly name02: Locator;
readonly kana01: Locator;
readonly kana02: Locator;
readonly zip01: Locator;
readonly zip02: Locator;
readonly addr01: Locator;
readonly addr02: Locator;
readonly tel01: Locator;
readonly tel02: Locator;
readonly tel03: Locator;
readonly email: Locator;
readonly emailConfirm: Locator;
readonly contents: Locator;
zapClient: ZapClient;

// 'name01', 'name02', 'kana01', 'kana02', 'zip01', 'zip02', 'addr01', 'addr02', 'tel01', 'tel02', 'tel03'
constructor(page: Page) {
this.page = page;
this.url = `${ PlaywrightConfig.use?.baseURL ?? "" }/contact/index.php`;
this.confirmButton = page.locator('input[name=confirm][alt=確認ページへ]');
this.submitButton = page.locator('input[name=send][alt=送信]');
this.name01 = page.locator('input[name=name01]');
this.name02 = page.locator('input[name=name02]');
this.kana01 = page.locator('input[name=kana01]');
this.kana02 = page.locator('input[name=kana02]');
this.zip01 = page.locator('input[name=zip01]');
this.zip02 = page.locator('input[name=zip02]');
this.addr01 = page.locator('input[name=addr01]');
this.addr02 = page.locator('input[name=addr02]');
this.tel01 = page.locator('input[name=tel01]');
this.tel02 = page.locator('input[name=tel02]');
this.tel03 = page.locator('input[name=tel03]');
this.email = page.locator('input[name=email]');
this.emailConfirm = page.locator('input[name=email_confirm]');
this.contents = page.locator('textarea[name=contents]');
this.zapClient = new ZapClient();
}

async goto() {
await this.page.goto(this.url);
}

async confirm() {
await this.confirmButton.click();
}

async submit() {
await this.submitButton.click();
}

async expectConfirmPage() {
this.getInputFields().forEach(async (fieled) => {
await expect(fieled).toBeHidden();
await expect(fieled).not.toBeEmpty();
});
}

private getInputFields(): Locator[] {
return [
this.name01,
this.name02,
this.kana01,
this.kana02,
this.zip01,
this.zip02,
this.addr01,
this.addr02,
this.tel01,
this.tel02,
this.tel03,
this.email,
this.emailConfirm
];
}
getZapClient() {
return this.zapClient;
}
}
43 changes: 43 additions & 0 deletions e2e-tests/pages/mypage/login.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Locator, Page } from "@playwright/test";
import { ZapClient } from '../../utils/ZapClient';

export class MypageLoginPage {
readonly page: Page;
readonly url: string;

readonly loginEmail: Locator;
readonly loginPass: Locator;
readonly loginButton: Locator;
readonly logoutButton: Locator;
zapClient: ZapClient;

constructor(page: Page) {
this.page = page;
this.url = '/mypage/login.php';

this.loginEmail = page.getByRole('textbox', { name: 'メールアドレスを入力して下さい' });
this.loginPass = page.getByRole('textbox', { name: 'パスワードを入力して下さい' });
this.loginButton = page.locator('id=header_login_form').getByRole('button');
this.logoutButton = page.getByRole('button', { name: 'ログアウト' }).first();
this.zapClient = new ZapClient();
}

async goto() {
await this.page.goto(this.url);
}

async login(email: string, password: string) {
await this.loginEmail.fill(email);
await this.loginPass.fill(password);
await this.loginButton.click();
}

async logout() {
await this.goto();
await this.logoutButton.click();
}

getZapClient() {
return this.zapClient;
}
}
Loading

0 comments on commit bf56277

Please sign in to comment.