Source for file ActionTest.php

Documentation is available at ActionTest.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  ActionTest.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: 4ffda108e48919fa20ff446d4d1b25bd2bc6599a $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Generator_ActionTest
  13. /**
  14.  *  スケルトン生成クラス
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**
  22.      *  アクション用テストのスケルトンを生成する
  23.      *  (現在のところ GATEWAY_WWW のみ対応)
  24.      *
  25.      *  @access public
  26.      *  @param  string  $action_name    アクション名
  27.      *  @param  string  $skelton        スケルトンファイル名
  28.      *  @param  int     $gateway        ゲートウェイ
  29.      *  @return true|Ethna_Error       true:成功 Ethna_Error:失敗
  30.      */
  31.     function generate($action_name$skelton null$gateway GATEWAY_WWW)
  32.     {
  33.         $action_dir $this->ctl->getActiondir($gateway);
  34.         $action_class $this->ctl->getDefaultActionClass($action_name$gateway);
  35.         $action_form $this->ctl->getDefaultFormClass($action_name$gateway);
  36.         $action_path $this->ctl->getDefaultActionPath($action_name 'Test');
  37.  
  38.         // entity
  39.         $entity $action_dir $action_path;
  40.         Ethna_Util::mkdir(dirname($entity)0755);
  41.  
  42.         // skelton
  43.         if ($skelton === null{
  44.             $skelton 'skel.action_test.php';
  45.         }
  46.  
  47.         // macro
  48.         $macro array();
  49.         $macro['project_id'$this->ctl->getAppId();
  50.         $macro['action_name'$action_name;
  51.         $macro['action_class'$action_class;
  52.         $macro['action_form'$action_form;
  53.         $macro['action_path'$action_path;
  54.  
  55.         // user macro
  56.         $user_macro $this->_getUserMacro();
  57.         $macro array_merge($macro$user_macro);
  58.  
  59.         // original action script existence check.
  60.         $original_action_path $this->ctl->getDefaultActionPath($action_name);
  61.         $original_action_entity $action_dir $original_action_path;
  62.         if (!file_exists($original_action_entity)) {
  63.             printf("\n");
  64.             printf("[!!!!warning!!!!] original action script was not found.\n");
  65.             printf("[!!!!warning!!!!] You must generate it by the following command :\n");
  66.             printf("[!!!!warning!!!!] ethna add-action %s\n\n"$action_name);
  67.         
  68.  
  69.         // generate
  70.         if (file_exists($entity)) {
  71.             printf("file [%s] already exists -> skip\n"$entity);
  72.         else if ($this->_generateFile($skelton$entity$macro== false{
  73.             printf("[warning] file creation failed [%s]\n"$entity);
  74.         else {
  75.             printf("action test(s) successfully created [%s]\n"$entity);
  76.         }
  77.  
  78.         $true true;
  79.         return $true;
  80.     }
  81. }
  82. // }}}

Documentation generated on Fri, 11 Nov 2011 03:57:26 +0900 by phpDocumentor 1.4.3