CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * The TestTask handles creating and updating test files.
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.console.libs.tasks
 20:  * @since         CakePHP(tm) v 1.2
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * Task class for creating and updating test files.
 28:  *
 29:  * @package       cake
 30:  * @subpackage    cake.cake.console.libs.tasks
 31:  */
 32: class TestTask extends Shell {
 33: /**
 34:  * Name of plugin
 35:  *
 36:  * @var string
 37:  * @access public
 38:  */
 39:     var $plugin = null;
 40: /**
 41:  * path to TESTS directory
 42:  *
 43:  * @var string
 44:  * @access public
 45:  */
 46:     var $path = TESTS;
 47: /**
 48:  * Execution method always used for tasks
 49:  *
 50:  * @access public
 51:  */
 52:     function execute() {
 53:         if (empty($this->args)) {
 54:             $this->__interactive();
 55:         }
 56: 
 57:         if (count($this->args) == 1) {
 58:             $this->__interactive($this->args[0]);
 59:         }
 60: 
 61:         if (count($this->args) > 1) {
 62:             $class = Inflector::underscore($this->args[0]);
 63:             if ($this->bake($class, $this->args[1])) {
 64:                 $this->out('done');
 65:             }
 66:         }
 67:     }
 68: /**
 69:  * Handles interactive baking
 70:  *
 71:  * @access private
 72:  */
 73:     function __interactive($class = null) {
 74:         $this->hr();
 75:         $this->out(sprintf("Bake Tests\nPath: %s", $this->path));
 76:         $this->hr();
 77: 
 78:         $key = null;
 79:         $options = array('Behavior', 'Helper', 'Component', 'Model', 'Controller');
 80: 
 81:         if ($class !== null) {
 82:             $class = Inflector::camelize($class);
 83:             if (in_array($class, $options)) {
 84:                 $key = array_search($class);
 85:             }
 86:         }
 87: 
 88:         while ($class == null) {
 89:             $cases = array();
 90:             $this->hr();
 91:             $this->out("Select a class:");
 92:             $this->hr();
 93: 
 94:             $keys = array();
 95:             foreach ($options as $key => $option) {
 96:                 $this->out(++$key . '. ' . $option);
 97:                 $keys[] = $key;
 98:             }
 99:             $keys[] = 'q';
100: 
101:             $key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
102: 
103:             if ($key != 'q') {
104:                 if (isset($options[--$key])) {
105:                     $class = $options[$key];
106:                 }
107: 
108:                 if ($class) {
109:                     $name = $this->in(__("Enter the name for the test or (q)uit", true), null, 'q');
110:                     if ($name !== 'q') {
111:                         $case = null;
112:                         while ($case !== 'q') {
113:                             $case = $this->in(__("Enter a test case or (q)uit", true), null, 'q');
114:                             if ($case !== 'q') {
115:                                 $cases[] = $case;
116:                             }
117:                         }
118:                         if ($this->bake($class, $name, $cases)) {
119:                             $this->out(__("Test baked\n", true));
120:                             $type = null;
121:                         }
122:                         $class = null;
123:                     }
124:                 }
125:             } else {
126:                 $this->_stop();
127:             }
128:         }
129:     }
130: /**
131:  * Writes File
132:  *
133:  * @access public
134:  */
135:     function bake($class, $name = null, $cases = array()) {
136:         if (!$name) {
137:             return false;
138:         }
139: 
140:         if (!is_array($cases)) {
141:             $cases = array($cases);
142:         }
143: 
144:         if (strpos($this->path, $class) === false) {
145:             $this->filePath = $this->path . 'cases' . DS . Inflector::tableize($class) . DS;
146:         }
147: 
148:         $class = Inflector::classify($class);
149:         $name = Inflector::classify($name);
150: 
151:         $import = $name;
152:         if (isset($this->plugin)) {
153:             $import = $this->plugin . '.' . $name;
154:         }
155:         $extras = $this->__extras($class);
156:         $out = "App::import('$class', '$import');\n";
157:         if ($class == 'Model') {
158:             $class = null;
159:         }
160:         $out .= "class Test{$name} extends {$name}{$class} {\n";
161:         $out .= "{$extras}";
162:         $out .= "}\n\n";
163:         $out .= "class {$name}{$class}Test extends CakeTestCase {\n";
164:         $out .= "\n\tfunction startTest() {";
165:         $out .= "\n\t\t\$this->{$name} = new Test{$name}();";
166:         $out .= "\n\t}\n";
167:         $out .= "\n\tfunction test{$name}Instance() {\n";
168:         $out .= "\t\t\$this->assertTrue(is_a(\$this->{$name}, '{$name}{$class}'));\n\t}\n";
169:         foreach ($cases as $case) {
170:             $case = Inflector::classify($case);
171:             $out .= "\n\tfunction test{$case}() {\n\n\t}\n";
172:         }
173:         $out .= "}\n";
174: 
175:         $this->out("Baking unit test for $name...");
176:         $this->out($out);
177:         $ok = $this->in(__('Is this correct?', true), array('y', 'n'), 'y');
178:         if ($ok == 'n') {
179:             return false;
180:         }
181: 
182:         $header = '$Id';
183:         $content = "<?php \n/* SVN FILE: $header$ */\n/* " . $name . " Test cases generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n{$out}?>";
184:         return $this->createFile($this->filePath . Inflector::underscore($name) . '.test.php', $content);
185:     }
186: /**
187:  * Handles the extra stuff needed
188:  *
189:  * @access private
190:  */
191:     function __extras($class) {
192:         $extras = null;
193:         switch ($class) {
194:             case 'Model':
195:                 $extras = "\n\tvar \$cacheSources = false;";
196:                 $extras .= "\n\tvar \$useDbConfig = 'test_suite';\n";
197:             break;
198:         }
199:         return $extras;
200:     }
201: }
202: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs