Skip to content
Browse files

Auth

  • Loading branch information...
1 parent 1b1bf13 commit 5e043673a66633d736634ecf414385159ae91962 @bartcc bartcc committed
Showing with 16 additions and 11,976 deletions.
  1. +16 −4 app/app_controller.php
  2. +0 −13 app/app_model.php
  3. +0 −1 app/cake/libs/controller/components/auth.php
  4. +0 −828 app/cake/tests/cases/basics.test.php
  5. +0 −939 app/cake/tests/cases/console/cake.test.php
  6. +0 −346 app/cake/tests/cases/console/libs/acl.test.php
  7. +0 −116 app/cake/tests/cases/console/libs/api.test.php
  8. +0 −130 app/cake/tests/cases/console/libs/bake.test.php
  9. +0 −503 app/cake/tests/cases/console/libs/schema.test.php
  10. +0 −501 app/cake/tests/cases/console/libs/shell.test.php
  11. +0 −633 app/cake/tests/cases/console/libs/tasks/controller.test.php
  12. +0 −155 app/cake/tests/cases/console/libs/tasks/db_config.test.php
  13. +0 −187 app/cake/tests/cases/console/libs/tasks/extract.test.php
  14. +0 −373 app/cake/tests/cases/console/libs/tasks/fixture.test.php
  15. +0 −909 app/cake/tests/cases/console/libs/tasks/model.test.php
  16. +0 −263 app/cake/tests/cases/console/libs/tasks/plugin.test.php
  17. +0 −301 app/cake/tests/cases/console/libs/tasks/project.test.php
  18. +0 −189 app/cake/tests/cases/console/libs/tasks/template.test.php
  19. +0 −646 app/cake/tests/cases/console/libs/tasks/test.test.php
  20. +0 −677 app/cake/tests/cases/console/libs/tasks/view.test.php
  21. +0 −2,496 app/cake/tests/cases/dispatcher.test.php
  22. +0 −372 app/cake/tests/cases/libs/cache.test.php
  23. +0 −196 app/cake/tests/cases/libs/cache/apc.test.php
  24. +0 −404 app/cake/tests/cases/libs/cache/file.test.php
  25. +0 −389 app/cake/tests/cases/libs/cache/memcache.test.php
  26. +0 −222 app/cake/tests/cases/libs/cache/xcache.test.php
  27. +0 −183 app/cake/tests/cases/libs/cake_log.test.php
