/** include_pathの設定(このtest runnerがあるディレクトリを追加) */
ini_set('include_path', realpath(ETHNA_INSTALL_BASE . '/class') . PATH_SEPARATOR . ini_get('include_path'));
-
/** Ethna関連クラスのインクルード */
require_once ETHNA_INSTALL_BASE . '/Ethna.php';
define('ETHNA_TEST_DIR', ETHNA_BASE . '/test');
define('ETHNA_TEST_PROJECT', 'mockproject');
define('ETHNA_TEST_SKELDIR', ETHNA_TEST_DIR . '/skel/');
+define('ETHNA_TEST_SKELTPLDIR', ETHNA_TEST_SKELDIR . '/template/');
/**
- * ethna command Emulator Class.
+ * ethna command, and project Emulator Class.
*
* @access public
*/
return $r;
}
+ // set plain ActionForm
+ $ctl =& $this->getController();
+ $backend =& $ctl->getBackend();
+ $af =& new Ethna_ActionForm($ctl);
+ $backend->setActionForm($af);
+
return true;
}
+ /**
+ * アプリケーションのエントリポイントをエミュレートします。
+ *
+ * @access public
+ * @param mixed $action_name 指定のアクション名(省略可)
+ * @param array $submit_value ブラウザからSubmitする値
+ * @return string ブラウザへの出力
+ */
+ function runMain($action_name = 'index', $submit_value = array())
+ {
+ if (($r = $this->create_ifnot_exists()) !== true) {
+ return $r;
+ }
+
+ $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_POST["action_${action_name}"] = true;
+ $_POST = array_merge($_POST, $submit_value);
+
+ $c =& $this->getController();
+ $c->setGateway(GATEWAY_WWW);
+ ob_start();
+ @$c->trigger($action_name, ""); // suppress header related error.
+ $c->end();
+ $result = ob_get_contents();
+ ob_end_clean();
+
+ return $result;
+ }
+
/*
* 作成したプロジェクトのコントローラクラス
* のインスタンスを取得します。
if (($r = $this->create_ifnot_exists()) !== true) {
return $r;
}
- return Ethna_Handle::getAppController($this->proj_basedir);
+ $ctl =& Ethna_Handle::getAppController($this->proj_basedir);
+
+ // キャッシュが返されるため、$GLOBALSが設定されない場合がある
+ $GLOBALS['_Ethna_controller'] =& $ctl;
+ return $ctl;
}
/*
--- /dev/null
+<?php
+/**
+ * Ethna_ViewClass_FormHelper_Test.php
+ *
+ * @package Ethna
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ */
+
+require_once ETHNA_INSTALL_BASE . '/test/Ethna_MockProject.php';
+
+/**
+ * Ethna_ViewClass のうち、フォームヘルパ
+ * に関連するテストケースを集めたクラス
+ *
+ * @package Ethna
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ * @access public
+ */
+class Ethna_ViewClass_FormHelper_Test extends Ethna_UnitTestBase
+{
+ var $project;
+
+ function setUp()
+ {
+ $this->project =& new Ethna_MockProject();
+ $this->project->create();
+ }
+
+ function tearDown()
+ {
+ $this->project->delete();
+ unset($GLOBALS['_Ethna_controller']);
+ }
+
+ function test_formhelper_Text()
+ {
+ $action_name = $tpl_name = 'texttest';
+ $action_skel = ETHNA_TEST_SKELDIR . 'skel.action.formhelper.php';
+ $this->project->runCmd('add-action',
+ array(
+ '-s',
+ $action_skel,
+ $action_name,
+ )
+ );
+ $tpl_skel = ETHNA_TEST_SKELTPLDIR . 'skel.template.text.tpl';
+ $this->project->runCmd('add-template',
+ array(
+ '-s',
+ $tpl_skel,
+ $tpl_name,
+ )
+ );
+ $submit_value = array(
+ 'text_setactval' => 'abcd',
+ );
+ $result = $this->project->runMain($action_name, $submit_value);
+ $this->assertPattern('#<input type="text" name="text_noval" value="" />#', $result);
+ $this->assertPattern('#<input type="text" name="text_setactval" value="abcd" />#', $result);
+ $this->assertPattern('#<input value="1234" type="text" name="text_settplval" />#', $result);
+ }
+
+ function test_formhelper_Textarea()
+ {
+ $action_name = $tpl_name = 'textareatest';
+ $action_skel = ETHNA_TEST_SKELDIR . 'skel.action.formhelper.php';
+ $this->project->runCmd('add-action',
+ array(
+ '-s',
+ $action_skel,
+ $action_name,
+ )
+ );
+ $tpl_skel = ETHNA_TEST_SKELTPLDIR . 'skel.template.textarea.tpl';
+ $this->project->runCmd('add-template',
+ array(
+ '-s',
+ $tpl_skel,
+ $tpl_name,
+ )
+ );
+ $submit_value = array(
+ 'textarea_setactval' => 'input',
+ );
+ $result = $this->project->runMain($action_name, $submit_value);
+
+ $this->assertPattern('#<textarea name="textarea_noval"></textarea>#', $result);
+ $this->assertPattern('#<textarea name="textarea_setactval">input</textarea>#', $result);
+ $this->assertPattern('#<textarea value="foo" name="textarea_settplval">foo</textarea>#', $result);
+ }
+}
+
+?>
*
* @package Ethna
* @author halt feits <halt.feits@gmail.com>
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
*/
+require_once ETHNA_INSTALL_BASE . '/test/Ethna_MockProject.php';
+
/**
- * Ethna_ViewClassクラスのテストケース
+ * Ethna_ViewClass のテストケース
+ * 但しフォームヘルパまわりのテストを除く
+ * フォームヘルパのテストについては、Ethna_View_FormHelper_Test.php を参照
*
* @package Ethna
* @author halt feits <halt.feits@gmail.com>
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
* @access public
*/
class Ethna_ViewClass_Test extends Ethna_UnitTestBase
{
- /**
- * Ethna_ViewClass
- * @var Ethna_ViewClass
- * @access protected
- */
- var $viewclass;
+ var $view;
- /**
- * setUp
- *
- * make Ethna_ViewClass class
- *
- * @access public
- * @param void
- */
function setUp()
{
- $this->viewclass =& $this->ctl->getView();
- }
-
- /**
- * test_getFormInput_Html
- *
- * @access public
- * @param void
- */
- function test_getFormInput_Html()
- {
- $actual = '<input type="text" name="test" value="<&>" />';
-
- $test_attr = array(
- 'type' => 'text',
- 'name' => 'test',
- 'value' => '<&>',
- );
-
- $result = $this->viewclass->_getFormInput_Html('input', $test_attr);
-
- $this->assertEqual($result, $actual);
+ $this->view =& $this->ctl->getView();
}
- function test_getFormInput_Text()
+ function test_forward()
{
- $name = "test_text";
- $def = array(
- 'max' => 20,
- );
- $params = array();
-
- $test_form = array(
- 'test_text' => array(
- 'name' => 'TestTestText',
- 'form_type' => FORM_TYPE_TEXT,
- 'type' => VAR_TYPE_STRING,
- ),
- );
-
- $this->viewclass->af->setDef(null, $test_form);
-
- $result = $this->viewclass->_getFormInput_Text($name, $def, $params);
+ // todo add tests.
}
- function test_getFormInput_Textarea()
+ function test_header_integer()
{
- $name = "content";
- $params = array();
-
- $test_form = array(
- $name => array(
- 'name' => 'TestTestText',
- 'form_type' => FORM_TYPE_TEXTAREA,
- 'type' => VAR_TYPE_STRING,
- 'required' => true,
- ),
- );
-
- $this->viewclass->af->setDef(null, $test_form);
-
- $result = $this->viewclass->getFormInput($name, null, $params);
-
- $this->assertTrue(strpos($result, '</textarea>'), "can't find textarea endtag [{$result}]");
+ if (version_compare(PHP_VERSION, '5.0.0', '>')) {
+
+ $expected_values = array(
+ '100' => 'HTTP/1.1: 100 Continue',
+ '101' => 'HTTP/1.1: 101 Switching Protocols',
+ '200' => 'HTTP/1.1: 200 OK',
+ '201' => 'HTTP/1.1: 201 Created',
+ '202' => 'HTTP/1.1: 202 Accepted',
+ '203' => 'HTTP/1.1: 203 Non-Authoritative Information',
+ '204' => 'HTTP/1.1: 204 No Content',
+ '205' => 'HTTP/1.1: 205 Reset Content',
+ '206' => 'HTTP/1.1: 206 Partial Content',
+ '300' => 'HTTP/1.1: 300 Multiple Choices',
+ '301' => 'HTTP/1.1: 301 Moved Permanently',
+ '302' => 'HTTP/1.1: 302 Found',
+ '303' => 'HTTP/1.1: 303 See Other',
+ '304' => 'HTTP/1.1: 304 Not Modified',
+ '305' => 'HTTP/1.1: 305 Use Proxy',
+ '307' => 'HTTP/1.1: 307 Temporary Redirect',
+ '400' => 'HTTP/1.1: 400 Bad Request',
+ '401' => 'HTTP/1.1: Unauthorized',
+ '402' => 'HTTP/1.1: Payment Required',
+ '403' => 'HTTP/1.1: Forbidden',
+ '404' => 'HTTP/1.1: Not Found',
+ '405' => 'HTTP/1.1: Method Not Allowed',
+ '406' => 'HTTP/1.1: Not Acceptable',
+ '407' => 'HTTP/1.1: Proxy Authentication Required',
+ '408' => 'HTTP/1.1: Request Time-out',
+ '409' => 'HTTP/1.1: Conflict',
+ '410' => 'HTTP/1.1: Gone',
+ '411' => 'HTTP/1.1: Length Required',
+ '412' => 'HTTP/1.1: Precondition Failed',
+ '413' => 'HTTP/1.1: Request Entity Too Large',
+ '414' => 'HTTP/1.1: Request-URI Too Large',
+ '415' => 'HTTP/1.1: Unsupported Media Type',
+ '416' => 'HTTP/1.1: Requested range not satisfiable',
+ '417' => 'HTTP/1.1: Expectation Failed',
+ '500' => 'HTTP/1.1: Internal Server Error',
+ '501' => 'HTTP/1.1: Not Implemented',
+ '502' => 'HTTP/1.1: Bad Gateway',
+ '503' => 'HTTP/1.1: Service Unavailable',
+ '504' => 'HTTP/1.1: Gateway Time-out'
+ );
+ foreach ($expected_values as $status => $raw_header) {
+ @$this->view->header($status);
+ $headers_sent = headers_list();
+ $this->assertNotA(array_search($raw_header, $headers_sent), false);
+ }
+ }
}
- function test_getFormInput_Select()
+ function test_header_array()
{
- $name = "select";
- $params = array();
-
- $test_form = array(
- 'select' => array(
- 'name' => 'TestTestText',
- 'form_type' => FORM_TYPE_SELECT,
- 'type' => VAR_TYPE_STRING,
- 'option' => array('a', 'b', 'c'),
- ),
- );
-
- $this->viewclass->af->setDef($name, $test_form);
-
- $result = $this->viewclass->getFormInput($name, null, $params);
-
- $this->assertTrue(!empty($result), "selectbox make error");
+ $test_status = array('X-PHP-Framework' => 'Ethna 3000',);
+ @$this->view->header($test_status);
+ $headers_sent = headers_list();
+ $expected = 'X-PHP-Framework: Ethna 3000';
+ $this->assertNotA(array_search($expected, $headers_sent), false);
+
}
- function test_getFormInput_Checkbox()
+ function test_header_string()
{
- $this->assertTrue(defined('FORM_TYPE_CHECKBOX'), 'undefined FORM_TYPE_CHECKBOX');
-
- $name = "check";
- $params = array();
-
- $test_form = array(
- $name => array(
- 'name' => 'TestTestText',
- 'form_type' => FORM_TYPE_CHECKBOX,
- 'type' => array(VAR_TYPE_INT),
- 'option' => array('a', 'b', 'c'),
- ),
- );
-
- $this->viewclass->af->setDef($name, $test_form);
-
- $result = $this->viewclass->getFormInput($name, null, $params);
-
- $this->assertTrue(!empty($result), "checkbox make error");
+ // valid header
+ $expected = 'X-PHP-Framework: Ethna 3001';
+ @$this->view->header($expected);
+ $headers_sent = headers_list();
+ $this->assertNotA(array_search($expected, $headers_sent), false);
+
+ // invalid header
+ $invalid_header = 'invalid_header@foo';
+ @$this->view->header($invalid_header);
+ $headers_sent = headers_list();
+ $this->assertFalse(array_search($invalid_header, $headers_sent));
}
- function test_getFormInput_Submit()
+ function test_redirect()
{
- $this->assertTrue(defined('FORM_TYPE_SUBMIT'), 'undefined FORM_TYPE_SUBMIT');
-
- $name = "post";
- $params = array();
-
- $test_form = array(
- $name => array(
- 'name' => 'Preview',
- 'form_type' => FORM_TYPE_SUBMIT,
- 'type' => VAR_TYPE_STRING,
- ),
- );
-
- $this->viewclass->af->setDef(null, $test_form);
-
- $result = $this->viewclass->getFormInput($name, null, $params);
-
- $this->assertTrue(!empty($result), "submit make error");
- $this->assertFalse(strpos($result, 'default '), "invalid attribute");
+ @$this->view->redirect('http://ethna.jp');
+ $headers_sent = headers_list();
+ $expected = 'Location: http://ethna.jp';
+ $this->assertNotA(array_search($expected, $headers_sent), false);
}
- function testGetFormName()
+ function test_setLayout()
{
- $test_word = "TestTestTest";
-
- $test_form = array(
- 'test_text' => array(
- 'name' => 'TestTestTest',
- 'form_type' => FORM_TYPE_TEXT,
- 'type' => VAR_TYPE_STRING
- ),
- );
- $params = array();
-
- $this->viewclass->af->form = $test_form;
-
- $result = $this->viewclass->getFormName('test_text', null, $params);
- $this->assertEqual($result, $test_word);
+ $project = new Ethna_MockProject();
+ $project->create();
+ $ctl = $project->getController()->getBackend();
+ $view = new MockProject_ViewClass($ctl, 'dummy', 'dummy.tpl');
+
+ // invalid file
+ $return = $view->setLayout('fake.tpl');
+ $this->assertTrue(Ethna::isError($return));
+
+ // valid layout file test.
+ $return = $view->setLayout('index.tpl');
+ $this->assertFalse(Ethna::isError($return));
}
- function test_getFormInput_Button()
+ function test_getLayout()
{
- $name = 'btn';
- $def = array(
- 'form_type' => FORM_TYPE_BUTTON,
- );
- $params = array();
-
- // valueなし
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('btn', null, $params);
- $this->assertTrue(strpos($result, 'value') === false);
-
- // defaultは指定しても無意味
- $params['default'] = 'hoge';
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('btn', null, $params);
- $this->assertTrue(strpos($result, 'value') === false);
-
- // valueを指定
- $params['value'] = 'fuga';
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('btn', null, $params);
- $this->assertTrue(strpos($result, 'value="fuga"'));
+ $layout = $this->view->getLayout();
+ $this->assertEqual($layout, 'layout.tpl');
}
- function test_getFormInput_Checkbox2()
+ function test_templateExists()
{
- $name = 'chkbx';
- $def = array(
- 'form_type' => FORM_TYPE_CHECKBOX,
- 'type' => array(VAR_TYPE_STRING),
- 'option' => array(1=>1, 2=>2),
- 'default' => 2,
- );
- $params = array('separator' => "\n");
-
- $expected =<<<EOS
-<label for="chkbx_1"><input type="checkbox" name="chkbx[]" value="1" id="chkbx_1" />1</label>
-<label for="chkbx_2"><input type="checkbox" name="chkbx[]" value="2" id="chkbx_2" checked="checked" />2</label>
-EOS;
-
- // def の default 指定で int(2) に check
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('chkbx', null, $params);
- $this->assertEqual($result, $expected);
-
- // params の default 指定で int(2) に check
- $def['default'] = 1;
- $params['default'] = 2; // paramsが優先
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('chkbx', null, $params);
- $this->assertEqual($result, $expected);
-
- // params の default 指定で string(1) "2" に check
- $params['default'] = '2';
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('chkbx', null, $params);
- $this->assertEqual($result, $expected);
+ $project = new Ethna_MockProject();
+ $project->create();
+ $ctl = $project->getController()->getBackend();
+ $view = new MockProject_ViewClass($ctl, 'dummy', 'dummy.tpl');
+
+ $this->assertTrue($view->templateExists('index.tpl'));
+ $this->assertFalse($view->templateExists('dummy.tpl'));
+
+ $project->delete();
}
- function test_default_value()
+ function test_error()
{
- $name = 'testform';
- $def = array();
- $params = array();
-
- // defaultもvalueもないとき
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('testform', null, $params);
- $this->assertTrue(strpos($result, 'value=""'));
-
- // defaultがあるとき
- $params['default'] = 'hoge';
- unset($params['value']);
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('testform', null, $params);
- $this->assertTrue(strpos($result, 'value="hoge"'));
-
- // valueがあるとき
- unset($params['default']);
- $params['value'] = 'fuga';
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('testform', null, $params);
- $this->assertTrue(strpos($result, 'value="fuga"'));
-
- // default, value両方があるとき: valueが優先
- $params['default'] = 'hogefuga';
- $params['value'] = 'foobar';
- $this->viewclass->af->setDef($name, $def);
- $result = $this->viewclass->getFormInput('testform', null, $params);
- $this->assertTrue(strpos($result, 'value="foobar"'));
+ // todo: add test page output
}
}
+
?>
function test_Template()
{
- $skel = ETHNA_TEST_SKELDIR . 'skel.template.i18ntest.tpl';
+ $skel = ETHNA_TEST_SKELTPLDIR . 'skel.template.i18ntest.tpl';
$r = $this->proj->runCmd('add-template',
array(
'-s', $skel,
--- /dev/null
+<?php
+/**
+ * Ethna_View_404_Test.php
+ *
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ * @version $Id$
+ */
+
+require_once ETHNA_INSTALL_BASE . '/test/Ethna_MockProject.php';
+
+//{{{ Ethna_View_404_Test
+/**
+ * Test Case For Ethna_View_404
+ *
+ * @access public
+ */
+class Ethna_View_404_Test extends Ethna_UnitTestBase
+{
+ var $test_ctl;
+ var $test_backend;
+ var $view_404;
+
+ function setUp()
+ {
+ $this->test_ctl =& new Ethna_Controller();
+ $this->test_backend =& $this->test_ctl->getBackend();
+ $this->view_404 = new Ethna_View_404($this->test_backend, '404', NULL);
+ }
+
+ function tearDown()
+ {
+ unset($GLOBALS['_Ethna_controller']);
+ }
+
+ function test_redirect_404()
+ {
+ $project =& new Ethna_MockProject();
+ $project->create();
+
+ // add mock action for redirect
+ $action_skel = ETHNA_TEST_SKELDIR . 'skel.action.404.php';
+ $project->runCmd('add-action',
+ array(
+ '-s', $action_skel,
+ 'return404',
+ )
+ );
+
+ $out = $project->runMain('return404');
+ $this->assertPattern("/404 Not Found/", $out);
+ }
+}
--- /dev/null
+<?php
+/**
+ * Ethna_View_500_Test.php
+ *
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ * @version $Id$
+ */
+
+require_once ETHNA_INSTALL_BASE . '/test/Ethna_MockProject.php';
+
+//{{{ Ethna_View_500_Test
+/**
+ * Test Case For Ethna_View_500
+ *
+ * @access public
+ */
+class Ethna_View_500_Test extends Ethna_UnitTestBase
+{
+ var $test_ctl;
+ var $test_backend;
+ var $view_500;
+
+ function setUp()
+ {
+ $this->test_ctl =& new Ethna_Controller();
+ $this->test_backend =& $this->test_ctl->getBackend();
+ $this->view_500 = new Ethna_View_500($this->test_backend, '500', NULL);
+ }
+
+ function tearDown()
+ {
+ unset($GLOBALS['_Ethna_controller']);
+ }
+
+ function test_redirect_500()
+ {
+ $project =& new Ethna_MockProject();
+ $project->create();
+
+ // add mock action for redirect
+ $action_skel = ETHNA_TEST_SKELDIR . 'skel.action.500.php';
+ $project->runCmd('add-action',
+ array(
+ '-s', $action_skel,
+ 'return500',
+ )
+ );
+
+ $out = $project->runMain('return500');
+ $this->assertPattern("/500 Internal Server Error/", $out);
+ }
+}
--- /dev/null
+<?php
+/**
+ * Ethna_View_Json_Test.php
+ *
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ * @version $Id$
+ */
+
+//{{{ Ethna_View_Json_Test
+/**
+ * Test Case For Ethna_View_Json
+ *
+ * @access public
+ */
+class Ethna_View_Json_Test extends Ethna_UnitTestBase
+{
+ var $test_ctl;
+ var $test_backend;
+ var $view_json;
+
+ function setUp()
+ {
+ $this->test_ctl =& new Ethna_Controller();
+ $this->test_backend =& $this->test_ctl->getBackend();
+ $this->view_json = new Ethna_View_Json($this->test_backend, 'json', NULL);
+ }
+
+ function tearDown()
+ {
+ unset($GLOBALS['_Ethna_controller']);
+ }
+
+ function test_preforward_utf8()
+ {
+ $param = array("a", "あいうえ");
+
+ // stop header output for testing.
+ ob_start();
+ // stop header output error for testing.
+ @$this->view_json->preforward($param);
+ $result = ob_get_contents();
+ ob_end_clean();
+
+ $this->assertEqual($result, '["a","\u3042\u3044\u3046\u3048"]');
+ }
+
+ function test_preforward_non_utf8()
+ {
+ $this->test_ctl->setClientEncoding('EUC-JP');
+
+ $param = array("a", "あいうえ");
+ mb_convert_variables('EUC-JP', 'UTF-8', $param);
+
+ ob_start();
+ // stop header output for testing.
+ @$this->view_json->preforward($param);
+ $result = ob_get_contents();
+ ob_end_clean();
+
+ $this->assertEqual($result, '["a","\u3042\u3044\u3046\u3048"]');
+
+ $this->test_ctl->setClientEncoding('UTF-8');
+ }
+
+ function test_json_action()
+ {
+ $project =& new Ethna_MockProject();
+ $project->create();
+
+ // add mock action for redirect
+ $action_skel = ETHNA_TEST_SKELDIR . 'skel.action.json.php';
+ $project->runCmd('add-action',
+ array(
+ '-s', $action_skel,
+ 'json',
+ )
+ );
+
+ $out = $project->runMain('json');
+ $this->assertEqual('["a","b"]', $out);
+ }
+}
--- /dev/null
+<?php
+/**
+ * Ethna_View_Redirect_Test.php
+ *
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ * @version $Id$
+ */
+
+require_once ETHNA_INSTALL_BASE . '/test/Ethna_MockProject.php';
+
+//{{{ Ethna_View_Redirect_Test
+/**
+ * Test Case For Ethna_View_Redirect
+ *
+ * @access public
+ */
+class Ethna_View_Redirect_Test extends Ethna_UnitTestBase
+{
+ var $test_ctl;
+ var $test_backend;
+ var $view_redirect;
+
+ function setUp()
+ {
+ $this->test_ctl =& new Ethna_Controller();
+ $this->test_backend =& $this->test_ctl->getBackend();
+ $this->view_redirect = new Ethna_View_Redirect($this->test_backend, 'redirect', NULL);
+ }
+
+ function tearDown()
+ {
+ unset($GLOBALS['_Ethna_controller']);
+ }
+
+ function test_preforward()
+ {
+ if (version_compare(PHP_VERSION, '5.0.0', '>')) {
+ // stop header output error for testing.
+ @$this->view_redirect->preforward('http://www.aoimiyazaki.jp/');
+
+ $headers_sent = headers_list();
+ $this->assertNotA(
+ array_search('Location: http://aoimiyazaki.jp', $headers_sent),
+ false
+ );
+ }
+ }
+
+ function test_redirect_action()
+ {
+ $project =& new Ethna_MockProject();
+ $project->create();
+
+ // add mock action for redirect
+ $action_skel = ETHNA_TEST_SKELDIR . 'skel.action.redirect.php';
+ $project->runCmd('add-action',
+ array(
+ '-s', $action_skel,
+ 'redirect',
+ )
+ );
+
+ $out = $project->runMain('redirect');
+ $this->assertEqual("", $out);
+
+ if (version_compare(PHP_VERSION, '5.0.0', '>')) {
+ $headers_sent = headers_list();
+ $this->assertNotA(
+ array_search('Location: http://www.ethnatest.example.com', $headers_sent),
+ false
+ );
+ }
+ }
+}
--- /dev/null
+<?php
+/**
+ * {$action_path}
+ *
+ * @author {$author}
+ * @package {$project_id}
+ * @version $Id: skel.action.php 568 2008-06-07 22:55:10Z mumumu-org $
+ */
+
+/**
+ * {$action_name} Form implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_form} extends {$project_id}_ActionForm
+{
+ /**
+ * @access private
+ * @var array form definition.
+ */
+ var $form = array();
+}
+
+/**
+ * {$action_name} action implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_class} extends {$project_id}_ActionClass
+{
+ /**
+ * preprocess of {$action_name} Action.
+ *
+ * @access public
+ * @return string forward name(null: success.
+ * false: in case you want to exit.)
+ */
+ function prepare()
+ {
+ return null;
+ }
+
+ /**
+ * {$action_name} action implementation.
+ *
+ * @access public
+ * @return string forward name.
+ */
+ function perform()
+ {
+ return '404';
+ }
+}
+
+?>
--- /dev/null
+<?php
+/**
+ * {$action_path}
+ *
+ * @author {$author}
+ * @package {$project_id}
+ * @version $Id: skel.action.php 568 2008-06-07 22:55:10Z mumumu-org $
+ */
+
+/**
+ * {$action_name} Form implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_form} extends {$project_id}_ActionForm
+{
+ /**
+ * @access private
+ * @var array form definition.
+ */
+ var $form = array();
+}
+
+/**
+ * {$action_name} action implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_class} extends {$project_id}_ActionClass
+{
+ /**
+ * preprocess of {$action_name} Action.
+ *
+ * @access public
+ * @return string forward name(null: success.
+ * false: in case you want to exit.)
+ */
+ function prepare()
+ {
+ return null;
+ }
+
+ /**
+ * {$action_name} action implementation.
+ *
+ * @access public
+ * @return string forward name.
+ */
+ function perform()
+ {
+ return '500';
+ }
+}
+
+?>
--- /dev/null
+<?php
+/**
+ * {$action_path}
+ *
+ * @author {$author}
+ * @package {$project_id}
+ * @version $Id: skel.action.php 568 2008-06-07 22:55:10Z mumumu-org $
+ */
+
+/**
+ * {$action_name} Form implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_form} extends {$project_id}_ActionForm
+{
+ /**
+ * @access private
+ * @var array form definition.
+ */
+ var $form = array(
+
+ /** FORM_TYPE_TEXT のテスト */
+
+ 'text_noval' => array(
+ 'type' => VAR_TYPE_INT,
+ 'name' => 'textarea_noval',
+ 'form_type' => FORM_TYPE_TEXT,
+ ),
+ 'text_setactval' => array(
+ 'type' => VAR_TYPE_STRING,
+ 'name' => 'text_setval',
+ 'form_type' => FORM_TYPE_TEXT,
+ 'max' => 10, // maxlength は無視されなければならない
+ ),
+ 'text_settplval' => array(
+ 'type' => VAR_TYPE_STRING,
+ 'name' => 'text_settplval',
+ 'form_type' => FORM_TYPE_TEXT,
+ 'max' => 10, // maxlength は無視されなければならない
+ ),
+
+ /** FORM_TYPE_TEXTAREA のテスト */
+
+ // テンプレートでvalue属性を設定しない場合
+ 'textarea_noval' => array(
+ 'type' => VAR_TYPE_INT,
+ 'name' => 'textarea_noval',
+ 'form_type' => FORM_TYPE_TEXTAREA,
+ ),
+ // アクションフォームに値が設定されており、
+ // テンプレートでvalue属性を設定しない場合
+ 'textarea_setactval' => array(
+ 'type' => VAR_TYPE_INT,
+ 'name' => 'textarea_setactval',
+ 'form_type' => FORM_TYPE_TEXTAREA,
+ ),
+ // テンプレートでvalue属性を設定した場合
+ 'textarea_settplval' => array(
+ 'type' => VAR_TYPE_INT,
+ 'name' => 'textarea_settplval',
+ 'form_type' => FORM_TYPE_TEXTAREA,
+ ),
+ );
+}
+
+/**
+ * {$action_name} action implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_class} extends {$project_id}_ActionClass
+{
+ /**
+ * preprocess of {$action_name} Action.
+ *
+ * @access public
+ * @return string forward name(null: success.
+ * false: in case you want to exit.)
+ */
+ function prepare()
+ {
+ return null;
+ }
+
+ /**
+ * {$action_name} action implementation.
+ *
+ * @access public
+ * @return string forward name.
+ */
+ function perform()
+ {
+ return '{$action_name}';
+ }
+}
+
+?>
--- /dev/null
+<?php
+/**
+ * {$action_path}
+ *
+ * @author {$author}
+ * @package {$project_id}
+ * @version $Id: skel.action.php 568 2008-06-07 22:55:10Z mumumu-org $
+ */
+
+/**
+ * {$action_name} Form implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_form} extends {$project_id}_ActionForm
+{
+ /**
+ * @access private
+ * @var array form definition.
+ */
+ var $form = array();
+}
+
+/**
+ * {$action_name} action implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_class} extends {$project_id}_ActionClass
+{
+ /**
+ * preprocess of {$action_name} Action.
+ *
+ * @access public
+ * @return string forward name(null: success.
+ * false: in case you want to exit.)
+ */
+ function prepare()
+ {
+ return null;
+ }
+
+ /**
+ * {$action_name} action implementation.
+ *
+ * @access public
+ * @return string forward name.
+ */
+ function perform()
+ {
+ return array('json', array('a', 'b'));
+ }
+}
+
+?>
--- /dev/null
+<?php
+/**
+ * {$action_path}
+ *
+ * @author {$author}
+ * @package {$project_id}
+ * @version $Id: skel.action.php 568 2008-06-07 22:55:10Z mumumu-org $
+ */
+
+/**
+ * {$action_name} Form implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_form} extends {$project_id}_ActionForm
+{
+ /**
+ * @access private
+ * @var array form definition.
+ */
+ var $form = array();
+}
+
+/**
+ * {$action_name} action implementation.
+ *
+ * @author {$author}
+ * @access public
+ * @package {$project_id}
+ */
+class {$action_class} extends {$project_id}_ActionClass
+{
+ /**
+ * preprocess of {$action_name} Action.
+ *
+ * @access public
+ * @return string forward name(null: success.
+ * false: in case you want to exit.)
+ */
+ function prepare()
+ {
+ return null;
+ }
+
+ /**
+ * {$action_name} action implementation.
+ *
+ * @access public
+ * @return string forward name.
+ */
+ function perform()
+ {
+ return array('redirect', 'http://www.ethnatest.example.com');
+ }
+}
+
+?>
--- /dev/null
+{form_input name="text_noval"}
+{form_input name="text_setactval"}
+{form_input name="text_settplval" value="1234"}
--- /dev/null
+{form ethna_action="textarea_test"}
+ {form_input name="textarea_noval"}
+ {form_input name="textarea_setactval"}
+ {form_input name="textarea_settplval" value="foo"}
+{/form}