2008-09-29 18:01:52 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* BasicsTest file
|
2008-09-29 18:01:52 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-09-29 18:01:52 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-09-29 18:01:52 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-09-29 18:01:52 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-09-29 18:01:52 +00:00
|
|
|
*/
|
2010-12-09 03:45:18 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
require_once CAKE . 'basics.php';
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('Folder', 'Utility');
|
2011-10-28 01:28:42 +00:00
|
|
|
App::uses('CakeResponse', 'Network');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-29 18:01:52 +00:00
|
|
|
/**
|
|
|
|
* BasicsTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case
|
2008-09-29 18:01:52 +00:00
|
|
|
*/
|
|
|
|
class BasicsTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function setUp() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
|
2009-06-11 16:13:16 +00:00
|
|
|
));
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-03 19:24:38 +00:00
|
|
|
/**
|
|
|
|
* test the array_diff_key compatibility function.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testArrayDiffKey() {
|
2009-08-03 19:24:38 +00:00
|
|
|
$one = array('one' => 1, 'two' => 2, 'three' => 3);
|
|
|
|
$two = array('one' => 'one', 'two' => 'two');
|
|
|
|
$result = array_diff_key($one, $two);
|
|
|
|
$expected = array('three' => 3);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-08-03 19:24:38 +00:00
|
|
|
|
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-08-03 19:24:38 +00:00
|
|
|
|
|
|
|
$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);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-08-03 19:24:38 +00:00
|
|
|
|
|
|
|
$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);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $result);
|
2009-08-03 19:24:38 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-09-29 18:01:52 +00:00
|
|
|
/**
|
|
|
|
* testHttpBase method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testEnv() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', 'Safe mode is on.');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
2012-03-11 04:12:08 +00:00
|
|
|
$server = $_SERVER;
|
|
|
|
$env = $_ENV;
|
2008-09-29 18:01:52 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'localhost';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.localhost');
|
2011-01-09 20:43:41 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'com.ar';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.com.ar');
|
2011-01-09 20:43:41 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'example.ar';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.ar');
|
2008-09-29 18:01:52 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.com');
|
2008-09-29 18:01:52 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'www.example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.com');
|
2008-09-29 18:01:52 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'subdomain.example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.com');
|
2008-09-29 18:01:52 +00:00
|
|
|
|
2011-01-09 20:43:41 +00:00
|
|
|
$_SERVER['HTTP_HOST'] = 'example.com.ar';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.com.ar');
|
2011-01-09 20:43:41 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'www.example.com.ar';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.com.ar');
|
2011-01-09 20:43:41 +00:00
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.example.com.ar');
|
2011-01-09 20:43:41 +00:00
|
|
|
|
2008-09-29 18:01:52 +00:00
|
|
|
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.subdomain.example.com');
|
2008-09-29 18:01:52 +00:00
|
|
|
|
2011-01-09 20:43:41 +00:00
|
|
|
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('HTTP_BASE'), '.subdomain.example.com.ar');
|
2011-01-09 20:43:41 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
$_SERVER = $_ENV = array();
|
|
|
|
|
|
|
|
$_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('SCRIPT_NAME'), '/a/test/test.php');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$_SERVER = $_ENV = array();
|
|
|
|
|
|
|
|
$_ENV['CGI_MODE'] = 'BINARY';
|
|
|
|
$_ENV['SCRIPT_URL'] = '/a/test/test.php';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('SCRIPT_NAME'), '/a/test/test.php');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$_SERVER = $_ENV = array();
|
|
|
|
|
2009-07-22 13:40:12 +00:00
|
|
|
$this->assertFalse(env('HTTPS'));
|
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
$_SERVER['HTTPS'] = 'on';
|
|
|
|
$this->assertTrue(env('HTTPS'));
|
|
|
|
|
2009-07-22 13:40:12 +00:00
|
|
|
$_SERVER['HTTPS'] = '1';
|
|
|
|
$this->assertTrue(env('HTTPS'));
|
|
|
|
|
|
|
|
$_SERVER['HTTPS'] = 'I am not empty';
|
|
|
|
$this->assertTrue(env('HTTPS'));
|
|
|
|
|
|
|
|
$_SERVER['HTTPS'] = 1;
|
|
|
|
$this->assertTrue(env('HTTPS'));
|
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
$_SERVER['HTTPS'] = 'off';
|
|
|
|
$this->assertFalse(env('HTTPS'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-22 13:40:12 +00:00
|
|
|
$_SERVER['HTTPS'] = false;
|
|
|
|
$this->assertFalse(env('HTTPS'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-22 13:40:12 +00:00
|
|
|
$_SERVER['HTTPS'] = '';
|
|
|
|
$this->assertFalse(env('HTTPS'));
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$_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();
|
|
|
|
|
2010-06-09 21:07:36 +00:00
|
|
|
$this->assertNull(env('TEST_ME'));
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$_ENV['TEST_ME'] = 'a';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('TEST_ME'), 'a');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$_SERVER['TEST_ME'] = 'b';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('TEST_ME'), 'b');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
unset($_ENV['TEST_ME']);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(env('TEST_ME'), 'b');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
2012-03-11 04:12:08 +00:00
|
|
|
$_SERVER = $server;
|
|
|
|
$_ENV = $env;
|
2008-09-29 18:01:52 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-01 00:09:00 +00:00
|
|
|
/**
|
|
|
|
* Test h()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testH() {
|
2008-10-01 00:09:00 +00:00
|
|
|
$string = '<foo>';
|
|
|
|
$result = h($string);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('<foo>', $result);
|
2008-10-01 00:09:00 +00:00
|
|
|
|
|
|
|
$in = array('this & that', '<p>Which one</p>');
|
|
|
|
$result = h($in);
|
|
|
|
$expected = array('this & that', '<p>Which one</p>');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-10-12 01:23:05 +00:00
|
|
|
|
|
|
|
$string = '<foo> & ';
|
|
|
|
$result = h($string);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('<foo> & &nbsp;', $result);
|
2010-10-12 01:23:05 +00:00
|
|
|
|
|
|
|
$string = '<foo> & ';
|
|
|
|
$result = h($string, false);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('<foo> & ', $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-12 02:26:41 +00:00
|
|
|
$string = '<foo> & ';
|
|
|
|
$result = h($string, 'UTF-8');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('<foo> & &nbsp;', $result);
|
2010-10-12 02:26:41 +00:00
|
|
|
|
|
|
|
$arr = array('<foo>', ' ');
|
|
|
|
$result = h($arr);
|
|
|
|
$expected = array(
|
|
|
|
'<foo>',
|
|
|
|
'&nbsp;'
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-10-12 02:26:41 +00:00
|
|
|
|
|
|
|
$arr = array('<foo>', ' ');
|
|
|
|
$result = h($arr, false);
|
|
|
|
$expected = array(
|
|
|
|
'<foo>',
|
|
|
|
' '
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-23 16:18:39 +00:00
|
|
|
$arr = array('f' => '<foo>', 'n' => ' ');
|
|
|
|
$result = h($arr, false);
|
|
|
|
$expected = array(
|
|
|
|
'f' => '<foo>',
|
|
|
|
'n' => ' '
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-10-28 01:28:42 +00:00
|
|
|
|
|
|
|
$obj = new stdClass();
|
|
|
|
$result = h($obj);
|
|
|
|
$this->assertEquals('(object)stdClass', $result);
|
|
|
|
|
|
|
|
$obj = new CakeResponse(array('body' => 'Body content'));
|
|
|
|
$result = h($obj);
|
|
|
|
$this->assertEquals('Body content', $result);
|
2008-10-01 00:09:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-01 00:09:00 +00:00
|
|
|
/**
|
|
|
|
* Test am()
|
|
|
|
*
|
|
|
|
* @return void
|
2008-10-16 01:11:09 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAm() {
|
2008-10-01 00:09:00 +00:00
|
|
|
$result = am(array('one', 'two'), 2, 3, 4);
|
|
|
|
$expected = array('one', 'two', 2, 3, 4);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-01 00:09:00 +00:00
|
|
|
|
|
|
|
$result = am(array('one' => array(2, 3), 'two' => array('foo')), array('one' => array(4, 5)));
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array('one' => array(4, 5), 'two' => array('foo'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-01 00:09:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-01 00:09:00 +00:00
|
|
|
/**
|
|
|
|
* test cache()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testCache() {
|
2009-03-11 23:46:10 +00:00
|
|
|
$_cacheDisable = Configure::read('Cache.disable');
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests.');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
2008-10-01 00:09:00 +00:00
|
|
|
Configure::write('Cache.disable', true);
|
|
|
|
$result = cache('basics_test', 'simple cache write');
|
|
|
|
$this->assertNull($result);
|
|
|
|
|
|
|
|
$result = cache('basics_test');
|
|
|
|
$this->assertNull($result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2008-10-01 00:09:00 +00:00
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
$result = cache('basics_test', 'simple cache write');
|
2010-06-09 21:07:36 +00:00
|
|
|
$this->assertTrue((boolean)$result);
|
2008-10-01 00:09:00 +00:00
|
|
|
$this->assertTrue(file_exists(CACHE . 'basics_test'));
|
|
|
|
|
|
|
|
$result = cache('basics_test');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('simple cache write', $result);
|
2008-10-01 00:09:00 +00:00
|
|
|
@unlink(CACHE . 'basics_test');
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2008-10-01 00:09:00 +00:00
|
|
|
cache('basics_test', 'expired', '+1 second');
|
|
|
|
sleep(2);
|
|
|
|
$result = cache('basics_test', null, '+1 second');
|
|
|
|
$this->assertNull($result);
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
Configure::write('Cache.disable', $_cacheDisable);
|
2008-10-01 00:09:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test clearCache()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testClearCache() {
|
2009-09-13 18:03:16 +00:00
|
|
|
$cacheOff = Configure::read('Cache.disable');
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests.');
|
2009-09-13 18:03:16 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
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'));
|
2010-03-18 23:31:03 +00:00
|
|
|
|
|
|
|
// 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');
|
|
|
|
}
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslate() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __('Plural Rule 1');
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __('Plural Rule 1 (from core)');
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __('Some string with %s', 'arguments');
|
|
|
|
$expected = 'Some string with arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __('Some string with %s %s', 'multiple', 'arguments');
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __('Some string with %s %s', array('multiple', 'arguments'));
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __('Testing %2$s %1$s', 'order', 'different');
|
|
|
|
$expected = 'Testing different order';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __('Testing %2$s %1$s', array('order', 'different'));
|
|
|
|
$expected = 'Testing different order';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __('Testing %.2f number', 1.2345);
|
|
|
|
$expected = 'Testing 1.23 number';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __n()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslatePlural() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __n('%d = 1', '%d = 0 or > 1', 0);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __n('%d = 1', '%d = 0 or > 1', 1);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __n('%d item.', '%d items.', 1, 1);
|
|
|
|
$expected = '1 item.';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __n('%d item for id %s', '%d items for id %s', 2, 2, '1234');
|
|
|
|
$expected = '2 items for id 1234';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __n('%d item for id %s', '%d items for id %s', 2, array(2, '1234'));
|
|
|
|
$expected = '2 items for id 1234';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __d()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslateDomain() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __d('default', 'Plural Rule 1');
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __d('core', 'Plural Rule 1');
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __d('core', 'Plural Rule 1 (from core)');
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __d('core', 'Some string with %s', 'arguments');
|
|
|
|
$expected = 'Some string with arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __d('core', 'Some string with %s %s', 'multiple', 'arguments');
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __d('core', 'Some string with %s %s', array('multiple', 'arguments'));
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __dn()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslateDomainPlural() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dn('default', '%d = 1', '%d = 0 or > 1', 0);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dn('core', '%d = 1', '%d = 0 or > 1', 0);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dn('default', '%d = 1', '%d = 0 or > 1', 1);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-12-05 01:34:59 +00:00
|
|
|
$result = __dn('core', '%d item.', '%d items.', 1, 1);
|
|
|
|
$expected = '1 item.';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dn('core', '%d item for id %s', '%d items for id %s', 2, 2, '1234');
|
|
|
|
$expected = '2 items for id 1234';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dn('core', '%d item for id %s', '%d items for id %s', 2, array(2, '1234'));
|
|
|
|
$expected = '2 items for id 1234';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __c()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslateCategory() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __c('Plural Rule 1', 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __c('Plural Rule 1 (from core)', 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __c('Some string with %s', 6, 'arguments');
|
|
|
|
$expected = 'Some string with arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __c('Some string with %s %s', 6, 'multiple', 'arguments');
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __c('Some string with %s %s', 6, array('multiple', 'arguments'));
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __dc()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslateDomainCategory() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dc('default', 'Plural Rule 1', 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dc('default', 'Plural Rule 1 (from core)', 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dc('core', 'Plural Rule 1', 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-01 00:09:00 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dc('core', 'Plural Rule 1 (from core)', 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = 'Plural Rule 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dc('core', 'Some string with %s', 6, 'arguments');
|
|
|
|
$expected = 'Some string with arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dc('core', 'Some string with %s %s', 6, 'multiple', 'arguments');
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dc('core', 'Some string with %s %s', 6, array('multiple', 'arguments'));
|
|
|
|
$expected = 'Some string with multiple arguments';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test __dcn()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:12:08 +00:00
|
|
|
public function testTranslateDomainCategoryPlural() {
|
2008-10-16 01:11:09 +00:00
|
|
|
Configure::write('Config.language', 'rule_1_po');
|
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1 (translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 1 (from core translated)';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
2010-04-15 16:38:12 +00:00
|
|
|
$result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6);
|
2008-10-16 01:11:09 +00:00
|
|
|
$expected = '%d = 0 or > 1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dcn('core', '%d item.', '%d items.', 1, 6, 1);
|
|
|
|
$expected = '1 item.';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dcn('core', '%d item for id %s', '%d items for id %s', 2, 6, 2, '1234');
|
|
|
|
$expected = '2 items for id 1234';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-05 01:34:59 +00:00
|
|
|
|
|
|
|
$result = __dcn('core', '%d item for id %s', '%d items for id %s', 2, 6, array(2, '1234'));
|
|
|
|
$expected = '2 items for id 1234';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test LogError()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testLogError() {
|
2008-10-16 01:11:09 +00:00
|
|
|
@unlink(LOGS . 'error.log');
|
|
|
|
|
2012-05-09 05:03:51 +00:00
|
|
|
// disable stderr output for this test
|
2012-05-25 16:27:40 +00:00
|
|
|
if (CakeLog::stream('stderr')) {
|
|
|
|
CakeLog::disable('stderr');
|
|
|
|
}
|
2012-05-09 05:03:51 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
LogError('Testing LogError() basic function');
|
|
|
|
LogError("Testing with\nmulti-line\nstring");
|
|
|
|
|
2012-05-25 16:27:40 +00:00
|
|
|
if (CakeLog::stream('stderr')) {
|
|
|
|
CakeLog::enable('stderr');
|
|
|
|
}
|
2012-05-09 05:03:51 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
$result = file_get_contents(LOGS . 'error.log');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Error: Testing LogError\(\) basic function/', $result);
|
|
|
|
$this->assertNotRegExp("/Error: Testing with\nmulti-line\nstring/", $result);
|
|
|
|
$this->assertRegExp('/Error: Testing with multi-line string/', $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
/**
|
|
|
|
* test fileExistsInPath()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testFileExistsInPath() {
|
2011-11-16 18:07:53 +00:00
|
|
|
if (!function_exists('ini_set')) {
|
|
|
|
$this->markTestSkipped('%s ini_set function not available');
|
|
|
|
}
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$_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);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(fileExistsInPath('file1.php'), $file1);
|
|
|
|
$this->assertEquals(fileExistsInPath('file2.php'), $file2);
|
|
|
|
$this->assertEquals(fileExistsInPath('folder1' . DS . 'file2.php'), $file2);
|
|
|
|
$this->assertEquals(fileExistsInPath($file2), $file2);
|
|
|
|
$this->assertEquals(fileExistsInPath('file3.php'), $file3);
|
|
|
|
$this->assertEquals(fileExistsInPath($file4), $file4);
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$this->assertFalse(fileExistsInPath('file1'));
|
|
|
|
$this->assertFalse(fileExistsInPath('file4.php'));
|
|
|
|
|
|
|
|
$Folder = new Folder($path);
|
|
|
|
$Folder->delete();
|
|
|
|
|
|
|
|
ini_set('include_path', $_includePath);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 01:11:09 +00:00
|
|
|
/**
|
|
|
|
* test convertSlash()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testConvertSlash() {
|
2008-10-16 01:11:09 +00:00
|
|
|
$result = convertSlash('\path\to\location\\');
|
|
|
|
$expected = '\path\to\location\\';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
|
|
|
|
$result = convertSlash('/path/to/location/');
|
|
|
|
$expected = 'path_to_location';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-10-16 01:11:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
/**
|
|
|
|
* test debug()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDebug() {
|
2009-03-11 23:46:10 +00:00
|
|
|
ob_start();
|
2012-03-11 04:12:08 +00:00
|
|
|
debug('this-is-a-test', false);
|
2009-03-11 23:46:10 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expectedText = <<<EXPECTED
|
2011-11-05 09:24:46 +00:00
|
|
|
%s (line %d)
|
|
|
|
########## DEBUG ##########
|
2011-11-17 02:31:16 +00:00
|
|
|
'this-is-a-test'
|
2011-11-05 09:24:46 +00:00
|
|
|
###########################
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
|
|
|
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-11 04:12:08 +00:00
|
|
|
debug('<div>this-is-a-test</div>', true);
|
2009-03-11 23:46:10 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expectedHtml = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
<div class="cake-debug-output">
|
|
|
|
<span><strong>%s</strong> (line <strong>%d</strong>)</span>
|
|
|
|
<pre class="cake-debug">
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', true, true);
|
2011-11-04 18:43:43 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expected = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
<div class="cake-debug-output">
|
|
|
|
<span><strong>%s</strong> (line <strong>%d</strong>)</span>
|
|
|
|
<pre class="cake-debug">
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', true, false);
|
2011-11-04 18:43:43 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expected = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
<div class="cake-debug-output">
|
|
|
|
|
|
|
|
<pre class="cake-debug">
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', null);
|
2011-11-04 18:43:43 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expectedHtml = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
<div class="cake-debug-output">
|
|
|
|
<span><strong>%s</strong> (line <strong>%d</strong>)</span>
|
|
|
|
<pre class="cake-debug">
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
EXPECTED;
|
2012-03-18 22:06:10 +00:00
|
|
|
$expectedText = <<<EXPECTED
|
2011-11-05 09:24:46 +00:00
|
|
|
%s (line %d)
|
|
|
|
########## DEBUG ##########
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-05 09:24:46 +00:00
|
|
|
###########################
|
|
|
|
EXPECTED;
|
|
|
|
if (php_sapi_name() == 'cli') {
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
|
2011-11-05 09:24:46 +00:00
|
|
|
} else {
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
|
2011-11-05 09:24:46 +00:00
|
|
|
}
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', null, false);
|
2011-11-04 18:43:43 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expectedHtml = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
<div class="cake-debug-output">
|
|
|
|
|
|
|
|
<pre class="cake-debug">
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
EXPECTED;
|
2012-03-18 22:06:10 +00:00
|
|
|
$expectedText = <<<EXPECTED
|
2011-11-05 09:24:46 +00:00
|
|
|
|
|
|
|
########## DEBUG ##########
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-05 09:24:46 +00:00
|
|
|
###########################
|
|
|
|
EXPECTED;
|
|
|
|
if (php_sapi_name() == 'cli') {
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
|
2011-11-05 09:24:46 +00:00
|
|
|
} else {
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
|
2011-11-05 09:24:46 +00:00
|
|
|
}
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-12-10 04:39:50 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', false);
|
2010-12-10 04:39:50 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expected = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
%s (line %d)
|
|
|
|
########## DEBUG ##########
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
###########################
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', false, true);
|
2011-11-04 18:43:43 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expected = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
%s (line %d)
|
|
|
|
########## DEBUG ##########
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
###########################
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
debug('<div>this-is-a-test</div>', false, false);
|
2011-11-04 18:43:43 +00:00
|
|
|
$result = ob_get_clean();
|
2012-03-18 22:06:10 +00:00
|
|
|
$expected = <<<EXPECTED
|
2011-11-04 18:43:43 +00:00
|
|
|
|
|
|
|
########## DEBUG ##########
|
2011-11-17 02:31:16 +00:00
|
|
|
'<div>this-is-a-test</div>'
|
2011-11-04 18:43:43 +00:00
|
|
|
###########################
|
|
|
|
EXPECTED;
|
2012-05-28 03:19:44 +00:00
|
|
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-11 23:46:10 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
/**
|
|
|
|
* test pr()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testPr() {
|
2009-03-11 23:46:10 +00:00
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
pr('this is a test');
|
2009-03-11 23:46:10 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "<pre>this is a test</pre>";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
ob_start();
|
2012-03-18 22:06:10 +00:00
|
|
|
pr(array('this' => 'is', 'a' => 'test'));
|
2009-03-11 23:46:10 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "<pre>Array\n(\n [this] => is\n [a] => test\n)\n</pre>";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-11 23:46:10 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
/**
|
|
|
|
* test stripslashes_deep()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testStripslashesDeep() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(ini_get('magic_quotes_sybase') === '1', 'magic_quotes_sybase is on.');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(stripslashes_deep("tes\'t"), "tes't");
|
2012-03-11 04:12:08 +00:00
|
|
|
$this->assertEquals(stripslashes_deep('tes\\' . chr(0) . 't'), 'tes' . chr(0) . 't');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(stripslashes_deep('tes\"t'), 'tes"t');
|
|
|
|
$this->assertEquals(stripslashes_deep("tes\'t"), "tes't");
|
|
|
|
$this->assertEquals(stripslashes_deep('te\\st'), 'test');
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$nested = array(
|
|
|
|
'a' => "tes\'t",
|
2012-03-11 04:12:08 +00:00
|
|
|
'b' => 'tes\\' . chr(0) . 't',
|
2009-03-11 23:46:10 +00:00
|
|
|
'c' => array(
|
|
|
|
'd' => 'tes\"t',
|
|
|
|
'e' => "te\'s\'t",
|
|
|
|
array('f' => "tes\'t")
|
|
|
|
),
|
|
|
|
'g' => 'te\\st'
|
2012-03-11 04:12:08 +00:00
|
|
|
);
|
2009-03-11 23:46:10 +00:00
|
|
|
$expected = array(
|
|
|
|
'a' => "tes't",
|
2012-03-11 04:12:08 +00:00
|
|
|
'b' => 'tes' . chr(0) . 't',
|
2009-03-11 23:46:10 +00:00
|
|
|
'c' => array(
|
|
|
|
'd' => 'tes"t',
|
|
|
|
'e' => "te's't",
|
|
|
|
array('f' => "tes't")
|
|
|
|
),
|
|
|
|
'g' => 'test'
|
2012-03-11 04:12:08 +00:00
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, stripslashes_deep($nested));
|
2009-03-11 23:46:10 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-11 23:46:10 +00:00
|
|
|
/**
|
|
|
|
* test stripslashes_deep() with magic_quotes_sybase on
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testStripslashesDeepSybase() {
|
2011-11-16 18:07:53 +00:00
|
|
|
if (!(ini_get('magic_quotes_sybase') === '1')) {
|
|
|
|
$this->markTestSkipped('magic_quotes_sybase is off');
|
|
|
|
}
|
2009-03-11 23:46:10 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(stripslashes_deep("tes\'t"), "tes\'t");
|
2009-03-11 23:46:10 +00:00
|
|
|
|
|
|
|
$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"
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, stripslashes_deep($nested));
|
2009-03-11 23:46:10 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-11-15 23:16:12 +00:00
|
|
|
/**
|
|
|
|
* test pluginSplit
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginSplit() {
|
2009-11-15 23:16:12 +00:00
|
|
|
$result = pluginSplit('Something.else');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Something', 'else'), $result);
|
2009-11-16 00:54:33 +00:00
|
|
|
|
2009-11-16 00:12:00 +00:00
|
|
|
$result = pluginSplit('Something.else.more.dots');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Something', 'else.more.dots'), $result);
|
2009-11-15 23:16:12 +00:00
|
|
|
|
|
|
|
$result = pluginSplit('Somethingelse');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(null, 'Somethingelse'), $result);
|
2009-11-16 00:54:33 +00:00
|
|
|
|
2009-11-16 00:12:00 +00:00
|
|
|
$result = pluginSplit('Something.else', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Something.', 'else'), $result);
|
2009-11-16 00:54:33 +00:00
|
|
|
|
2009-11-16 00:12:00 +00:00
|
|
|
$result = pluginSplit('Something.else.more.dots', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Something.', 'else.more.dots'), $result);
|
2009-11-16 00:54:33 +00:00
|
|
|
|
|
|
|
$result = pluginSplit('Post', false, 'Blog');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Blog', 'Post'), $result);
|
2009-11-16 00:54:33 +00:00
|
|
|
|
|
|
|
$result = pluginSplit('Blog.Post', false, 'Ultimate');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Blog', 'Post'), $result);
|
2009-11-15 23:16:12 +00:00
|
|
|
}
|
2008-09-29 18:01:52 +00:00
|
|
|
}
|