Sorry, we could not display the entire diff because too many files (490) changed.
View
20 app/app_controller.php
@@ -1,4 +1,5 @@
<?php
+
/**
* Application level Controller
*
@@ -31,8 +32,19 @@
* @subpackage cake.app
*/
class AppController extends Controller {
-
- function beforeFilter() {
- $this->autoRender = FALSE;
- }
+
+ var $helpers = array('Session', 'Html', 'Js');
+ var $components = array('RequestHandler', 'Session', 'Auth', 'Cookie');
+
+ function beforeFilter() {
+ $this->autoRender = FALSE;
+ $this->Auth->autoRedirect = FALSE;
+
+ }
+
+ function beforeRender() {
+ if ($this->RequestHandler->isAjax())
+ $this->layout = 'ajax';
+ }
+
}
View
13 app/app_model.php
@@ -32,17 +32,4 @@
*/
class AppModel extends Model {
- function afterFind($results) {
-
- foreach ($results as $key => $val) {
- if(isset($val[$this->alias]['done'])) {
- $val[$this->alias]['done'] = (BOOLEAN) $val[$this->alias]['done'];
- }
- $results[$key] = $val[$this->alias];
- }
-
- return $results;
- }
-
-
}
View
1 app/cake/libs/controller/components/auth.php
@@ -684,7 +684,6 @@ function login($data = null) {
if (empty($data)) {
$data = $this->data;
}
-
if ($user = $this->identify($data)) {
$this->Session->write($this->sessionKey, $user);
$this->_loggedIn = true;
View
828 app/cake/tests/cases/basics.test.php
@@ -1,828 +0,0 @@
-<?php
-/**
- * BasicsTest file
- *
- * PHP versions 4 and 5
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
- * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The Open Group Test Suite License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
- * @package cake
- * @subpackage cake.tests.cases
- * @since CakePHP(tm) v 1.2.0.4206
- * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
- */
-require_once CAKE . 'basics.php';
-App::import('Core', 'Folder');
-
-/**
- * BasicsTest class
- *
- * @package cake
- * @subpackage cake.tests.cases
- */
-class BasicsTest extends CakeTestCase {
-
-/**
- * setUp method
- *
- * @return void
- * @access public
- */
- function setUp() {
- App::build(array(
- 'locales' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS)
- ));
- $this->_language = Configure::read('Config.language');
- }
-
-/**
- * tearDown method
- *
- * @return void
- * @access public
- */
- function tearDown() {
- App::build();
- Configure::write('Config.language', $this->_language);
- }
-
-/**
- * test the array_diff_key compatibility function.
- *
- * @return void
- * @access public
- */
- function testArrayDiffKey() {
- $one = array('one' => 1, 'two' => 2, 'three' => 3);
- $two = array('one' => 'one', 'two' => 'two');
- $result = array_diff_key($one, $two);
- $expected = array('three' => 3);
- $this->assertEqual($result, $expected);
-
- $one = array('one' => array('value', 'value-two'), 'two' => 2, 'three' => 3);
- $two = array('two' => 'two');
- $result = array_diff_key($one, $two);
- $expected = array('one' => array('value', 'value-two'), 'three' => 3);
- $this->assertEqual($result, $expected);
-
- $one = array('one' => null, 'two' => 2, 'three' => '', 'four' => 0);
- $two = array('two' => 'two');
- $result = array_diff_key($one, $two);
- $expected = array('one' => null, 'three' => '', 'four' => 0);
- $this->assertEqual($result, $expected);
-
- $one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
- $two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true);
- $result = array_diff_key($one, $two);
- $this->assertEqual($result, array());
-
- }
-/**
- * testHttpBase method
- *
- * @return void
- * @access public
- */
- function testEnv() {
- $this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', '%s safe mode is on');
-
- $__SERVER = $_SERVER;
- $__ENV = $_ENV;
-
- $_SERVER['HTTP_HOST'] = 'localhost';
- $this->assertEqual(env('HTTP_BASE'), '.localhost');
-
- $_SERVER['HTTP_HOST'] = 'com.ar';
- $this->assertEqual(env('HTTP_BASE'), '.com.ar');
-
- $_SERVER['HTTP_HOST'] = 'example.ar';
- $this->assertEqual(env('HTTP_BASE'), '.example.ar');
-
- $_SERVER['HTTP_HOST'] = 'example.com';
- $this->assertEqual(env('HTTP_BASE'), '.example.com');
-
- $_SERVER['HTTP_HOST'] = 'www.example.com';
- $this->assertEqual(env('HTTP_BASE'), '.example.com');
-
- $_SERVER['HTTP_HOST'] = 'subdomain.example.com';
- $this->assertEqual(env('HTTP_BASE'), '.example.com');
-
- $_SERVER['HTTP_HOST'] = 'example.com.ar';
- $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
-
- $_SERVER['HTTP_HOST'] = 'www.example.com.ar';
- $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
-
- $_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
- $this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
-
- $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
- $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
-
- $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
- $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar');
-
- $_SERVER = $_ENV = array();
-
- $_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
- $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
-
- $_SERVER = $_ENV = array();
-
- $_ENV['CGI_MODE'] = 'BINARY';
- $_ENV['SCRIPT_URL'] = '/a/test/test.php';
- $this->assertEqual(env('SCRIPT_NAME'), '/a/test/test.php');
-
- $_SERVER = $_ENV = array();
-
- $this->assertFalse(env('HTTPS'));
-
- $_SERVER['HTTPS'] = 'on';
- $this->assertTrue(env('HTTPS'));
-
- $_SERVER['HTTPS'] = '1';
- $this->assertTrue(env('HTTPS'));
-
- $_SERVER['HTTPS'] = 'I am not empty';
- $this->assertTrue(env('HTTPS'));
-
- $_SERVER['HTTPS'] = 1;
- $this->assertTrue(env('HTTPS'));
-
- $_SERVER['HTTPS'] = 'off';
- $this->assertFalse(env('HTTPS'));
-
- $_SERVER['HTTPS'] = false;
- $this->assertFalse(env('HTTPS'));
-
- $_SERVER['HTTPS'] = '';
- $this->assertFalse(env('HTTPS'));
-
- $_SERVER = array();
-
- $_ENV['SCRIPT_URI'] = 'https://domain.test/a/test.php';
- $this->assertTrue(env('HTTPS'));
-
- $_ENV['SCRIPT_URI'] = 'http://domain.test/a/test.php';
- $this->assertFalse(env('HTTPS'));
-
- $_SERVER = $_ENV = array();
-
- $this->assertFalse(env('TEST_ME'));
-
- $_ENV['TEST_ME'] = 'a';
- $this->assertEqual(env('TEST_ME'), 'a');
-
- $_SERVER['TEST_ME'] = 'b';
- $this->assertEqual(env('TEST_ME'), 'b');
-
- unset($_ENV['TEST_ME']);
- $this->assertEqual(env('TEST_ME'), 'b');
-
- $_SERVER = $__SERVER;
- $_ENV = $__ENV;
- }
-
-/**
- * test uses()
- *
- * @return void
- * @access public
- * @deprecated
- */
- function testUses() {
- $this->skipIf(class_exists('Security') || class_exists('Sanitize'), '%s Security and/or Sanitize class already loaded');
-
- $this->assertFalse(class_exists('Security'));
- $this->assertFalse(class_exists('Sanitize'));
-
- uses('Security', 'Sanitize');
-
- $this->assertTrue(class_exists('Security'));
- $this->assertTrue(class_exists('Sanitize'));
- }
-
-/**
- * Test h()
- *
- * @return void
- * @access public
- */
- function testH() {
- $string = '<foo>';
- $result = h($string);
- $this->assertEqual('&lt;foo&gt;', $result);
-
- $in = array('this & that', '<p>Which one</p>');
- $result = h($in);
- $expected = array('this &amp; that', '&lt;p&gt;Which one&lt;/p&gt;');
- $this->assertEqual($expected, $result);
- }
-
-/**
- * Test a()
- *
- * @return void
- * @access public
- */
- function testA() {
- $result = a('this', 'that', 'bar');
- $this->assertEqual(array('this', 'that', 'bar'), $result);
- }
-
-/**
- * Test aa()
- *
- * @return void
- * @access public
- */
- function testAa() {
- $result = aa('a', 'b', 'c', 'd');
- $expected = array('a' => 'b', 'c' => 'd');
- $this->assertEqual($expected, $result);
-
- $result = aa('a', 'b', 'c', 'd', 'e');
- $expected = array('a' => 'b', 'c' => 'd', 'e' => null);
- $this->assertEqual($result, $expected);
- }
-
-/**
- * Test am()
- *
- * @return void
- * @access public
- */
- function testAm() {
- $result = am(array('one', 'two'), 2, 3, 4);
- $expected = array('one', 'two', 2, 3, 4);
- $this->assertEqual($result, $expected);
-
- $result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
- $expected = array('one' => array(4, 5),'two' => array('foo'));
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test cache()
- *
- * @return void
- * @access public
- */
- function testCache() {
- $_cacheDisable = Configure::read('Cache.disable');
- if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
- return;
- }
-
- Configure::write('Cache.disable', true);
- $result = cache('basics_test', 'simple cache write');
- $this->assertNull($result);
-
- $result = cache('basics_test');
- $this->assertNull($result);
-
- Configure::write('Cache.disable', false);
- $result = cache('basics_test', 'simple cache write');
- $this->assertTrue($result);
- $this->assertTrue(file_exists(CACHE . 'basics_test'));
-
- $result = cache('basics_test');
- $this->assertEqual($result, 'simple cache write');
- @unlink(CACHE . 'basics_test');
-
- cache('basics_test', 'expired', '+1 second');
- sleep(2);
- $result = cache('basics_test', null, '+1 second');
- $this->assertNull($result);
-
- Configure::write('Cache.disable', $_cacheDisable);
- }
-
-/**
- * test clearCache()
- *
- * @return void
- * @access public
- */
- function testClearCache() {
- $cacheOff = Configure::read('Cache.disable');
- if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
- return;
- }
-
- cache('views' . DS . 'basics_test.cache', 'simple cache write');
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
-
- cache('views' . DS . 'basics_test_2.cache', 'simple cache write 2');
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_2.cache'));
-
- cache('views' . DS . 'basics_test_3.cache', 'simple cache write 3');
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
-
- $result = clearCache(array('basics_test', 'basics_test_2'), 'views', '.cache');
- $this->assertTrue($result);
- $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
- $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
-
- $result = clearCache(null, 'views', '.cache');
- $this->assertTrue($result);
- $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test_3.cache'));
-
- // Different path from views and with prefix
- cache('models' . DS . 'basics_test.cache', 'simple cache write');
- $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
-
- cache('models' . DS . 'basics_test_2.cache', 'simple cache write 2');
- $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
-
- cache('models' . DS . 'basics_test_3.cache', 'simple cache write 3');
- $this->assertTrue(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
-
- $result = clearCache('basics', 'models', '.cache');
- $this->assertTrue($result);
- $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test.cache'));
- $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_2.cache'));
- $this->assertFalse(file_exists(CACHE . 'models' . DS . 'basics_test_3.cache'));
-
- // checking if empty files were not removed
- $emptyExists = file_exists(CACHE . 'views' . DS . 'empty');
- if (!$emptyExists) {
- cache('views' . DS . 'empty', '');
- }
- cache('views' . DS . 'basics_test.php', 'simple cache write');
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
-
- $result = clearCache();
- $this->assertTrue($result);
- $this->assertTrue(file_exists(CACHE . 'views' . DS . 'empty'));
- $this->assertFalse(file_exists(CACHE . 'views' . DS . 'basics_test.php'));
- if (!$emptyExists) {
- unlink(CACHE . 'views' . DS . 'empty');
- }
- }
-
-/**
- * test __()
- *
- * @return void
- * @access public
- */
- function test__() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __('Plural Rule 1', true);
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __('Plural Rule 1 (from core)', true);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __('Plural Rule 1 (from core)');
- $result = ob_get_clean();
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test __n()
- *
- * @return void
- * @access public
- */
- function test__n() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __n('%d = 1', '%d = 0 or > 1', 0, true);
- $expected = '%d = 0 or > 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __n('%d = 1', '%d = 0 or > 1', 1, true);
- $expected = '%d = 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2, true);
- $expected = '%d = 0 or > 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
- $result = ob_get_clean();
- $expected = '%d = 0 or > 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test __d()
- *
- * @return void
- * @access public
- */
- function test__d() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __d('default', 'Plural Rule 1', true);
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __d('core', 'Plural Rule 1', true);
- $expected = 'Plural Rule 1';
- $this->assertEqual($result, $expected);
-
- $result = __d('core', 'Plural Rule 1 (from core)', true);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __d('core', 'Plural Rule 1 (from core)');
- $result = ob_get_clean();
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test __dn()
- *
- * @return void
- * @access public
- */
- function test__dn() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __dn('default', '%d = 1', '%d = 0 or > 1', 0, true);
- $expected = '%d = 0 or > 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __dn('core', '%d = 1', '%d = 0 or > 1', 0, true);
- $expected = '%d = 0 or > 1';
- $this->assertEqual($result, $expected);
-
- $result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0, true);
- $expected = '%d = 0 or > 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- $result = __dn('default', '%d = 1', '%d = 0 or > 1', 1, true);
- $expected = '%d = 1 (translated)';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
- $result = ob_get_clean();
- $expected = '%d = 0 or > 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test __c()
- *
- * @return void
- * @access public
- */
- function test__c() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __c('Plural Rule 1', 6, true);
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __c('Plural Rule 1 (from core)', 6, true);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __c('Plural Rule 1 (from core)', 6);
- $result = ob_get_clean();
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test __dc()
- *
- * @return void
- * @access public
- */
- function test__dc() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __dc('default', 'Plural Rule 1', 6, true);
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __dc('default', 'Plural Rule 1 (from core)', 6, true);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- $result = __dc('core', 'Plural Rule 1', 6, true);
- $expected = 'Plural Rule 1';
- $this->assertEqual($result, $expected);
-
- $result = __dc('core', 'Plural Rule 1 (from core)', 6, true);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __dc('default', 'Plural Rule 1 (from core)', 6);
- $result = ob_get_clean();
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test __dcn()
- *
- * @return void
- * @access public
- */
- function test__dcn() {
- Configure::write('Config.language', 'rule_1_po');
-
- $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6, true);
- $expected = '%d = 0 or > 1 (translated)';
- $this->assertEqual($result, $expected);
-
- $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6, true);
- $expected = '%d = 1 (from core translated)';
- $this->assertEqual($result, $expected);
-
- $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6, true);
- $expected = '%d = 0 or > 1';
- $this->assertEqual($result, $expected);
-
- ob_start();
- __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
- $result = ob_get_clean();
- $expected = '%d = 1 (from core translated)';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test LogError()
- *
- * @return void
- * @access public
- */
- function testLogError() {
- @unlink(LOGS . 'error.log');
-
- LogError('Testing LogError() basic function');
- LogError("Testing with\nmulti-line\nstring");
-
- $result = file_get_contents(LOGS . 'error.log');
- $this->assertPattern('/Error: Testing LogError\(\) basic function/', $result);
- $this->assertNoPattern("/Error: Testing with\nmulti-line\nstring/", $result);
- $this->assertPattern('/Error: Testing with multi-line string/', $result);
- }
-
-/**
- * test fileExistsInPath()
- *
- * @return void
- * @access public
- */
- function testFileExistsInPath() {
- $this->skipUnless(function_exists('ini_set'), '%s ini_set function not available');
-
- $_includePath = ini_get('include_path');
-
- $path = TMP . 'basics_test';
- $folder1 = $path . DS . 'folder1';
- $folder2 = $path . DS . 'folder2';
- $file1 = $path . DS . 'file1.php';
- $file2 = $folder1 . DS . 'file2.php';
- $file3 = $folder1 . DS . 'file3.php';
- $file4 = $folder2 . DS . 'file4.php';
-
- new Folder($path, true);
- new Folder($folder1, true);
- new Folder($folder2, true);
- touch($file1);
- touch($file2);
- touch($file3);
- touch($file4);
-
- ini_set('include_path', $path . PATH_SEPARATOR . $folder1);
-
- $this->assertEqual(fileExistsInPath('file1.php'), $file1);
- $this->assertEqual(fileExistsInPath('file2.php'), $file2);
- $this->assertEqual(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
- $this->assertEqual(fileExistsInPath($file2), $file2);
- $this->assertEqual(fileExistsInPath('file3.php'), $file3);
- $this->assertEqual(fileExistsInPath($file4), $file4);
-
- $this->assertFalse(fileExistsInPath('file1'));
- $this->assertFalse(fileExistsInPath('file4.php'));
-
- $Folder = new Folder($path);
- $Folder->delete();
-
- ini_set('include_path', $_includePath);
- }
-
-/**
- * test convertSlash()
- *
- * @return void
- * @access public
- */
- function testConvertSlash() {
- $result = convertSlash('\path\to\location\\');
- $expected = '\path\to\location\\';
- $this->assertEqual($result, $expected);
-
- $result = convertSlash('/path/to/location/');
- $expected = 'path_to_location';
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test debug()
- *
- * @return void
- * @access public
- */
- function testDebug() {
- ob_start();
- debug('this-is-a-test');
- $result = ob_get_clean();
- $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
- $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
- $pattern .= '.*line.*' . (__LINE__ - 4) . '.*this-is-a-test.*/s';
- $this->assertPattern($pattern, $result);
-
- ob_start();
- debug('<div>this-is-a-test</div>', true);
- $result = ob_get_clean();
- $pattern = '/.*\>(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
- $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
- $pattern .= '.*line.*' . (__LINE__ - 4) . '.*&lt;div&gt;this-is-a-test&lt;\/div&gt;.*/s';
- $this->assertPattern($pattern, $result);
- }
-
-/**
- * test pr()
- *
- * @return void
- * @access public
- */
- function testPr() {
- ob_start();
- pr('this is a test');
- $result = ob_get_clean();
- $expected = "<pre>this is a test</pre>";
- $this->assertEqual($result, $expected);
-
- ob_start();
- pr(array('this' => 'is', 'a' => 'test'));
- $result = ob_get_clean();
- $expected = "<pre>Array\n(\n [this] => is\n [a] => test\n)\n</pre>";
- $this->assertEqual($result, $expected);
- }
-
-/**
- * test params()
- *
- * @return void
- * @access public
- */
- function testParams() {
- $this->assertNull(params('weekend'));
- $this->assertNull(params(array()));
- $this->assertEqual(params(array('weekend')), array('weekend'));
-
- $nested = array(array('weekend'));
- $this->assertEqual(params($nested), array('weekend'));
-
- $multiple = array(array('weekend'), 'jean-luc', 'godard');
- $this->assertEqual(params($multiple), $multiple);
- }
-
-/**
- * test stripslashes_deep()
- *
- * @return void
- * @access public
- */
- function testStripslashesDeep() {
- $this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
-
- $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
- $this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');
- $this->assertEqual(stripslashes_deep('tes\"t'), 'tes"t');
- $this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
- $this->assertEqual(stripslashes_deep('te\\st'), 'test');
-
- $nested = array(
- 'a' => "tes\'t",
- 'b' => 'tes\\' . chr(0) .'t',
- 'c' => array(
- 'd' => 'tes\"t',
- 'e' => "te\'s\'t",
- array('f' => "tes\'t")
- ),
- 'g' => 'te\\st'
- );
- $expected = array(
- 'a' => "tes't",
- 'b' => 'tes' . chr(0) .'t',
- 'c' => array(
- 'd' => 'tes"t',
- 'e' => "te's't",
- array('f' => "tes't")
- ),
- 'g' => 'test'
- );
- $this->assertEqual(stripslashes_deep($nested), $expected);
- }
-
-/**
- * test stripslashes_deep() with magic_quotes_sybase on
- *
- * @return void
- * @access public
- */
- function testStripslashesDeepSybase() {
- $this->skipUnless(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is off');
-
- $this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");
-
- $nested = array(
- 'a' => "tes't",
- 'b' => "tes''t",
- 'c' => array(
- 'd' => "tes'''t",
- 'e' => "tes''''t",
- array('f' => "tes''t")
- ),
- 'g' => "te'''''st"
- );
- $expected = array(
- 'a' => "tes't",
- 'b' => "tes't",
- 'c' => array(
- 'd' => "tes''t",
- 'e' => "tes''t",
- array('f' => "tes't")
- ),
- 'g' => "te'''st"
- );
- $this->assertEqual(stripslashes_deep($nested), $expected);
- }
-
-/**
- * test ife()
- *
- * @return void
- * @access public
- */
- function testIfe() {
- $this->assertEqual(ife(true, 'a', 'b'), 'a');
- $this->assertEqual(ife(' ', 'a', 'b'), 'a');
- $this->assertEqual(ife('test', 'a', 'b'), 'a');
- $this->assertEqual(ife(23, 'a', 'b'), 'a');
- $this->assertEqual(ife(array('t' => 'est'), 'a', 'b'), 'a');
-
- $this->assertEqual(ife(false, 'a', 'b'), 'b');
- $this->assertEqual(ife(null, 'a', 'b'), 'b');
- $this->assertEqual(ife('', 'a', 'b'), 'b');
- $this->assertEqual(ife(0, 'a', 'b'), 'b');
- $this->assertEqual(ife(array(), 'a', 'b'), 'b');
- }
-
-/**
- * test pluginSplit
- *
- * @return void
- */
- function testPluginSplit() {
- $result = pluginSplit('Something.else');
- $this->assertEqual($result, array('Something', 'else'));
-
- $result = pluginSplit('Something.else.more.dots');
- $this->assertEqual($result, array('Something', 'else.more.dots'));
-
- $result = pluginSplit('Somethingelse');
- $this->assertEqual($result, array(null, 'Somethingelse'));
-
- $result = pluginSplit('Something.else', true);
- $this->assertEqual($result, array('Something.', 'else'));
-
- $result = pluginSplit('Something.else.more.dots', true);
- $this->assertEqual($result, array('Something.', 'else.more.dots'));
-
- $result = pluginSplit('Post', false, 'Blog');
- $this->assertEqual($result, array('Blog', 'Post'));
-
- $result = pluginSplit('Blog.Post', false, 'Ultimate');
- $this->assertEqual($result, array('Blog', 'Post'));
- }
-}
View
939 app/cake/tests/cases/console/cake.test.php
@@ -1,939 +0,0 @@
-<?php
-/**
- * ShellDispatcherTest file
- *
- * PHP versions 4 and 5
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
- * Copyright 2005-2010, Cake Software Foundation, Inc.
- *
- * Licensed under The Open Group Test Suite License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright 2005-2010, Cake Software Foundation, Inc.
- * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
- * @package cake
- * @subpackage cake.tests.cases.console
- * @since CakePHP(tm) v 1.2.0.5432
- * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
- */
-if (!defined('DISABLE_AUTO_DISPATCH')) {
- define('DISABLE_AUTO_DISPATCH', true);
-}
-
-if (!class_exists('ShellDispatcher')) {
- ob_start();
- $argv = false;
- require CAKE . 'console' . DS . 'cake.php';
- ob_end_clean();
-}
-
-require_once CONSOLE_LIBS . 'shell.php';
-
-/**
- * TestShellDispatcher class
- *
- * @package cake
- * @subpackage cake.tests.cases.console
- */
-class TestShellDispatcher extends ShellDispatcher {
-
-/**
- * params property
- *
- * @var array
- * @access public
- */
- var $params = array();
-
-/**
- * stdout property
- *
- * @var string
- * @access public
- */
- var $stdout = '';
-
-/**
- * stderr property
- *
- * @var string
- * @access public
- */
- var $stderr = '';
-
-/**
- * stopped property
- *
- * @var string
- * @access public
- */
- var $stopped = null;
-
-/**
- * TestShell
- *
- * @var mixed
- * @access public
- */
- var $TestShell;
-
-/**
- * _initEnvironment method
- *
- * @return void
- * @access protected
- */
- function _initEnvironment() {
- }
-
-/**
- * stderr method
- *
- * @return void
- * @access public
- */
- function stderr($string) {
- $this->stderr .= rtrim($string, ' ');
- }
-
-/**
- * stdout method
- *
- * @return void
- * @access public
- */
- function stdout($string, $newline = true) {
- if ($newline) {
- $this->stdout .= rtrim($string, ' ') . "\n";
- } else {
- $this->stdout .= rtrim($string, ' ');
- }
- }
-
-/**
- * clear method
- *
- * @return void
- * @access public
- */
- function clear() {
-
- }
-
-/**
- * _stop method
- *
- * @return void
- * @access protected
- */
- function _stop($status = 0) {
- $this->stopped = 'Stopped with status: ' . $status;
- return $status;
- }
-
-/**
- * getShell
- *
- * @param mixed $plugin
- * @return mixed
- * @access public
- */
- function getShell($plugin = null) {
- return $this->_getShell($plugin);
- }
-
-/**
- * _getShell
- *
- * @param mixed $plugin
- * @return mixed
- * @access protected
- */
- function _getShell($plugin = null) {
- if (isset($this->TestShell)) {
- return $this->TestShell;
- }
- return parent::_getShell($plugin);
- }
-}
-
-/**
- * ShellDispatcherTest
- *
- * @package cake
- * @subpackage cake.tests.cases.libs
- */
-class ShellDispatcherTest extends CakeTestCase {
-
-/**
- * setUp method
- *
- * @return void
- * @access public
- */
- function setUp() {
- App::build(array(
- 'plugins' => array(
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
- ),
- 'shells' => array(
- CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS,
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
- )
- ), true);
- }
-
-/**
- * tearDown method
- *
- * @return void
- * @access public
- */
- function tearDown() {
- App::build();
- }
-
-/**
- * testParseParams method
- *
- * @return void
- * @access public
- */
- function testParseParams() {
- $Dispatcher =& new TestShellDispatcher();
-
- $params = array(
- '/cake/1.2.x.x/cake/console/cake.php',
- 'bake',
- '-app',
- 'new',
- '-working',
- '/var/www/htdocs'
- );
- $expected = array(
- 'app' => 'new',
- 'webroot' => 'webroot',
- 'working' => '/var/www/htdocs/new',
- 'root' => '/var/www/htdocs'
- );
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array('cake.php');
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
- 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- 'cake.php',
- '-app',
- 'new',
- );
- $expected = array(
- 'app' => 'new',
- 'webroot' => 'webroot',
- 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
- 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- './cake.php',
- 'bake',
- '-app',
- 'new',
- '-working',
- '/cake/1.2.x.x/cake/console'
- );
-
- $expected = array(
- 'app' => 'new',
- 'webroot' => 'webroot',
- 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
- 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
- );
-
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- './console/cake.php',
- 'bake',
- '-app',
- 'new',
- '-working',
- '/cake/1.2.x.x/cake'
- );
- $expected = array(
- 'app' => 'new',
- 'webroot' => 'webroot',
- 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
- 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- './console/cake.php',
- 'bake',
- '-app',
- 'new',
- '-dry',
- '-working',
- '/cake/1.2.x.x/cake'
- );
- $expected = array(
- 'app' => 'new',
- 'webroot' => 'webroot',
- 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
- 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
- 'dry' => 1
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- './console/cake.php',
- '-working',
- '/cake/1.2.x.x/cake',
- 'schema',
- 'run',
- 'create',
- '-dry',
- '-f',
- '-name',
- 'DbAcl'
- );
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
- 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
- 'dry' => 1,
- 'f' => 1,
- 'name' => 'DbAcl'
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $expected = array('./console/cake.php', 'schema', 'run', 'create');
- $this->assertEqual($expected, $Dispatcher->args);
-
- $params = array(
- '/cake/1.2.x.x/cake/console/cake.php',
- '-working',
- '/cake/1.2.x.x/app',
- 'schema',
- 'run',
- 'create',
- '-dry',
- '-name',
- 'DbAcl'
- );
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => '/cake/1.2.x.x/app',
- 'root' => '/cake/1.2.x.x',
- 'dry' => 1,
- 'name' => 'DbAcl'
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $expected = array('/cake/1.2.x.x/cake/console/cake.php', 'schema', 'run', 'create');
- $this->assertEqual($expected, $Dispatcher->args);
- $params = array(
- 'cake.php',
- '-working',
- 'C:/wamp/www/cake/app',
- 'bake',
- '-app',
- 'C:/wamp/www/apps/cake/app',
- );
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => 'C:\wamp\www\apps\cake\app',
- 'root' => 'C:\wamp\www\apps\cake'
- );
-
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- 'cake.php',
- '-working',
- 'C:\wamp\www\cake\app',
- 'bake',
- '-app',
- 'C:\wamp\www\apps\cake\app',
- );
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => 'C:\wamp\www\apps\cake\app',
- 'root' => 'C:\wamp\www\apps\cake'
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- 'cake.php',
- '-working',
- 'C:\wamp\www\apps',
- 'bake',
- '-app',
- 'cake\app',
- '-url',
- 'http://example.com/some/url/with/a/path'
- );
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => 'C:\wamp\www\apps\cake\app',
- 'root' => 'C:\wamp\www\apps\cake',
- 'url' => 'http://example.com/some/url/with/a/path'
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- '/home/amelo/dev/cake-common/cake/console/cake.php',
- '-root',
- '/home/amelo/dev/lsbu-vacancy',
- '-working',
- '/home/amelo/dev/lsbu-vacancy',
- '-app',
- 'app',
- );
- $expected = array(
- 'app' => 'app',
- 'webroot' => 'webroot',
- 'working' => '/home/amelo/dev/lsbu-vacancy/app',
- 'root' => '/home/amelo/dev/lsbu-vacancy',
- );
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
-
- $params = array(
- 'cake.php',
- '-working',
- 'D:\www',
- 'bake',
- 'my_app',
- );
- $expected = array(
- 'working' => 'D:\www',
- 'app' => 'www',
- 'root' => 'D:',
- 'webroot' => 'webroot'
- );
-
- $Dispatcher->params = $Dispatcher->args = array();
- $Dispatcher->parseParams($params);
- $this->assertEqual($expected, $Dispatcher->params);
- }
-
-/**
- * testBuildPaths method
- *
- * @return void
- * @access public
- */
- function testBuildPaths() {
- $Dispatcher =& new TestShellDispatcher();
-
- $result = $Dispatcher->shellPaths;
-
- $expected = array(
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS,
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS . 'vendors' . DS . 'shells' . DS,
- APP . 'vendors' . DS . 'shells' . DS,
- VENDORS . 'shells' . DS,
- CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS,
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS,
- );
- $this->assertIdentical(array_diff($result, $expected), array());
- $this->assertIdentical(array_diff($expected, $result), array());
- }
-
-/**
- * Verify loading of (plugin-) shells
- *
- * @return void
- * @access public
- */
- function testGetShell() {
- $this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
- $this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Dispatcher->shell = 'sample';
- $Dispatcher->shellName = 'Sample';
- $Dispatcher->shellClass = 'SampleShell';
-
- $result = $Dispatcher->getShell();
- $this->assertIsA($result, 'SampleShell');
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Dispatcher->shell = 'example';
- $Dispatcher->shellName = 'Example';
- $Dispatcher->shellClass = 'ExampleShell';
-
- $result = $Dispatcher->getShell('test_plugin');
- $this->assertIsA($result, 'ExampleShell');
- }
-
-/**
- * Verify correct dispatch of Shell subclasses with a main method
- *
- * @return void
- * @access public
- */
- function testDispatchShellWithMain() {
- Mock::generate('Shell', 'MockWithMainShell', array('main', '_secret'));
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Shell = new MockWithMainShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('initialize');
- $Shell->expectOnce('loadTasks');
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWithMainShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main', 'initdb');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('initdb'));
-
- $Shell = new MockWithMainShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('help');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main', 'help');
- $result = $Dispatcher->dispatch();
- $this->assertNull($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWithMainShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectNever('hr');
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main', 'hr');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('hr'));
-
- $Shell = new MockWithMainShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main', 'dispatch');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('dispatch'));
-
- $Shell = new MockWithMainShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main', 'idontexist');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('idontexist'));
-
- $Shell = new MockWithMainShell();
- $Shell->expectNever('startup');
- $Shell->expectNever('main');
- $Shell->expectNever('_secret');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main', '_secret');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
- }
-
-/**
- * Verify correct dispatch of Shell subclasses without a main method
- *
- * @return void
- * @access public
- */
- function testDispatchShellWithoutMain() {
- Mock::generate('Shell', 'MockWithoutMainShell', array('initDb', '_secret'));
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Shell = new MockWithoutMainShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectOnce('initialize');
- $Shell->expectOnce('loadTasks');
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWithoutMainShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('initDb');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main', 'initdb');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWithoutMainShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectNever('startup');
- $Shell->expectNever('hr');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main', 'hr');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
- $this->assertEqual($Dispatcher->args, array('hr'));
-
- $Shell = new MockWithoutMainShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main', 'dispatch');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
-
- $Shell = new MockWithoutMainShell();
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main', 'idontexist');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
-
- $Shell = new MockWithoutMainShell();
- $Shell->expectNever('startup');
- $Shell->expectNever('_secret');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main', '_secret');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
- }
-
-/**
- * Verify correct dispatch of custom classes with a main method
- *
- * @return void
- * @access public
- */
- function testDispatchNotAShellWithMain() {
- Mock::generate('Object', 'MockWithMainNotAShell',
- array('main', 'initialize', 'loadTasks', 'startup', '_secret'));
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Shell = new MockWithMainNotAShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectNever('initialize');
- $Shell->expectNever('loadTasks');
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main_not_a');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWithMainNotAShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main_not_a', 'initdb');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('initdb'));
-
- $Shell = new MockWithMainNotAShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main_not_a', 'hr');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('hr'));
-
- $Shell = new MockWithMainNotAShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main_not_a', 'dispatch');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('dispatch'));
-
- $Shell = new MockWithMainNotAShell();
- $Shell->setReturnValue('main', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('main');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main_not_a', 'idontexist');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array('idontexist'));
-
- $Shell = new MockWithMainNotAShell();
- $Shell->expectNever('startup');
- $Shell->expectNever('main');
- $Shell->expectNever('_secret');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_with_main_not_a', '_secret');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
- }
-
-/**
- * Verify correct dispatch of custom classes without a main method
- *
- * @return void
- * @access public
- */
- function testDispatchNotAShellWithoutMain() {
- Mock::generate('Object', 'MockWithoutMainNotAShell',
- array('initDb', 'initialize', 'loadTasks', 'startup', '_secret'));
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Shell = new MockWithoutMainNotAShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectNever('initialize');
- $Shell->expectNever('loadTasks');
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main_not_a');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
-
- $Shell = new MockWithoutMainNotAShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectOnce('startup');
- $Shell->expectOnce('initDb');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main_not_a', 'initdb');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWithoutMainNotAShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main_not_a', 'hr');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
-
- $Shell = new MockWithoutMainNotAShell();
- $Shell->setReturnValue('initDb', true);
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main_not_a', 'dispatch');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
-
- $Shell = new MockWithoutMainNotAShell();
- $Shell->expectNever('startup');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main_not_a', 'idontexist');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
-
- $Shell = new MockWithoutMainNotAShell();
- $Shell->expectNever('startup');
- $Shell->expectNever('_secret');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_without_main_not_a', '_secret');
- $result = $Dispatcher->dispatch();
- $this->assertFalse($result);
- }
-
-/**
- * Verify that a task is called instead of the shell if the first arg equals
- * the name of the task
- *
- * @return void
- * @access public
- */
- function testDispatchTask() {
- Mock::generate('Shell', 'MockWeekShell', array('main'));
- Mock::generate('Shell', 'MockOnSundayTask', array('execute'));
-
- $Dispatcher =& new TestShellDispatcher();
-
- $Shell = new MockWeekShell();
- $Shell->expectOnce('initialize');
- $Shell->expectOnce('loadTasks');
- $Shell->expectNever('startup');
- $Shell->expectNever('main');
-
- $Task = new MockOnSundayTask();
- $Task->setReturnValue('execute', true);
- $Task->expectOnce('initialize');
- $Task->expectOnce('loadTasks');
- $Task->expectOnce('startup');
- $Task->expectOnce('execute');
-
- $Shell->MockOnSunday =& $Task;
- $Shell->taskNames = array('MockOnSunday');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_week', 'mock_on_sunday');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- $this->assertEqual($Dispatcher->args, array());
-
- $Shell = new MockWeekShell();
- $Task = new MockOnSundayTask();
- $Task->expectNever('execute');
- $Task->expectOnce('help');
-
- $Shell->MockOnSunday =& $Task;
- $Shell->taskNames = array('MockOnSunday');
- $Dispatcher->TestShell =& $Shell;
-
- $Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help');
- $result = $Dispatcher->dispatch();
- $this->assertTrue($result);
- }
-
-/**
- * Verify shifting of arguments
- *
- * @return void
- * @access public
- */
- function testShiftArgs() {
- $Dispatcher =& new TestShellDispatcher();
-
- $Dispatcher->args = array('a', 'b', 'c');
- $this->assertEqual($Dispatcher->shiftArgs(), 'a');
- $this->assertIdentical($Dispatcher->args, array('b', 'c'));
-
- $Dispatcher->args = array('a' => 'b', 'c', 'd');
- $this->assertEqual($Dispatcher->shiftArgs(), 'b');
- $this->assertIdentical($Dispatcher->args, array('c', 'd'));
-
- $Dispatcher->args = array('a', 'b' => 'c', 'd');
- $this->assertEqual($Dispatcher->shiftArgs(), 'a');
- $this->assertIdentical($Dispatcher->args, array('b' => 'c', 'd'));
-
- $Dispatcher->args = array(0 => 'a', 2 => 'b', 30 => 'c');
- $this->assertEqual($Dispatcher->shiftArgs(), 'a');
- $this->assertIdentical($Dispatcher->args, array(0 => 'b', 1 => 'c'));
-
- $Dispatcher->args = array();
- $this->assertNull($Dispatcher->shiftArgs());
- $this->assertIdentical($Dispatcher->args, array());
- }
-
-/**
- * testHelpCommand method
- *
- * @return void
- * @access public
- */
- function testHelpCommand() {
- $Dispatcher =& new TestShellDispatcher();
-
- $expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/welcome \[.*TestPluginTwo.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/acl \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/api \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/bake \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/console \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/i18n \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/schema \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/testsuite \[.*CORE.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
-
- $expected = "/sample \[.*test_app.*\]/";
- $this->assertPattern($expected, $Dispatcher->stdout);
- }
-}
View
346 app/cake/tests/cases/console/libs/acl.test.php
@@ -1,346 +0,0 @@
-<?php
-/**
- * AclShell Test file
- *
- * PHP versions 4 and 5
- *
- * CakePHP : Rapid Development Framework (http://cakephp.org)
- * Copyright 2006-2010, Cake Software Foundation, Inc.
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
- * @link http://cakephp.org CakePHP Project
- * @package cake
- * @subpackage cake.tests.cases.console.libs.tasks
- * @since CakePHP v 1.2.0.7726
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
-App::import('Shell', 'Shell', false);
-
-if (!defined('DISABLE_AUTO_DISPATCH')) {
- define('DISABLE_AUTO_DISPATCH', true);
-}
-
-if (!class_exists('ShellDispatcher')) {
- ob_start();
- $argv = false;
- require CAKE . 'console' . DS . 'cake.php';
- ob_end_clean();
-}
-
-if (!class_exists('AclShell')) {
- require CAKE . 'console' . DS . 'libs' . DS . 'acl.php';
-}
-
-Mock::generatePartial(
- 'ShellDispatcher', 'TestAclShellMockShellDispatcher',
- array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch')
-);
-Mock::generatePartial(
- 'AclShell', 'MockAclShell',
- array('in', 'out', 'hr', 'createFile', 'error', 'err')
-);
-
-Mock::generate('AclComponent', 'MockAclShellAclComponent');
-
-/**
- * AclShellTest class
- *
- * @package cake
- * @subpackage cake.tests.cases.console.libs.tasks
- */
-class AclShellTest extends CakeTestCase {
-
-/**
- * Fixtures
- *
- * @var array
- * @access public
- */
- var $fixtures = array('core.aco', 'core.aro', 'core.aros_aco');
-
-/**
- * configure Configure for testcase
- *
- * @return void
- * @access public
- */
- function startCase() {
- $this->_aclDb = Configure::read('Acl.database');
- $this->_aclClass = Configure::read('Acl.classname');
-
- Configure::write('Acl.database', 'test_suite');
- Configure::write('Acl.classname', 'DbAcl');
- }
-
-/**
- * restore Environment settings
- *
- * @return void
- * @access public
- */
- function endCase() {
- Configure::write('Acl.database', $this->_aclDb);
- Configure::write('Acl.classname', $this->_aclClass);
- }
-
-/**
- * startTest method
- *
- * @return void
- * @access public
- */
- function startTest() {
- $this->Dispatcher =& new TestAclShellMockShellDispatcher();
- $this->Task =& new MockAclShell($this->Dispatcher);
- $this->Task->Dispatch =& $this->Dispatcher;
- $this->Task->params['datasource'] = 'test_suite';
- $this->Task->Acl =& new AclComponent();
- $controller = null;
- $this->Task->Acl->startup($controller);
- }
-
-/**
- * endTest method
- *
- * @return void
- * @access public
- */
- function endTest() {
- ClassRegistry::flush();
- }
-
-/**
- * test that model.foreign_key output works when looking at acl rows
- *
- * @return void
- * @access public
- */
- function testViewWithModelForeignKeyOutput() {
- $this->Task->command = 'view';
- $this->Task->startup();
- $data = array(
- 'parent_id' => null,
- 'model' => 'MyModel',
- 'foreign_key' => 2,
- );
- $this->Task->Acl->Aro->create($data);
- $this->Task->Acl->Aro->save();
- $this->Task->args[0] = 'aro';
-
- $this->Task->expectAt(0, 'out', array('Aro tree:'));
- $this->Task->expectAt(1, 'out', array(new PatternExpectation('/\[1\] ROOT/')));
- $this->Task->expectAt(3, 'out', array(new PatternExpectation('/\[3\] Gandalf/')));
- $this->Task->expectAt(5, 'out', array(new PatternExpectation('/\[5\] MyModel.2/')));
-
- $this->Task->view();
- }
-
-/**
- * test view with an argument
- *
- * @return void
- * @access public
- */
- function testViewWithArgument() {
- $this->Task->args = array('aro', 'admins');
- $this->Task->expectAt(0, 'out', array('Aro tree:'));
- $this->Task->expectAt(1, 'out', array(' [2] admins'));
- $this->Task->expectAt(2, 'out', array(' [3] Gandalf'));
- $this->Task->expectAt(3, 'out', array(' [4] Elrond'));
- $this->Task->view();
- }
-
-/**
- * test the method that splits model.foreign key. and that it returns an array.
- *
- * @return void
- * @access public
- */
- function testParsingModelAndForeignKey() {
- $result = $this->Task->parseIdentifier('Model.foreignKey');
- $expected = array('model' => 'Model', 'foreign_key' => 'foreignKey');
-
- $result = $this->Task->parseIdentifier('mySuperUser');
- $this->assertEqual($result, 'mySuperUser');
-
- $result = $this->Task->parseIdentifier('111234');
- $this->assertEqual($result, '111234');
- }
-
-/**
- * test creating aro/aco nodes
- *
- * @return void
-