Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefilterTransform の後方互換処理 #364

Merged
merged 6 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ php:
- 7.3
- 7.4

addons:
apt:
sources:
- google-chrome
packages:
- dpkg # see https://github.com/travis-ci/travis-ci/issues/9361
- google-chrome-stable

env:
global:
- DBNAME=myapp_test DBSERVER=127.0.0.1 HTTP_URL=http://localhost:8085/ HTTPS_URL=http://localhost:8085/
Expand Down Expand Up @@ -66,6 +58,9 @@ matrix:
- php: 7.3
env: DB=pgsql USER=postgres DBPASS=password DBUSER=postgres COVERAGE=true

before_install:
- if [[ $DIST = 'trusty' ]]; then sudo apt-get -y install google-chrome-stable --allow-unauthenticated ; fi

before_script:
- if [[ $DB = 'mysql' ]]; then mysql -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';" ; fi

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

$I = new AcceptanceTester($scenario);
$I->wantTo('プラグインの prefilterTransform が正常に動作するかを確認する');
$I->amOnPage('/admin');

$I->fillField('input[name=login_id]', 'admin');
$I->fillField('input[name=password]', 'password');
$I->click(['css' => '.btn-tool-format']);

$I->see('ログイン : 管理者 様');

$I->amGoingTo('オーナーズストア>プラグイン管理');
$I->amOnPage('/admin/ownersstore/');

$I->expect('プラグインを圧縮します');

$file = 'PrefilterTransformPlugin.tar.gz';
$dir = __DIR__.'/../../../../tests/class/fixtures/plugin/PrefilterTransformPlugin';
chdir($dir);
$tar = new Archive_Tar($file, true);
if ($tar->create(['PrefilterTransformPlugin.php', 'plugin_info.php'])) {
rename($dir.'/'.$file, __DIR__.'/../../../_data/'.$file);
$I->attachFile(['css' => '#system > table > tbody > tr > td > input'], $file);
}
$I->expect('プラグインをインストールします');
$I->click(['css' => '#system > table > tbody > tr > td > a']); // インストールボタン

$I->wait(1);
$I->seeInPopup('プラグインをインストールしても宜しいでしょうか?');
$I->acceptPopup();

$I->wait(1);
$I->seeInPopup('プラグインをインストールしました');
$I->acceptPopup();

$I->amOnPage('/admin/ownersstore/');

$I->expect('プラグインを有効化します');
$I->click(['css' => '#system > table.system-plugin > tbody > tr:nth-child(2) > td.plugin_info > div > label > input[type=checkbox]']); // 有効化ボタン

$I->wait(1);
$I->seeInPopup('プラグインを有効にしても宜しいですか?');
$I->acceptPopup();

$I->wait(1);
$I->seeInPopup('有効にしました。');
$I->acceptPopup();

$I->expect('prefilterTransform の動作を確認します');
$I->amOnPage('/products/list.php');
$I->seeInSource('<p>プラグイン仕様書の記述方法</p>');
$I->seeInSource('<p>一部のプラグインは完全一致が使用されている</p>');

$I->amOnPage('/admin/ownersstore/');
$I->expect('プラグインを無効化します');
$I->click(['css' => '#system > table.system-plugin > tbody > tr:nth-child(2) > td.plugin_info > div > label > input[type=checkbox]']); // 無効化ボタン

$I->wait(1);
$I->seeInPopup('プラグインを無効にしても宜しいですか?');
$I->acceptPopup();

$I->wait(1);
$I->seeInPopup('無効にしました。');
$I->acceptPopup();

$I->expect('プラグインを削除します');
$I->click(['css' => '#system > table.system-plugin > tbody > tr:nth-child(2) > td.plugin_info > div > a:nth-child(6)']); // 削除ボタン

$I->wait(1);
$I->seeInPopup('プラグインを削除しても宜しいですか?');
$I->acceptPopup();

$I->wait(1);
$I->seeInPopup('削除しました');
$I->acceptPopup();
22 changes: 20 additions & 2 deletions data/class/SC_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function prefilter_transform($source, Smarty_Internal_Template $template)
// フックポイントを実行.
$objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
if ($objPlugin) {
$objPlugin->doAction('prefilterTransform', array(&$source, $this->objPage, $template->smarty->_current_file));
$objPlugin->doAction('prefilterTransform', array(&$source, $this->objPage, $this->getCurrentTemplateFile($template)));
}
}

Expand All @@ -167,7 +167,7 @@ public function outputfilter_transform($source, Smarty_Internal_Template $templa
// フックポイントを実行.
$objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
if ($objPlugin) {
$objPlugin->doAction('outputfilterTransform', array(&$source, $this->objPage, $template->smarty->_current_file));
$objPlugin->doAction('outputfilterTransform', array(&$source, $this->objPage, $this->getCurrentTemplateFile($template)));
}
}

Expand Down Expand Up @@ -266,4 +266,22 @@ public function lower_compatibility_smarty($tpl_source, $smarty)
return preg_replace($pattern, $replace, $tpl_source);
}

/**
* 現在のテンプレートファイルパスを返す.
*
* 2.13(Smarty2) との後方互換用.
* 2.13 で使用していた $template->smarty->_current_file は $template->source->filepath の後方互換用変数だが
* 以下ような振舞いの違いがある
* - Smarty2: テンプレートディレクトリからの相対パス
* - Smarty3: テンプレートディレクトリからの絶対パス
* この関数は 2.13 と同様にテンプレートディレクトリからの相対パスを返す
*
* @param Smarty_Internal_Template $template
* @return string 現在のテンプレートファイルパス
*/
public function getCurrentTemplateFile(Smarty_Internal_Template $template)
{
$current_file = str_replace($template->smarty->getTemplateDir(), '', $template->source->filepath);
return str_replace('\\', '/', $current_file); // Windows 向けにパスの区切り文字を正規化する
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class PrefilterTransformPlugin extends SC_Plugin_Base
{
public function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source);
switch($objPage->arrPageLayout['device_type_id']) {
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) {
// see http://downloads.ec-cube.net/manual/12.0_plugin/plugin.pdf
$objTransform->select('h2.title')->insertBefore('<p>プラグイン仕様書の記述方法</p>');
}
if ('products/list.tpl' === $filename) {
$objTransform->select('h2.title')->insertBefore('<p>一部のプラグインは完全一致が使用されている</p>');
}
break;
case DEVICE_TYPE_ADMIN:
default:
}
$source = $objTransform->getHTML();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class plugin_info {
static $PLUGIN_CODE = 'PrefilterTransformPlugin';
static $PLUGIN_NAME = 'PrefilterTransformPlugin';
static $CLASS_NAME = 'PrefilterTransformPlugin';
static $PLUGIN_VERSION = '0.0.0';
static $COMPLIANT_VERSION = '2.17';
static $AUTHOR = 'dummy';
static $DESCRIPTION = 'dummy';
static $HOOK_POINTS = [
['prefilterTransform', 'prefilterTransform']
];
}