| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084 |
- <?php
- /**
- * BasicsTest file
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since 1.2.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase;
- use Cake\Cache\Cache;
- use Cake\Core\App;
- use Cake\Core\Configure;
- use Cake\Log\Log;
- use Cake\Network\Response;
- use Cake\TestSuite\TestCase;
- use Cake\Utility\Folder;
- require_once CAKE . 'basics.php';
- /**
- * BasicsTest class
- */
- class BasicsTest extends TestCase {
- /**
- * test the array_diff_key compatibility function.
- *
- * @return void
- */
- 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->assertEquals($expected, $result);
- $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->assertEquals($expected, $result);
- $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->assertEquals($expected, $result);
- $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->assertSame(array(), $result);
- }
- /**
- * testHttpBase method
- *
- * @return void
- */
- public function testEnv() {
- $this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', 'Safe mode is on.');
- $server = $_SERVER;
- $env = $_ENV;
- $_SERVER['HTTP_HOST'] = 'localhost';
- $this->assertEquals(env('HTTP_BASE'), '.localhost');
- $_SERVER['HTTP_HOST'] = 'com.ar';
- $this->assertEquals(env('HTTP_BASE'), '.com.ar');
- $_SERVER['HTTP_HOST'] = 'example.ar';
- $this->assertEquals(env('HTTP_BASE'), '.example.ar');
- $_SERVER['HTTP_HOST'] = 'example.com';
- $this->assertEquals(env('HTTP_BASE'), '.example.com');
- $_SERVER['HTTP_HOST'] = 'www.example.com';
- $this->assertEquals(env('HTTP_BASE'), '.example.com');
- $_SERVER['HTTP_HOST'] = 'subdomain.example.com';
- $this->assertEquals(env('HTTP_BASE'), '.example.com');
- $_SERVER['HTTP_HOST'] = 'example.com.ar';
- $this->assertEquals(env('HTTP_BASE'), '.example.com.ar');
- $_SERVER['HTTP_HOST'] = 'www.example.com.ar';
- $this->assertEquals(env('HTTP_BASE'), '.example.com.ar');
- $_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
- $this->assertEquals(env('HTTP_BASE'), '.example.com.ar');
- $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
- $this->assertEquals(env('HTTP_BASE'), '.subdomain.example.com');
- $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
- $this->assertEquals(env('HTTP_BASE'), '.subdomain.example.com.ar');
- $_SERVER = $_ENV = array();
- $_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
- $this->assertEquals(env('SCRIPT_NAME'), '/a/test/test.php');
- $_SERVER = $_ENV = array();
- $_ENV['CGI_MODE'] = 'BINARY';
- $_ENV['SCRIPT_URL'] = '/a/test/test.php';
- $this->assertEquals(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->assertNull(env('TEST_ME'));
- $_ENV['TEST_ME'] = 'a';
- $this->assertEquals(env('TEST_ME'), 'a');
- $_SERVER['TEST_ME'] = 'b';
- $this->assertEquals(env('TEST_ME'), 'b');
- unset($_ENV['TEST_ME']);
- $this->assertEquals(env('TEST_ME'), 'b');
- $_SERVER = $server;
- $_ENV = $env;
- }
- /**
- * Test h()
- *
- * @return void
- */
- public function testH() {
- $string = '<foo>';
- $result = h($string);
- $this->assertEquals('<foo>', $result);
- $in = array('this & that', '<p>Which one</p>');
- $result = h($in);
- $expected = array('this & that', '<p>Which one</p>');
- $this->assertEquals($expected, $result);
- $string = '<foo> & ';
- $result = h($string);
- $this->assertEquals('<foo> & &nbsp;', $result);
- $string = '<foo> & ';
- $result = h($string, false);
- $this->assertEquals('<foo> & ', $result);
- $string = '<foo> & ';
- $result = h($string, 'UTF-8');
- $this->assertEquals('<foo> & &nbsp;', $result);
- $string = "An invalid\x80string";
- $result = h($string);
- $this->assertContains('string', $result);
- $arr = array('<foo>', ' ');
- $result = h($arr);
- $expected = array(
- '<foo>',
- '&nbsp;'
- );
- $this->assertEquals($expected, $result);
- $arr = array('<foo>', ' ');
- $result = h($arr, false);
- $expected = array(
- '<foo>',
- ' '
- );
- $this->assertEquals($expected, $result);
- $arr = array('f' => '<foo>', 'n' => ' ');
- $result = h($arr, false);
- $expected = array(
- 'f' => '<foo>',
- 'n' => ' '
- );
- $this->assertEquals($expected, $result);
- $arr = array('invalid' => "\x99An invalid\x80string", 'good' => 'Good string');
- $result = h($arr);
- $this->assertContains('An invalid', $result['invalid']);
- $this->assertEquals('Good string', $result['good']);
- // Test that boolean values are not converted to strings
- $result = h(false);
- $this->assertFalse($result);
- $arr = array('foo' => false, 'bar' => true);
- $result = h($arr);
- $this->assertFalse($result['foo']);
- $this->assertTrue($result['bar']);
- $obj = new \stdClass();
- $result = h($obj);
- $this->assertEquals('(object)stdClass', $result);
- $obj = new Response(array('body' => 'Body content'));
- $result = h($obj);
- $this->assertEquals('Body content', $result);
- }
- /**
- * Test am()
- *
- * @return void
- */
- public function testAm() {
- $result = am(array('one', 'two'), 2, 3, 4);
- $expected = array('one', 'two', 2, 3, 4);
- $this->assertEquals($expected, $result);
- $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->assertEquals($expected, $result);
- }
- /**
- * test cache()
- *
- * @return void
- */
- public function testCache() {
- Cache::disable();
- $result = cache('basics_test', 'simple cache write');
- $this->assertNull($result);
- $result = cache('basics_test');
- $this->assertNull($result);
- Cache::enable();
- $result = cache('basics_test', 'simple cache write');
- $this->assertTrue((bool)$result);
- $this->assertTrue(file_exists(CACHE . 'basics_test'));
- $result = cache('basics_test');
- $this->assertEquals('simple cache write', $result);
- if (file_exists(CACHE . 'basics_test')) {
- unlink(CACHE . 'basics_test');
- }
- cache('basics_test', 'expired', '+1 second');
- sleep(2);
- $result = cache('basics_test', null, '+1 second');
- $this->assertNull($result);
- }
- /**
- * test clearCache()
- *
- * @return void
- */
- public function testClearCache() {
- $cacheOff = Configure::read('Cache.disable');
- $this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests.');
- cache('views/basics_test.cache', 'simple cache write');
- $this->assertTrue(file_exists(CACHE . 'views/basics_test.cache'));
- cache('views/basics_test_2.cache', 'simple cache write 2');
- $this->assertTrue(file_exists(CACHE . 'views/basics_test_2.cache'));
- cache('views/basics_test_3.cache', 'simple cache write 3');
- $this->assertTrue(file_exists(CACHE . 'views/basics_test_3.cache'));
- $result = clearCache(array('basics_test', 'basics_test_2'), 'views', '.cache');
- $this->assertTrue($result);
- $this->assertFalse(file_exists(CACHE . 'views/basics_test.cache'));
- $this->assertFalse(file_exists(CACHE . 'views/basics_test.cache'));
- $this->assertTrue(file_exists(CACHE . 'views/basics_test_3.cache'));
- $result = clearCache(null, 'views', '.cache');
- $this->assertTrue($result);
- $this->assertFalse(file_exists(CACHE . 'views/basics_test_3.cache'));
- // Different path from views and with prefix
- cache('models/basics_test.cache', 'simple cache write');
- $this->assertTrue(file_exists(CACHE . 'models/basics_test.cache'));
- cache('models/basics_test_2.cache', 'simple cache write 2');
- $this->assertTrue(file_exists(CACHE . 'models/basics_test_2.cache'));
- cache('models/basics_test_3.cache', 'simple cache write 3');
- $this->assertTrue(file_exists(CACHE . 'models/basics_test_3.cache'));
- $result = clearCache('basics', 'models', '.cache');
- $this->assertTrue($result);
- $this->assertFalse(file_exists(CACHE . 'models/basics_test.cache'));
- $this->assertFalse(file_exists(CACHE . 'models/basics_test_2.cache'));
- $this->assertFalse(file_exists(CACHE . 'models/basics_test_3.cache'));
- // checking if empty files were not removed
- $emptyExists = file_exists(CACHE . 'views/empty');
- if (!$emptyExists) {
- cache('views/empty', '');
- }
- cache('views/basics_test.php', 'simple cache write');
- $this->assertTrue(file_exists(CACHE . 'views/basics_test.php'));
- $this->assertTrue(file_exists(CACHE . 'views/empty'));
- $result = clearCache();
- $this->assertTrue($result);
- $this->assertTrue(file_exists(CACHE . 'views/empty'));
- $this->assertFalse(file_exists(CACHE . 'views/basics_test.php'));
- if (!$emptyExists) {
- unlink(CACHE . 'views/empty');
- }
- }
- /**
- * test __()
- *
- * @return void
- */
- public function testTranslate() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __('Plural Rule 1');
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __('Plural Rule 1 (from core)');
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __('Some string with %s', 'arguments');
- $expected = 'Some string with arguments';
- $this->assertEquals($expected, $result);
- $result = __('Some string with %s %s', 'multiple', 'arguments');
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- $result = __('Some string with %s %s', array('multiple', 'arguments'));
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- $result = __('Testing %2$s %1$s', 'order', 'different');
- $expected = 'Testing different order';
- $this->assertEquals($expected, $result);
- $result = __('Testing %2$s %1$s', array('order', 'different'));
- $expected = 'Testing different order';
- $this->assertEquals($expected, $result);
- $result = __('Testing %.2f number', 1.2345);
- $expected = 'Testing 1.23 number';
- $this->assertEquals($expected, $result);
- }
- /**
- * testTranslatePercent
- *
- * @return void
- */
- public function testTranslatePercent() {
- $result = __('%s are 100% real fruit', 'Apples');
- $expected = 'Apples are 100% real fruit';
- $this->assertEquals($expected, $result, 'Percent sign at end of word should be considered literal');
- $result = __('%s are %d% real fruit', 'Apples', 100);
- $expected = 'Apples are 100% real fruit';
- $this->assertEquals($expected, $result, 'A digit marker should not be misinterpreted');
- $result = __('%s are %s% real fruit', 'Apples', 100);
- $expected = 'Apples are 100% real fruit';
- $this->assertEquals($expected, $result, 'A string marker should not be misinterpreted');
- $result = __('%nonsense %s', 'Apples');
- $expected = '%nonsense Apples';
- $this->assertEquals($expected, $result, 'A percent sign at the start of the string should be considered literal');
- $result = __('%s are awesome%', 'Apples');
- $expected = 'Apples are awesome%';
- $this->assertEquals($expected, $result, 'A percent sign at the end of the string should be considered literal');
- $result = __('%2$d %1$s entered the bowl', 'Apples', 2);
- $expected = '2 Apples entered the bowl';
- $this->assertEquals($expected, $result, 'Positional replacement markers should not be misinterpreted');
- $result = __('%.2f% of all %s agree', 99.44444, 'Cats');
- $expected = '99.44% of all Cats agree';
- $this->assertEquals($expected, $result, 'significant-digit placeholder should not be misinterpreted');
- }
- /**
- * testTranslateWithFormatSpecifiers
- *
- * @return void
- */
- public function testTranslateWithFormatSpecifiers() {
- $expected = 'Check, one, two, three';
- $result = __('Check, %+10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, +1, two, three';
- $result = __('Check, %+5d, two, three', 1);
- $this->assertEquals($expected, $result);
- $expected = 'Check, @@one, two, three';
- $result = __('Check, %\'@+10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, one, two , three';
- $result = __('Check, %-10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, one, two##, three';
- $result = __('Check, %\'#-10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, one, two, three';
- $result = __d('default', 'Check, %+10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, @@one, two, three';
- $result = __d('default', 'Check, %\'@+10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, one, two , three';
- $result = __d('default', 'Check, %-10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- $expected = 'Check, one, two##, three';
- $result = __d('default', 'Check, %\'#-10s, three', 'one, two');
- $this->assertEquals($expected, $result);
- }
- /**
- * testTranslateDomainPluralWithFormatSpecifiers
- *
- * @return void
- */
- public function testTranslateDomainPluralWithFormatSpecifiers() {
- $result = __dn('core', '%+5d item.', '%+5d items.', 1, 1);
- $expected = ' +1 item.';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%-5d item.', '%-5d items.', 10, 10);
- $expected = '10 items.';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 1, 1);
- $expected = '###+1 item.';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 90, 90);
- $expected = '**+90 items.';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 9000, 9000);
- $expected = '+9000 items.';
- $this->assertEquals($expected, $result);
- }
- /**
- * test testTranslatePluralWithFormatSpecifiers
- *
- * @return void
- */
- public function testTranslatePluralWithFormatSpecifiers() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __n('%-5d = 1', '%-5d = 0 or > 1', 10);
- $expected = '%-5d = 0 or > 1 (translated)';
- $this->assertEquals($expected, $result);
- }
- /**
- * test testTranslateDomainCategoryWithFormatSpecifiers
- *
- * @return void
- */
- public function testTranslateDomainCategoryWithFormatSpecifiers() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __dc('default', '%+10s world', 6, 'hello');
- $expected = ' hello world';
- $this->assertEquals($expected, $result);
- $result = __dc('default', '%-10s world', 6, 'hello');
- $expected = 'hello world';
- $this->assertEquals($expected, $result);
- $result = __dc('default', '%\'@-10s world', 6, 'hello');
- $expected = 'hello@@@@@ world';
- $this->assertEquals($expected, $result);
- }
- /**
- * test testTranslateDomainCategoryPluralWithFormatSpecifiers
- *
- * @return void
- */
- public function testTranslateDomainCategoryPluralWithFormatSpecifiers() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __dcn('default', '%-5d = 1', '%-5d = 0 or > 1', 0, 6);
- $expected = '%-5d = 0 or > 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __dcn('default', '%-5d = 1', '%-5d = 0 or > 1', 1, 6);
- $expected = '%-5d = 1 (translated)';
- $this->assertEquals($expected, $result);
- }
- /**
- * test testTranslateCategoryWithFormatSpecifiers
- *
- * @return void
- */
- public function testTranslateCategoryWithFormatSpecifiers() {
- $result = __c('Some string with %+10s', 6, 'arguments');
- $expected = 'Some string with arguments';
- $this->assertEquals($expected, $result);
- $result = __c('Some string with %-10s: args', 6, 'arguments');
- $expected = 'Some string with arguments : args';
- $this->assertEquals($expected, $result);
- $result = __c('Some string with %\'*-10s: args', 6, 'arguments');
- $expected = 'Some string with arguments*: args';
- $this->assertEquals($expected, $result);
- }
- /**
- * test __n()
- *
- * @return void
- */
- public function testTranslatePlural() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __n('%d = 1', '%d = 0 or > 1', 0);
- $expected = '%d = 0 or > 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __n('%d = 1', '%d = 0 or > 1', 1);
- $expected = '%d = 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', 2);
- $expected = '%d = 0 or > 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __n('%d item.', '%d items.', 1, 1);
- $expected = '1 item.';
- $this->assertEquals($expected, $result);
- $result = __n('%d item for id %s', '%d items for id %s', 2, 2, '1234');
- $expected = '2 items for id 1234';
- $this->assertEquals($expected, $result);
- $result = __n('%d item for id %s', '%d items for id %s', 2, array(2, '1234'));
- $expected = '2 items for id 1234';
- $this->assertEquals($expected, $result);
- }
- /**
- * test __d()
- *
- * @return void
- */
- public function testTranslateDomain() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __d('default', 'Plural Rule 1');
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __d('core', 'Plural Rule 1');
- $expected = 'Plural Rule 1';
- $this->assertEquals($expected, $result);
- $result = __d('core', 'Plural Rule 1 (from core)');
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __d('core', 'Some string with %s', 'arguments');
- $expected = 'Some string with arguments';
- $this->assertEquals($expected, $result);
- $result = __d('core', 'Some string with %s %s', 'multiple', 'arguments');
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- $result = __d('core', 'Some string with %s %s', array('multiple', 'arguments'));
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- }
- /**
- * test __dn()
- *
- * @return void
- */
- public function testTranslateDomainPlural() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __dn('default', '%d = 1', '%d = 0 or > 1', 0);
- $expected = '%d = 0 or > 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%d = 1', '%d = 0 or > 1', 0);
- $expected = '%d = 0 or > 1';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 0);
- $expected = '%d = 0 or > 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __dn('default', '%d = 1', '%d = 0 or > 1', 1);
- $expected = '%d = 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%d item.', '%d items.', 1, 1);
- $expected = '1 item.';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%d item for id %s', '%d items for id %s', 2, 2, '1234');
- $expected = '2 items for id 1234';
- $this->assertEquals($expected, $result);
- $result = __dn('core', '%d item for id %s', '%d items for id %s', 2, array(2, '1234'));
- $expected = '2 items for id 1234';
- $this->assertEquals($expected, $result);
- }
- /**
- * test __c()
- *
- * @return void
- */
- public function testTranslateCategory() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __c('Plural Rule 1', 6);
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __c('Plural Rule 1 (from core)', 6);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __c('Some string with %s', 6, 'arguments');
- $expected = 'Some string with arguments';
- $this->assertEquals($expected, $result);
- $result = __c('Some string with %s %s', 6, 'multiple', 'arguments');
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- $result = __c('Some string with %s %s', 6, array('multiple', 'arguments'));
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- }
- /**
- * test __dc()
- *
- * @return void
- */
- public function testTranslateDomainCategory() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __dc('default', 'Plural Rule 1', 6);
- $expected = 'Plural Rule 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __dc('default', 'Plural Rule 1 (from core)', 6);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __dc('core', 'Plural Rule 1', 6);
- $expected = 'Plural Rule 1';
- $this->assertEquals($expected, $result);
- $result = __dc('core', 'Plural Rule 1 (from core)', 6);
- $expected = 'Plural Rule 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __dc('core', 'Some string with %s', 6, 'arguments');
- $expected = 'Some string with arguments';
- $this->assertEquals($expected, $result);
- $result = __dc('core', 'Some string with %s %s', 6, 'multiple', 'arguments');
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- $result = __dc('core', 'Some string with %s %s', 6, array('multiple', 'arguments'));
- $expected = 'Some string with multiple arguments';
- $this->assertEquals($expected, $result);
- }
- /**
- * test __dcn()
- *
- * @return void
- */
- public function testTranslateDomainCategoryPlural() {
- Configure::write('Config.language', 'rule_1_po');
- $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6);
- $expected = '%d = 0 or > 1 (translated)';
- $this->assertEquals($expected, $result);
- $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6);
- $expected = '%d = 1 (from core translated)';
- $this->assertEquals($expected, $result);
- $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6);
- $expected = '%d = 0 or > 1';
- $this->assertEquals($expected, $result);
- $result = __dcn('core', '%d item.', '%d items.', 1, 6, 1);
- $expected = '1 item.';
- $this->assertEquals($expected, $result);
- $result = __dcn('core', '%d item for id %s', '%d items for id %s', 2, 6, 2, '1234');
- $expected = '2 items for id 1234';
- $this->assertEquals($expected, $result);
- $result = __dcn('core', '%d item for id %s', '%d items for id %s', 2, 6, array(2, '1234'));
- $expected = '2 items for id 1234';
- $this->assertEquals($expected, $result);
- }
- /**
- * test fileExistsInPath()
- *
- * @return void
- */
- public function testFileExistsInPath() {
- if (!function_exists('ini_set')) {
- $this->markTestSkipped('%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->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);
- $this->assertFalse(fileExistsInPath('file1'));
- $this->assertFalse(fileExistsInPath('file4.php'));
- $Folder = new Folder($path);
- $Folder->delete();
- ini_set('include_path', $_includePath);
- }
- /**
- * test convertSlash()
- *
- * @return void
- */
- public function testConvertSlash() {
- $result = convertSlash('\path\to\location\\');
- $expected = '\path\to\location\\';
- $this->assertEquals($expected, $result);
- $result = convertSlash('/path/to/location/');
- $expected = 'path_to_location';
- $this->assertEquals($expected, $result);
- }
- /**
- * test debug()
- *
- * @return void
- */
- public function testDebug() {
- ob_start();
- debug('this-is-a-test', false);
- $result = ob_get_clean();
- $expectedText = <<<EXPECTED
- %s (line %d)
- ########## DEBUG ##########
- 'this-is-a-test'
- ###########################
- EXPECTED;
- $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', true);
- $result = ob_get_clean();
- $expectedHtml = <<<EXPECTED
- <div class="cake-debug-output">
- <span><strong>%s</strong> (line <strong>%d</strong>)</span>
- <pre class="cake-debug">
- '<div>this-is-a-test</div>'
- </pre>
- </div>
- EXPECTED;
- $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', true, true);
- $result = ob_get_clean();
- $expected = <<<EXPECTED
- <div class="cake-debug-output">
- <span><strong>%s</strong> (line <strong>%d</strong>)</span>
- <pre class="cake-debug">
- '<div>this-is-a-test</div>'
- </pre>
- </div>
- EXPECTED;
- $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', true, false);
- $result = ob_get_clean();
- $expected = <<<EXPECTED
- <div class="cake-debug-output">
- <pre class="cake-debug">
- '<div>this-is-a-test</div>'
- </pre>
- </div>
- EXPECTED;
- $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', null);
- $result = ob_get_clean();
- $expectedHtml = <<<EXPECTED
- <div class="cake-debug-output">
- <span><strong>%s</strong> (line <strong>%d</strong>)</span>
- <pre class="cake-debug">
- '<div>this-is-a-test</div>'
- </pre>
- </div>
- EXPECTED;
- $expectedText = <<<EXPECTED
- %s (line %d)
- ########## DEBUG ##########
- '<div>this-is-a-test</div>'
- ###########################
- EXPECTED;
- if (php_sapi_name() === 'cli') {
- $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 18);
- } else {
- $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
- }
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', null, false);
- $result = ob_get_clean();
- $expectedHtml = <<<EXPECTED
- <div class="cake-debug-output">
- <pre class="cake-debug">
- '<div>this-is-a-test</div>'
- </pre>
- </div>
- EXPECTED;
- $expectedText = <<<EXPECTED
- ########## DEBUG ##########
- '<div>this-is-a-test</div>'
- ###########################
- EXPECTED;
- if (php_sapi_name() === 'cli') {
- $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 18);
- } else {
- $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
- }
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', false);
- $result = ob_get_clean();
- $expected = <<<EXPECTED
- %s (line %d)
- ########## DEBUG ##########
- '<div>this-is-a-test</div>'
- ###########################
- EXPECTED;
- $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', false, true);
- $result = ob_get_clean();
- $expected = <<<EXPECTED
- %s (line %d)
- ########## DEBUG ##########
- '<div>this-is-a-test</div>'
- ###########################
- EXPECTED;
- $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
- $this->assertEquals($expected, $result);
- ob_start();
- debug('<div>this-is-a-test</div>', false, false);
- $result = ob_get_clean();
- $expected = <<<EXPECTED
- ########## DEBUG ##########
- '<div>this-is-a-test</div>'
- ###########################
- EXPECTED;
- $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
- $this->assertEquals($expected, $result);
- ob_start();
- debug(false, false, false);
- $result = ob_get_clean();
- $expected = <<<EXPECTED
- ########## DEBUG ##########
- false
- ###########################
- EXPECTED;
- $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
- $this->assertEquals($expected, $result);
- }
- /**
- * test pr()
- *
- * @return void
- */
- public function testPr() {
- $this->skipIf(php_sapi_name() === 'cli', 'Skipping web test in cli mode');
- ob_start();
- pr('this is a test');
- $result = ob_get_clean();
- $expected = "<pre>this is a test</pre>";
- $this->assertEquals($expected, $result);
- 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->assertEquals($expected, $result);
- }
- /**
- * test pr()
- *
- * @return void
- */
- public function testPrCli() {
- $this->skipIf(php_sapi_name() != 'cli', 'Skipping cli test in web mode');
- ob_start();
- pr('this is a test');
- $result = ob_get_clean();
- $expected = "\nthis is a test\n";
- $this->assertEquals($expected, $result);
- ob_start();
- pr(array('this' => 'is', 'a' => 'test'));
- $result = ob_get_clean();
- $expected = "\nArray\n(\n [this] => is\n [a] => test\n)\n\n";
- $this->assertEquals($expected, $result);
- }
- /**
- * test pluginSplit
- *
- * @return void
- */
- public function testPluginSplit() {
- $result = pluginSplit('Something.else');
- $this->assertEquals(array('Something', 'else'), $result);
- $result = pluginSplit('Something.else.more.dots');
- $this->assertEquals(array('Something', 'else.more.dots'), $result);
- $result = pluginSplit('Somethingelse');
- $this->assertEquals(array(null, 'Somethingelse'), $result);
- $result = pluginSplit('Something.else', true);
- $this->assertEquals(array('Something.', 'else'), $result);
- $result = pluginSplit('Something.else.more.dots', true);
- $this->assertEquals(array('Something.', 'else.more.dots'), $result);
- $result = pluginSplit('Post', false, 'Blog');
- $this->assertEquals(array('Blog', 'Post'), $result);
- $result = pluginSplit('Blog.Post', false, 'Ultimate');
- $this->assertEquals(array('Blog', 'Post'), $result);
- }
- /**
- * test namespaceSplit
- *
- * @return void
- */
- public function testNamespaceSplit() {
- $result = namespaceSplit('Something');
- $this->assertEquals(array('', 'Something'), $result);
- $result = namespaceSplit('\Something');
- $this->assertEquals(array('', 'Something'), $result);
- $result = namespaceSplit('Cake\Something');
- $this->assertEquals(array('Cake', 'Something'), $result);
- $result = namespaceSplit('Cake\Test\Something');
- $this->assertEquals(array('Cake\Test', 'Something'), $result);
- }
- }
|