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:  * Test Suite Shell
  5:  *
  6:  * This Shell allows the running of test suites via the cake command line
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  *  Licensed under The Open Group Test Suite 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          https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
 18:  * @package       cake
 19:  * @subpackage    cake.cake.console.libs
 20:  * @since         CakePHP(tm) v 1.2.0.4433
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
 25:  */
 26: class TestSuiteShell extends Shell {
 27: /**
 28:  * The test category, "app", "core" or the name of a plugin
 29:  *
 30:  * @var string
 31:  * @access public
 32:  */
 33:     var $category = '';
 34: /**
 35:  * "group", "case" or "all"
 36:  *
 37:  * @var string
 38:  * @access public
 39:  */
 40:     var $type = '';
 41: /**
 42:  * Path to the test case/group file
 43:  *
 44:  * @var string
 45:  * @access public
 46:  */
 47:     var $file = '';
 48: /**
 49:  * Storage for plugins that have tests
 50:  *
 51:  * @var string
 52:  * @access public
 53:  */
 54:     var $plugins = array();
 55: /**
 56:  * Convenience variable to avoid duplicated code
 57:  *
 58:  * @var string
 59:  * @access public
 60:  */
 61:     var $isPluginTest = false;
 62: /**
 63:  * Stores if the user wishes to get a code coverage analysis report
 64:  *
 65:  * @var string
 66:  * @access public
 67:  */
 68:     var $doCoverage = false;
 69: /**
 70:  * The headline for the test output
 71:  *
 72:  * @var string
 73:  * @access public
 74:  */
 75:     var $headline = 'CakePHP Test Shell';
 76: /**
 77:  * Initialization method installs Simpletest and loads all plugins
 78:  *
 79:  * @return void
 80:  * @access public
 81:  */
 82:     function initialize() {
 83:         $corePath = Configure::corePaths('cake');
 84:         if (isset($corePath[0])) {
 85:             define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
 86:         } else {
 87:             define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
 88:         }
 89: 
 90:         $this->__installSimpleTest();
 91: 
 92:         require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
 93:         require_once CAKE . 'tests' . DS . 'lib' . DS . 'cli_reporter.php';
 94: 
 95:         $plugins = Configure::listObjects('plugin');
 96:         foreach ($plugins as $p) {
 97:             $this->plugins[] = Inflector::underscore($p);
 98:         }
 99:     }
100: /**
101:  * Main entry point to this shell
102:  *
103:  * @return void
104:  * @access public
105:  */
106:     function main() {
107:         $this->out($this->headline);
108:         $this->hr();
109: 
110:         if (count($this->args) > 0) {
111:             $this->category = $this->args[0];
112: 
113:             if (!in_array($this->category, array('app', 'core'))) {
114:                 $this->isPluginTest = true;
115:             }
116: 
117:             if (isset($this->args[1])) {
118:                 $this->type = $this->args[1];
119:             }
120: 
121:             if (isset($this->args[2])) {
122:                 if ($this->args[2] == 'cov') {
123:                     $this->doCoverage = true;
124:                 } else {
125:                     $this->file = Inflector::underscore($this->args[2]);
126:                 }
127:             }
128: 
129:             if (isset($this->args[3]) && $this->args[3] == 'cov') {
130:                 $this->doCoverage = true;
131:             }
132:         } else {
133:             $this->err('Sorry, you did not pass any arguments!');
134:         }
135: 
136:         if ($this->__canRun()) {
137:             $this->out('Running '.$this->category.' '.$this->type.' '.$this->file);
138: 
139:             $exitCode = 0;
140:             if (!$this->__run()) {
141:                 $exitCode = 1;
142:             }
143:             exit($exitCode);
144:         } else {
145:             $this->err('Sorry, the tests could not be found.');
146:             exit(1);
147:         }
148:     }
149: /**
150:  * Help screen
151:  *
152:  * @return void
153:  * @access public
154:  */
155:     function help() {
156:         $this->out('Usage: ');
157:         $this->out("\tcake testsuite category test_type file");
158:         $this->out("\t\t- category - \"app\", \"core\" or name of a plugin");
159:         $this->out("\t\t- test_type - \"case\", \"group\" or \"all\"");
160:         $this->out("\t\t- test_file - file name with folder prefix and without the (test|group).php suffix");
161:         $this->out('');
162:         $this->out('Examples: ');
163:         $this->out("\t\tcake testsuite app all");
164:         $this->out("\t\tcake testsuite core all");
165:         $this->out('');
166:         $this->out("\t\tcake testsuite app case behaviors/debuggable");
167:         $this->out("\t\tcake testsuite app case models/my_model");
168:         $this->out("\t\tcake testsuite app case controllers/my_controller");
169:         $this->out('');
170:         $this->out("\t\tcake testsuite core case file");
171:         $this->out("\t\tcake testsuite core case router");
172:         $this->out("\t\tcake testsuite core case set");
173:         $this->out('');
174:         $this->out("\t\tcake testsuite app group mygroup");
175:         $this->out("\t\tcake testsuite core group acl");
176:         $this->out("\t\tcake testsuite core group socket");
177:         $this->out('');
178:         $this->out("\t\tcake testsuite bugs case models/bug");
179:         $this->out("\t\t  // for the plugin 'bugs' and its test case 'models/bug'");
180:         $this->out("\t\tcake testsuite bugs group bug");
181:         $this->out("\t\t  // for the plugin bugs and its test group 'bug'");
182:         $this->out('');
183:         $this->out('Code Coverage Analysis: ');
184:         $this->out("\n\nAppend 'cov' to any of the above in order to enable code coverage analysis");
185:     }
186: /**
187:  * Checks if the arguments supplied point to a valid test file and thus the shell can be run.
188:  *
189:  * @return bool true if it's a valid test file, false otherwise
190:  * @access private
191:  */
192:     function __canRun() {
193:         $isNeitherAppNorCore = !in_array($this->category, array('app', 'core'));
194:         $isPlugin = in_array(Inflector::underscore($this->category), $this->plugins);
195: 
196:         if ($isNeitherAppNorCore && !$isPlugin) {
197:             $this->err($this->category.' is an invalid test category (either "app", "core" or name of a plugin)');
198:             return false;
199:         }
200: 
201:         $folder = $this->__findFolderByCategory($this->category);
202:         if (!file_exists($folder)) {
203:             $this->err($folder . ' not found');
204:             return false;
205:         }
206: 
207:         if (!in_array($this->type, array('all', 'group', 'case'))) {
208:             $this->err($this->type.' is invalid. Should be case, group or all');
209:             return false;
210:         }
211: 
212:         switch ($this->type) {
213:             case 'all':
214:                 return true;
215:                 break;
216:             case 'group':
217:                 if (file_exists($folder.DS.'groups'.DS.$this->file.'.group.php')) {
218:                     return true;
219:                 }
220:                 break;
221:             case 'case':
222:                 if ($this->category == 'app' && file_exists($folder.DS.'cases'.DS.$this->file.'.test.php')) {
223:                     return true;
224:                 }
225: 
226:                 if ($this->category == 'core' && file_exists($folder.DS.'cases'.DS.'libs'.DS.$this->file.'.test.php')) {
227:                     return true;
228:                 }
229: 
230:                 if ($isPlugin && file_exists($folder.DS.'cases'.DS.$this->file.'.test.php')) {
231:                     return true;
232:                 }
233:                 break;
234:         }
235: 
236:         $this->err($this->category.' '.$this->type.' '.$this->file.' is an invalid test identifier');
237:         return false;
238:     }
239: /**
240:  * Executes the tests depending on our settings
241:  *
242:  * @return void
243:  * @access private
244:  */
245:     function __run() {
246:         $reporter = new CLIReporter();
247:         $this->__setGetVars();
248: 
249:         if ($this->type == 'all') {
250:             return TestManager::runAllTests($reporter);
251:         }
252: 
253:         if ($this->doCoverage) {
254:             if (!extension_loaded('xdebug')) {
255:                 $this->out('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install');
256:                 exit(0);
257:             }
258:         }
259: 
260:         if ($this->type == 'group') {
261:             $ucFirstGroup = ucfirst($this->file);
262: 
263:             $path = CORE_TEST_GROUPS;
264:             if ($this->category == 'app') {
265:                 $path = APP_TEST_GROUPS;
266:             } elseif ($this->isPluginTest) {
267:                 $path = APP.'plugins'.DS.$this->category.DS.'tests'.DS.'groups';
268:             }
269: 
270:             if ($this->doCoverage) {
271:                 require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
272:                 CodeCoverageManager::start($ucFirstGroup, $reporter);
273:             }
274:             $result = TestManager::runGroupTest($ucFirstGroup, $reporter);
275:             if ($this->doCoverage) {
276:                 CodeCoverageManager::report();
277:             }
278:             return $result;
279:         }
280: 
281:         $case = 'libs'.DS.$this->file.'.test.php';
282:         if ($this->category == 'app') {
283:             $case = $this->file.'.test.php';
284:         } elseif ($this->isPluginTest) {
285:             $case = $this->file.'.test.php';
286:         }
287: 
288:         if ($this->doCoverage) {
289:             require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
290:             CodeCoverageManager::start($case, $reporter);
291:         }
292: 
293:         $result = TestManager::runTestCase($case, $reporter);
294:         if ($this->doCoverage) {
295:             CodeCoverageManager::report();
296:         }
297: 
298:         return $result;
299:     }
300: /**
301:  * Finds the correct folder to look for tests for based on the input category
302:  *
303:  * @return string the folder path
304:  * @access private
305:  */
306:     function __findFolderByCategory($category) {
307:         $folder = '';
308:         $paths = array(
309:             'core' => CAKE,
310:             'app'  => APP
311:         );
312: 
313:         if (array_key_exists($category, $paths)) {
314:             $folder = $paths[$category] . 'tests';
315:         } else {
316:             $scoredCategory = Inflector::underscore($category);
317:             $folder = APP . 'plugins' . DS . $scoredCategory . DS;
318:             $pluginPaths = Configure::read('pluginPaths');
319:             foreach ($pluginPaths as $path) {
320:                 if (file_exists($path . $scoredCategory . DS . 'tests')) {
321:                     $folder = $path . $scoredCategory . DS . 'tests';
322:                     break;
323:                 }
324:             }
325:         }
326:         return $folder;
327:     }
328: /**
329:  * Sets some get vars needed for TestManager
330:  *
331:  * @return void
332:  * @access private
333:  */
334:     function __setGetVars() {
335:         if (in_array($this->category, $this->plugins)) {
336:             $_GET['plugin'] = $this->category;
337:         } elseif (in_array(Inflector::Humanize($this->category), $this->plugins)) {
338:             $_GET['plugin'] = Inflector::Humanize($this->category);
339:         } elseif ($this->category == 'app') {
340:             $_GET['app'] = true;
341:         }
342:         if ($this->type == 'group') {
343:             $_GET['group'] = true;
344:         }
345:     }
346: /**
347:  * tries to install simpletest and exits gracefully if it is not there
348:  *
349:  * @return void
350:  * @access private
351:  */
352:     function __installSimpleTest() {
353:         if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
354:             $this->err('Sorry, Simpletest could not be found. Download it from http://simpletest.org and install it to your vendors directory.');
355:             exit;
356:         }
357:     }
358: }
359: ?>
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