From 773ce0260d692b61ceaa9ae14c35982d6c1dbbe2 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sat, 26 May 2012 17:34:00 -0400 Subject: [PATCH] Update test case Utility folder --- .../TestCase/Utility/ClassRegistryTest.php | 19 ++-- .../Test/TestCase/Utility/DebuggerTest.php | 46 ++++---- lib/Cake/Test/TestCase/Utility/FileTest.php | 12 +- lib/Cake/Test/TestCase/Utility/FolderTest.php | 14 ++- lib/Cake/Test/TestCase/Utility/HashTest.php | 6 +- .../Test/TestCase/Utility/InflectorTest.php | 11 +- .../{CakeNumberTest.php => NumberTest.php} | 15 +-- .../TestCase/Utility/ObjectCollectionTest.php | 37 +++--- .../Test/TestCase/Utility/SanitizeTest.php | 12 +- .../Test/TestCase/Utility/SecurityTest.php | 7 +- lib/Cake/Test/TestCase/Utility/SetTest.php | 105 +++++++++--------- lib/Cake/Test/TestCase/Utility/StringTest.php | 6 +- .../{CakeTimeTest.php => TimeTest.php} | 72 ++++++------ .../Test/TestCase/Utility/ValidationTest.php | 17 +-- lib/Cake/Test/TestCase/Utility/XmlTest.php | 33 +++--- 15 files changed, 226 insertions(+), 186 deletions(-) rename lib/Cake/Test/TestCase/Utility/{CakeNumberTest.php => NumberTest.php} (98%) rename lib/Cake/Test/TestCase/Utility/{CakeTimeTest.php => TimeTest.php} (94%) diff --git a/lib/Cake/Test/TestCase/Utility/ClassRegistryTest.php b/lib/Cake/Test/TestCase/Utility/ClassRegistryTest.php index eb20fceade8..689b5b8c7e4 100644 --- a/lib/Cake/Test/TestCase/Utility/ClassRegistryTest.php +++ b/lib/Cake/Test/TestCase/Utility/ClassRegistryTest.php @@ -16,14 +16,19 @@ * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('ClassRegistry', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\Fixture\TestModel, + Cake\TestSuite\TestCase, + Cake\Core\Plugin, + Cake\Model\ConnectionManager, + Cake\Utility\ClassRegistry; /** * ClassRegisterModel class * * @package Cake.Test.Case.Utility */ -class ClassRegisterModel extends CakeTestModel { +class ClassRegisterModel extends TestModel { /** * useTable property @@ -160,7 +165,7 @@ public function doSomething(); * * @package Cake.Test.Case.Utility */ -class ClassRegistryTest extends CakeTestCase { +class ClassRegistryTest extends TestCase { /** * testAddModel method @@ -285,7 +290,7 @@ public function testPluginAppModel() { $this->assertFalse($TestRegistryPluginModel); //Faking a plugin - CakePlugin::load('RegistryPlugin', array('path' => '/fake/path')); + Plugin::load('RegistryPlugin', array('path' => '/fake/path')); $TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel'); $this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel')); @@ -297,7 +302,7 @@ public function testPluginAppModel() { $PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser'); $this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel')); $this->assertSame($PluginUser, $PluginUserCopy); - CakePlugin::unload(); + Plugin::unload(); } /** @@ -330,7 +335,7 @@ public function testInitStrict() { /** * Test that you cannot init() an abstract class. An exception will be raised. * - * @expectedException CakeException + * @expectedException Cake\Error\Exception * @return void */ public function testInitAbstractClass() { @@ -340,7 +345,7 @@ public function testInitAbstractClass() { /** * Test that you cannot init() an abstract class. A exception will be raised. * - * @expectedException CakeException + * @expectedException Cake\Error\Exception * @return void */ public function testInitInterface() { diff --git a/lib/Cake/Test/TestCase/Utility/DebuggerTest.php b/lib/Cake/Test/TestCase/Utility/DebuggerTest.php index f45f19cdcde..03f788e4660 100644 --- a/lib/Cake/Test/TestCase/Utility/DebuggerTest.php +++ b/lib/Cake/Test/TestCase/Utility/DebuggerTest.php @@ -16,7 +16,12 @@ * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Debugger', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\Utility\Debugger, + Cake\TestSuite\TestCase, + Cake\Core\Configure, + Cake\Controller\Controller, + Cake\View\View; /** * DebugggerTestCaseDebuggger class @@ -34,7 +39,7 @@ class DebuggerTestCaseDebugger extends Debugger { * * @package Cake.Test.Case.Utility */ -class DebuggerTest extends CakeTestCase { +class DebuggerTest extends TestCase { protected $_restoreError = false; @@ -102,7 +107,7 @@ public function testExcerpt() { * @return void */ public function testOutput() { - set_error_handler('Debugger::showError'); + set_error_handler('Cake\Utility\Debugger::showError'); $this->_restoreError = true; $result = Debugger::output(false); @@ -158,7 +163,7 @@ public function testOutput() { * @return void */ public function testChangeOutputFormats() { - set_error_handler('Debugger::showError'); + set_error_handler('Cake\Utility\Debugger::showError'); $this->_restoreError = true; Debugger::output('js', array( @@ -204,7 +209,7 @@ public function testOutputAs() { /** * Test that choosing a non-existent format causes an exception * - * @expectedException CakeException + * @expectedException Cake\Error\Exception * @return void */ public function testOutputAsException() { @@ -217,7 +222,7 @@ public function testOutputAsException() { * @return void */ public function testAddFormat() { - set_error_handler('Debugger::showError'); + set_error_handler('Cake\Utility\Debugger::showError'); $this->_restoreError = true; Debugger::addFormat('js', array( @@ -256,7 +261,7 @@ public function testAddFormat() { * @return void */ public function testAddFormatCallback() { - set_error_handler('Debugger::showError'); + set_error_handler('Cake\Utility\Debugger::showError'); $this->_restoreError = true; Debugger::addFormat('callback', array('callback' => array($this, 'customFormat'))); @@ -292,7 +297,6 @@ public function testTrimPath() { * @return void */ public function testExportVar() { - App::uses('Controller', 'Controller'); $Controller = new Controller(); $Controller->helpers = array('Html', 'Form'); $View = new View($Controller); @@ -301,9 +305,9 @@ public function testExportVar() { $result = Debugger::exportVar($View); $expected = << object(HelperCollection) {} - Blocks => object(ViewBlock) {} +object(Cake\View\View) { + Helpers => object(Cake\View\HelperCollection) {} + Blocks => object(Cake\View\ViewBlock) {} plugin => null name => '' passedArgs => array() @@ -325,7 +329,7 @@ public function testExportVar() { hasRendered => false uuids => array() request => null - response => object(CakeResponse) {} + response => object(Cake\Network\Response) {} elementCache => 'default' int => (int) 2 float => (float) 1.333 @@ -414,16 +418,16 @@ public function testDump() { */ public function testGetInstance() { $result = Debugger::getInstance(); - $this->assertInstanceOf('Debugger', $result); + $this->assertInstanceOf('Cake\Utility\Debugger', $result); - $result = Debugger::getInstance('DebuggerTestCaseDebugger'); - $this->assertInstanceOf('DebuggerTestCaseDebugger', $result); + $result = Debugger::getInstance(__NAMESPACE__ . '\DebuggerTestCaseDebugger'); + $this->assertInstanceOf(__NAMESPACE__ . '\DebuggerTestCaseDebugger', $result); $result = Debugger::getInstance(); - $this->assertInstanceOf('DebuggerTestCaseDebugger', $result); + $this->assertInstanceOf(__NAMESPACE__ . '\DebuggerTestCaseDebugger', $result); - $result = Debugger::getInstance('Debugger'); - $this->assertInstanceOf('Debugger', $result); + $result = Debugger::getInstance('Cake\Utility\Debugger'); + $this->assertInstanceOf('Cake\Utility\Debugger', $result); } /** @@ -468,11 +472,11 @@ public function testNoDbCredentials() { */ public function testTraceExclude() { $result = Debugger::trace(); - $this->assertRegExp('/^DebuggerTest::testTraceExclude/', $result); + $this->assertRegExp('/^Cake\\\Test\\\TestCase\\\Utility\\\DebuggerTest::testTraceExclude/', $result); $result = Debugger::trace(array( - 'exclude' => array('DebuggerTest::testTraceExclude') + 'exclude' => array('Cake\Test\TestCase\Utility\DebuggerTest::testTraceExclude') )); - $this->assertNotRegExp('/^DebuggerTest::testTraceExclude/', $result); + $this->assertNotRegExp('/^Cake\\\Test\\\TestCase\\\Utility\\\DebuggerTest::testTraceExclude/', $result); } } diff --git a/lib/Cake/Test/TestCase/Utility/FileTest.php b/lib/Cake/Test/TestCase/Utility/FileTest.php index e63bcbd9f49..0e93156c3b1 100644 --- a/lib/Cake/Test/TestCase/Utility/FileTest.php +++ b/lib/Cake/Test/TestCase/Utility/FileTest.php @@ -16,15 +16,17 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('File', 'Utility'); -App::uses('Folder', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Utility\File, + Cake\Utility\Folder; /** * FileTest class * * @package Cake.Test.Case.Utility */ -class FileTest extends CakeTestCase { +class FileTest extends TestCase { /** * File property @@ -119,7 +121,7 @@ function_exists('mime_content_type') && false === mime_content_type($this->File- $this->assertEquals($expecting, $result); $result = $this->File->Folder(); - $this->assertInstanceOf('Folder', $result); + $this->assertInstanceOf('Cake\Utility\Folder', $result); } /** @@ -522,7 +524,7 @@ public function testCopy() { */ public function testMime() { $this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type'); - $path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; + $path = CAKE . 'Test' . DS . 'TestApp' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; $file = new File($path); $expected = 'image/gif'; if (function_exists('mime_content_type') && false === mime_content_type($file->pwd())) { diff --git a/lib/Cake/Test/TestCase/Utility/FolderTest.php b/lib/Cake/Test/TestCase/Utility/FolderTest.php index 76ee08af459..5440fa9b794 100644 --- a/lib/Cake/Test/TestCase/Utility/FolderTest.php +++ b/lib/Cake/Test/TestCase/Utility/FolderTest.php @@ -16,15 +16,17 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Folder', 'Utility'); -App::uses('File', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Utility\File, + Cake\Utility\Folder; /** * FolderTest class * * @package Cake.Test.Case.Utility */ -class FolderTest extends CakeTestCase { +class FolderTest extends TestCase { protected static $_tmp = array(); @@ -60,8 +62,8 @@ public function tearDown() { $exclude = array_merge(self::$_tmp, array('.', '..')); foreach (scandir(TMP) as $dir) { if (is_dir(TMP . $dir) && !in_array($dir, $exclude)) { - $iterator = new RecursiveDirectoryIterator(TMP . $dir); - foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { + $iterator = new \RecursiveDirectoryIterator(TMP . $dir); + foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) { if ($file->isFile() || $file->isLink()) { unlink($file->getPathname()); } elseif ($file->isDir() && !in_array($file->getFilename(), array('.', '..'))) { @@ -180,7 +182,7 @@ public function testRecursiveCreateFailure() { $Folder = new Folder($path); $result = $Folder->create($path . DS . 'two' . DS . 'three'); $this->assertFalse($result); - } catch (PHPUnit_Framework_Error $e) { + } catch (\PHPUnit_Framework_Error $e) { $this->assertTrue(true); } diff --git a/lib/Cake/Test/TestCase/Utility/HashTest.php b/lib/Cake/Test/TestCase/Utility/HashTest.php index d4d3c94d52e..428f69b9926 100644 --- a/lib/Cake/Test/TestCase/Utility/HashTest.php +++ b/lib/Cake/Test/TestCase/Utility/HashTest.php @@ -12,9 +12,11 @@ * @since CakePHP(tm) v 2.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Hash', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Utility\Hash; -class HashTest extends CakeTestCase { +class HashTest extends TestCase { public static function articleData() { return array( diff --git a/lib/Cake/Test/TestCase/Utility/InflectorTest.php b/lib/Cake/Test/TestCase/Utility/InflectorTest.php index cd19892480a..6431d6e304f 100644 --- a/lib/Cake/Test/TestCase/Utility/InflectorTest.php +++ b/lib/Cake/Test/TestCase/Utility/InflectorTest.php @@ -18,19 +18,16 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license Open Group Test Suite License (http://www.opensource.org/licenses/opengroup.php) */ - -/** - * Included libraries. - * - */ -App::uses('Inflector', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Utility\Inflector; /** * Short description for class. * * @package Cake.Test.Case.Utility */ -class InflectorTest extends CakeTestCase { +class InflectorTest extends TestCase { /** * tearDown diff --git a/lib/Cake/Test/TestCase/Utility/CakeNumberTest.php b/lib/Cake/Test/TestCase/Utility/NumberTest.php similarity index 98% rename from lib/Cake/Test/TestCase/Utility/CakeNumberTest.php rename to lib/Cake/Test/TestCase/Utility/NumberTest.php index 7c2dab19ea0..b9b86930a03 100644 --- a/lib/Cake/Test/TestCase/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/TestCase/Utility/NumberTest.php @@ -1,6 +1,6 @@ Number = new CakeNumber(); + $this->Number = new Number(); } /** @@ -111,7 +112,7 @@ public function testMultibyteFormat() { $this->assertEquals($expected, $result); $value = '13371337.1337'; - $result = CakeNumber::format($value, array( + $result = Number::format($value, array( 'thousands' => '- |-| /-\ >< () |2 -', 'decimals' => '- £€€† -', 'before' => '' diff --git a/lib/Cake/Test/TestCase/Utility/ObjectCollectionTest.php b/lib/Cake/Test/TestCase/Utility/ObjectCollectionTest.php index c8adc05efeb..e01916fa48a 100644 --- a/lib/Cake/Test/TestCase/Utility/ObjectCollectionTest.php +++ b/lib/Cake/Test/TestCase/Utility/ObjectCollectionTest.php @@ -16,9 +16,11 @@ * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ - -App::uses('ObjectCollection', 'Utility'); -App::uses('CakeEvent', 'Event'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Event\Event, + Cake\Utility\ObjectCollection, + Cake\Core\Object; /** * A generic object class @@ -89,6 +91,9 @@ public function load($object, $settings = array()) { return $this->_loaded[$name]; } $objectClass = $name . 'GenericObject'; + if (strpos($objectClass, 'Mock') === false) { + $objectClass = __NAMESPACE__ . '\\' . $objectClass; + } $this->_loaded[$name] = new $objectClass($this, $settings); $enable = isset($settings['enabled']) ? $settings['enabled'] : true; if ($enable === true) { @@ -99,7 +104,7 @@ public function load($object, $settings = array()) { } -class ObjectCollectionTest extends CakeTestCase { +class ObjectCollectionTest extends TestCase { /** * setUp @@ -128,8 +133,8 @@ public function tearDown() { */ public function testLoad() { $result = $this->Objects->load('First'); - $this->assertInstanceOf('FirstGenericObject', $result); - $this->assertInstanceOf('FirstGenericObject', $this->Objects->First); + $this->assertInstanceOf(__NAMESPACE__ . '\FirstGenericObject', $result); + $this->assertInstanceOf(__NAMESPACE__ . '\FirstGenericObject', $this->Objects->First); $result = $this->Objects->attached(); $this->assertEquals(array('First'), $result, 'attached() results are wrong.'); @@ -175,10 +180,10 @@ public function testSet() { $this->assertEquals(array('First'), $result, 'loaded objects are wrong'); $result = $this->Objects->set('First', new SecondGenericObject($this->Objects)); - $this->assertInstanceOf('SecondGenericObject', $result['First'], 'set failed'); + $this->assertInstanceOf(__NAMESPACE__ . '\SecondGenericObject', $result['First'], 'set failed'); $result = $this->Objects->set('Second', new SecondGenericObject($this->Objects)); - $this->assertInstanceOf('SecondGenericObject', $result['Second'], 'set failed'); + $this->assertInstanceOf(__NAMESPACE__ . '\SecondGenericObject', $result['Second'], 'set failed'); $this->assertEquals(2, count($result)); } @@ -190,13 +195,13 @@ public function testSet() { */ protected function _makeMockClasses() { if (!class_exists('TriggerMockFirstGenericObject')) { - $this->getMock('FirstGenericObject', array(), array(), 'TriggerMockFirstGenericObject', false); + $this->getMock(__NAMESPACE__ . '\FirstGenericObject', array(), array(), 'TriggerMockFirstGenericObject', false); } if (!class_exists('TriggerMockSecondGenericObject')) { - $this->getMock('SecondGenericObject', array(), array(), 'TriggerMockSecondGenericObject', false); + $this->getMock(__NAMESPACE__ . '\SecondGenericObject', array(), array(), 'TriggerMockSecondGenericObject', false); } if (!class_exists('TriggerMockThirdGenericObject')) { - $this->getMock('ThirdGenericObject', array(), array(), 'TriggerMockThirdGenericObject', false); + $this->getMock(__NAMESPACE__ . '\ThirdGenericObject', array(), array(), 'TriggerMockThirdGenericObject', false); } } @@ -337,7 +342,7 @@ public function testTriggerWithModParams() { /** * test that setting modParams to an index that doesn't exist doesn't cause errors. * - * @expectedException CakeException + * @expectedException Cake\Error\Exception * @return void */ public function testTriggerModParamsInvalidIndex() { @@ -537,7 +542,7 @@ public function testnormalizeObjectArray() { } /** - * tests that passing an instance of CakeEvent to trigger will prepend the subject to the list of arguments + * tests that passing an instance of Cake\Event\Event to trigger will prepend the subject to the list of arguments * * @return void */ @@ -559,12 +564,12 @@ public function testDispatchEventWithSubject() { ->with($subjectClass, 'first argument') ->will($this->returnValue(true)); - $event = new CakeEvent('callback', $subjectClass, array('first argument')); + $event = new Event('callback', $subjectClass, array('first argument')); $this->assertTrue($this->Objects->trigger($event)); } /** - * tests that passing an instance of CakeEvent to trigger with omitSubject property + * tests that passing an instance of Cake\Event\Event to trigger with omitSubject property * will NOT prepend the subject to the list of arguments * * @return void @@ -587,7 +592,7 @@ public function testDispatchEventNoSubject() { ->with('first argument') ->will($this->returnValue(true)); - $event = new CakeEvent('callback', $subjectClass, array('first argument')); + $event = new Event('callback', $subjectClass, array('first argument')); $event->omitSubject = true; $this->assertTrue($this->Objects->trigger($event)); } diff --git a/lib/Cake/Test/TestCase/Utility/SanitizeTest.php b/lib/Cake/Test/TestCase/Utility/SanitizeTest.php index 13ba63c53ac..ae2196424ef 100644 --- a/lib/Cake/Test/TestCase/Utility/SanitizeTest.php +++ b/lib/Cake/Test/TestCase/Utility/SanitizeTest.php @@ -16,14 +16,18 @@ * @since CakePHP(tm) v 1.2.0.5428 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Sanitize', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\TestSuite\Fixture\TestModel, + Cake\Utility\Sanitize; + /** * DataTest class * * @package Cake.Test.Case.Utility */ -class SanitizeDataTest extends CakeTestModel { +class SanitizeDataTest extends TestModel { /** * name property @@ -45,7 +49,7 @@ class SanitizeDataTest extends CakeTestModel { * * @package Cake.Test.Case.Utility */ -class SanitizeArticle extends CakeTestModel { +class SanitizeArticle extends TestModel { /** * name property @@ -67,7 +71,7 @@ class SanitizeArticle extends CakeTestModel { * * @package Cake.Test.Case.Utility */ -class SanitizeTest extends CakeTestCase { +class SanitizeTest extends TestCase { /** * autoFixtures property diff --git a/lib/Cake/Test/TestCase/Utility/SecurityTest.php b/lib/Cake/Test/TestCase/Utility/SecurityTest.php index ca7fb69160f..d12616eae67 100644 --- a/lib/Cake/Test/TestCase/Utility/SecurityTest.php +++ b/lib/Cake/Test/TestCase/Utility/SecurityTest.php @@ -16,14 +16,17 @@ * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Security', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Core\Configure, + Cake\Utility\Security; /** * SecurityTest class * * @package Cake.Test.Case.Utility */ -class SecurityTest extends CakeTestCase { +class SecurityTest extends TestCase { /** * sut property diff --git a/lib/Cake/Test/TestCase/Utility/SetTest.php b/lib/Cake/Test/TestCase/Utility/SetTest.php index 4960a139dc2..8bb33b7569a 100644 --- a/lib/Cake/Test/TestCase/Utility/SetTest.php +++ b/lib/Cake/Test/TestCase/Utility/SetTest.php @@ -16,15 +16,18 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Set', 'Utility'); -App::uses('Model', 'Model'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Utility\Set, + Cake\Utility\Xml, + Cake\Model\Model; /** * SetTest class * * @package Cake.Test.Case.Utility */ -class SetTest extends CakeTestCase { +class SetTest extends TestCase { /** * testNumericKeyExtraction method @@ -1579,7 +1582,7 @@ public function testClassicExtract() { $expected = array('dot.test' => array(array('name' => 'jippi'))); $this->assertEquals($expected, $result); - $a = new stdClass(); + $a = new \stdClass(); $a->articles = array( array('Article' => array('id' => 1, 'title' => 'Article 1')), array('Article' => array('id' => 2, 'title' => 'Article 2')), @@ -1594,7 +1597,7 @@ public function testClassicExtract() { $expected = array('Article 1', 'Article 2', 'Article 3'); $this->assertEquals($expected, $result); - $a = new ArrayObject(); + $a = new \ArrayObject(); $a['articles'] = array( array('Article' => array('id' => 1, 'title' => 'Article 1')), array('Article' => array('id' => 2, 'title' => 'Article 2')), @@ -1909,7 +1912,7 @@ public function testCombine() { $expected = array('2: mariano.iglesias' => 'Mariano Iglesias', '14: phpnut' => 'Larry E. Masters', '25: gwoo' => 'The Gwoo'); $this->assertEquals($expected, $result); - $b = new stdClass(); + $b = new \stdClass(); $b->users = array( array('User' => array('id' => 2, 'group_id' => 1, 'Data' => array('user' => 'mariano.iglesias','name' => 'Mariano Iglesias'))), @@ -2039,21 +2042,21 @@ public function testMapReverse() { $this->assertEquals($expected, $result); $expected = array('User' => array('psword' => 'whatever', 'Icon' => array('id' => 851))); - $class = new stdClass; - $class->User = new stdClass; + $class = new \stdClass; + $class->User = new \stdClass; $class->User->psword = 'whatever'; - $class->User->Icon = new stdClass; + $class->User->Icon = new \stdClass; $class->User->Icon->id = 851; $result = Set::reverse($class); $this->assertEquals($expected, $result); $expected = array('User' => array('psword' => 'whatever', 'Icon' => array('id' => 851), 'Profile' => array('name' => 'Some Name', 'address' => 'Some Address'))); - $class = new stdClass; - $class->User = new stdClass; + $class = new \stdClass; + $class->User = new \stdClass; $class->User->psword = 'whatever'; - $class->User->Icon = new stdClass; + $class->User->Icon = new \stdClass; $class->User->Icon->id = 851; - $class->User->Profile = new stdClass; + $class->User->Profile = new \stdClass; $class->User->Profile->name = 'Some Name'; $class->User->Profile->address = 'Some Address'; @@ -2067,16 +2070,16 @@ public function testMapReverse() { array('id' => 1, 'article_id' => 1, 'user_id' => 1, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), array('id' => 2, 'article_id' => 1, 'user_id' => 2, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); - $class = new stdClass; - $class->User = new stdClass; + $class = new \stdClass; + $class->User = new \stdClass; $class->User->psword = 'whatever'; - $class->User->Icon = new stdClass; + $class->User->Icon = new \stdClass; $class->User->Icon->id = 851; - $class->User->Profile = new stdClass; + $class->User->Profile = new \stdClass; $class->User->Profile->name = 'Some Name'; $class->User->Profile->address = 'Some Address'; - $class->User->Comment = new stdClass; - $class->User->Comment->{'0'} = new stdClass; + $class->User->Comment = new \stdClass; + $class->User->Comment->{'0'} = new \stdClass; $class->User->Comment->{'0'}->id = 1; $class->User->Comment->{'0'}->article_id = 1; $class->User->Comment->{'0'}->user_id = 1; @@ -2084,7 +2087,7 @@ public function testMapReverse() { $class->User->Comment->{'0'}->published = 'Y'; $class->User->Comment->{'0'}->created = '2007-03-18 10:47:23'; $class->User->Comment->{'0'}->updated = '2007-03-18 10:49:31'; - $class->User->Comment->{'1'} = new stdClass; + $class->User->Comment->{'1'} = new \stdClass; $class->User->Comment->{'1'}->id = 2; $class->User->Comment->{'1'}->article_id = 1; $class->User->Comment->{'1'}->user_id = 2; @@ -2104,16 +2107,16 @@ public function testMapReverse() { array('id' => 2, 'article_id' => 1, 'user_id' => 2, 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); // @codingStandardsIgnoreStart - $class = new stdClass; - $class->User = new stdClass; + $class = new \stdClass; + $class->User = new \stdClass; $class->User->psword = 'whatever'; - $class->User->Icon = new stdClass; + $class->User->Icon = new \stdClass; $class->User->Icon->id = 851; - $class->User->Profile = new stdClass; + $class->User->Profile = new \stdClass; $class->User->Profile->name = 'Some Name'; $class->User->Profile->address = 'Some Address'; $class->User->Comment = array(); - $comment = new stdClass; + $comment = new \stdClass; $comment->id = 1; $comment->article_id = 1; $comment->user_id = 1; @@ -2121,7 +2124,7 @@ public function testMapReverse() { $comment->published = 'Y'; $comment->created = '2007-03-18 10:47:23'; $comment->updated = '2007-03-18 10:49:31'; - $comment2 = new stdClass; + $comment2 = new \stdClass; $comment2->id = 2; $comment2->article_id = 1; $comment2->user_id = 2; @@ -2134,11 +2137,11 @@ public function testMapReverse() { $result = Set::reverse($class); $this->assertEquals($expected, $result); - $class = new stdClass; - $class->User = new stdClass; + $class = new \stdClass; + $class->User = new \stdClass; $class->User->id = 100; $class->someString = 'this is some string'; - $class->Profile = new stdClass; + $class->Profile = new \stdClass; $class->Profile->name = 'Joe Mamma'; $result = Set::reverse($class); @@ -2150,11 +2153,11 @@ public function testMapReverse() { $this->assertEquals($expected, $result); // @codingStandardsIgnoreStart - $class = new stdClass; - $class->User = new stdClass; + $class = new \stdClass; + $class->User = new \stdClass; $class->User->id = 100; $class->User->_name_ = 'User'; - $class->Profile = new stdClass; + $class->Profile = new \stdClass; $class->Profile->name = 'Joe Mamma'; $class->Profile->_name_ = 'Profile'; // @codingStandardsIgnoreEnd @@ -2387,7 +2390,7 @@ public function testMapNesting() { $mapped = Set::map($data); // @codingStandardsIgnoreStart - $expected = new stdClass(); + $expected = new \stdClass(); $expected->_name_ = 'IndexedPage'; $expected->id = 2; $expected->url = 'http://blah.com/'; @@ -2429,7 +2432,7 @@ public function testNestedMappedData() { )); // @codingStandardsIgnoreStart - $expected = new stdClass; + $expected = new \stdClass; $expected->_name_ = 'Post'; $expected->id = '1'; $expected->author_id = '1'; @@ -2439,7 +2442,7 @@ public function testNestedMappedData() { $expected->created = "2007-03-18 10:39:23"; $expected->updated = "2007-03-18 10:41:31"; - $expected->Author = new stdClass; + $expected->Author = new \stdClass; $expected->Author->id = '1'; $expected->Author->user = 'mariano'; $expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99'; @@ -2448,7 +2451,7 @@ public function testNestedMappedData() { $expected->Author->test = "working"; $expected->Author->_name_ = 'Author'; - $expected2 = new stdClass; + $expected2 = new \stdClass; $expected2->_name_ = 'Post'; $expected2->id = '2'; $expected2->author_id = '3'; @@ -2458,7 +2461,7 @@ public function testNestedMappedData() { $expected2->created = "2007-03-18 10:41:23"; $expected2->updated = "2007-03-18 10:43:31"; - $expected2->Author = new stdClass; + $expected2->Author = new \stdClass; $expected2->Author->id = '3'; $expected2->Author->user = 'larry'; $expected2->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99'; @@ -2481,7 +2484,7 @@ public function testNestedMappedData() { ) ); // @codingStandardsIgnoreStart - $expected = new stdClass; + $expected = new \stdClass; $expected->_name_ = 'Post'; $expected->id = '1'; $expected->author_id = '1'; @@ -2491,7 +2494,7 @@ public function testNestedMappedData() { $expected->created = "2007-03-18 10:39:23"; $expected->updated = "2007-03-18 10:41:31"; - $expected->Author = new stdClass; + $expected->Author = new \stdClass; $expected->Author->id = '1'; $expected->Author->user = 'mariano'; $expected->Author->password = '5f4dcc3b5aa765d61d8327deb882cf99'; @@ -2541,19 +2544,19 @@ public function testNestedMappedData() { $result = Set::map($data); // @codingStandardsIgnoreStart - $expected = new stdClass(); + $expected = new \stdClass(); $expected->_name_ = 'User'; $expected->id = 1; $expected->email = 'user@example.com'; $expected->first_name = 'John'; $expected->last_name = 'Smith'; - $piece = new stdClass(); + $piece = new \stdClass(); $piece->id = 1; $piece->title = 'Moonlight Sonata'; $piece->composer = 'Ludwig van Beethoven'; - $piece->PiecesUser = new stdClass(); + $piece->PiecesUser = new \stdClass(); $piece->PiecesUser->id = 1; $piece->PiecesUser->created = '2008-01-01 00:00:00'; $piece->PiecesUser->modified = '2008-01-01 00:00:00'; @@ -2563,12 +2566,12 @@ public function testNestedMappedData() { $piece->_name_ = 'Piece'; - $piece2 = new stdClass(); + $piece2 = new \stdClass(); $piece2->id = 2; $piece2->title = 'Moonlight Sonata 2'; $piece2->composer = 'Ludwig van Beethoven'; - $piece2->PiecesUser = new stdClass(); + $piece2->PiecesUser = new \stdClass(); $piece2->PiecesUser->id = 2; $piece2->PiecesUser->created = '2008-01-01 00:00:00'; $piece2->PiecesUser->modified = '2008-01-01 00:00:00'; @@ -2627,19 +2630,19 @@ public function testNestedMappedData() { $result = Set::map($data); // @codingStandardsIgnoreStart - $expected = new stdClass(); + $expected = new \stdClass(); $expected->_name_ = 'FooUser'; $expected->id = 1; $expected->email = 'user@example.com'; $expected->first_name = 'John'; $expected->last_name = 'Smith'; - $piece = new stdClass(); + $piece = new \stdClass(); $piece->id = 1; $piece->title = 'Moonlight Sonata'; $piece->composer = 'Ludwig van Beethoven'; $piece->_name_ = 'FooPiece'; - $piece->PiecesUser = new stdClass(); + $piece->PiecesUser = new \stdClass(); $piece->PiecesUser->id = 1; $piece->PiecesUser->created = '2008-01-01 00:00:00'; $piece->PiecesUser->modified = '2008-01-01 00:00:00'; @@ -2647,12 +2650,12 @@ public function testNestedMappedData() { $piece->PiecesUser->user_id = 2; $piece->PiecesUser->_name_ = 'FooPiecesUser'; - $piece2 = new stdClass(); + $piece2 = new \stdClass(); $piece2->id = 2; $piece2->title = 'Moonlight Sonata 2'; $piece2->composer = 'Ludwig van Beethoven'; $piece2->_name_ = 'FooPiece'; - $piece2->PiecesUser = new stdClass(); + $piece2->PiecesUser = new \stdClass(); $piece2->PiecesUser->id = 2; $piece2->PiecesUser->created = '2008-01-01 00:00:00'; $piece2->PiecesUser->modified = '2008-01-01 00:00:00'; @@ -2739,7 +2742,7 @@ public function testApply() { $expected = array('MOVIE 3', 'MOVIE 1', 'MOVIE 2'); $this->assertEquals($expected, $result); - $result = Set::apply('/Movie/rating', $data, array('SetTest', 'method'), array('type' => 'reduce')); + $result = Set::apply('/Movie/rating', $data, array(__CLASS__, 'method'), array('type' => 'reduce')); $expected = 9; $this->assertEquals($expected, $result); @@ -2764,8 +2767,6 @@ public static function method($val1, $val2) { * @return void */ public function testXmlSetReverse() { - App::uses('Xml', 'Utility'); - $string = ' diff --git a/lib/Cake/Test/TestCase/Utility/StringTest.php b/lib/Cake/Test/TestCase/Utility/StringTest.php index efa024b5b54..363f09119b6 100644 --- a/lib/Cake/Test/TestCase/Utility/StringTest.php +++ b/lib/Cake/Test/TestCase/Utility/StringTest.php @@ -16,14 +16,16 @@ * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('String', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Utility\String; /** * StringTest class * * @package Cake.Test.Case.Utility */ -class StringTest extends CakeTestCase { +class StringTest extends TestCase { public function setUp() { parent::setUp(); diff --git a/lib/Cake/Test/TestCase/Utility/CakeTimeTest.php b/lib/Cake/Test/TestCase/Utility/TimeTest.php similarity index 94% rename from lib/Cake/Test/TestCase/Utility/CakeTimeTest.php rename to lib/Cake/Test/TestCase/Utility/TimeTest.php index 482aaf8dcdd..1161a1c765c 100644 --- a/lib/Cake/Test/TestCase/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/TestCase/Utility/TimeTest.php @@ -1,6 +1,6 @@ Time = new CakeTime(); + $this->Time = new Time(); $this->_systemTimezoneIdentifier = date_default_timezone_get(); } @@ -338,7 +344,7 @@ public function testNice() { $this->assertEquals(date('Y-d-m', $time), $this->Time->nice($time)); $this->assertEquals('%Y-%d-%m', $this->Time->niceFormat); - CakeTime::$niceFormat = '%Y-%d-%m %H:%M:%S'; + Time::$niceFormat = '%Y-%d-%m %H:%M:%S'; $this->assertEquals(date('Y-d-m H:i:s', $time), $this->Time->nice($time)); $this->assertEquals('%Y-%d-%m %H:%M:%S', $this->Time->niceFormat); @@ -366,7 +372,7 @@ public function testNiceShort() { $this->assertEquals('Tomorrow, ' . date('H:i', $time), $this->Time->niceShort($time)); date_default_timezone_set('Europe/London'); - $result = $this->Time->niceShort('2005-01-15 10:00:00', new DateTimeZone('Europe/Brussels')); + $result = $this->Time->niceShort('2005-01-15 10:00:00', new \DateTimeZone('Europe/Brussels')); $this->assertEquals('Jan 15th 2005, 11:00', $result); date_default_timezone_set('UTC'); @@ -436,28 +442,28 @@ public function testToServer() { date_default_timezone_set('Europe/Paris'); $time = '2005-10-25 10:00:00'; $result = $this->Time->toServer($time); - $date = new DateTime($time, new DateTimeZone('UTC')); - $date->setTimezone(new DateTimeZone(date_default_timezone_get())); + $date = new \DateTime($time, new \DateTimeZone('UTC')); + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); $expected = $date->format('Y-m-d H:i:s'); $this->assertEquals($expected, $result); $time = '2002-01-01 05:15:30'; $result = $this->Time->toServer($time, 'America/New_York'); - $date = new DateTime($time, new DateTimeZone('America/New_York')); - $date->setTimezone(new DateTimeZone(date_default_timezone_get())); + $date = new \DateTime($time, new \DateTimeZone('America/New_York')); + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); $expected = $date->format('Y-m-d H:i:s'); $this->assertEquals($expected, $result); $time = '2010-01-28T15:00:00+10:00'; $result = $this->Time->toServer($time, 'America/New_York'); - $date = new DateTime($time); - $date->setTimezone(new DateTimeZone(date_default_timezone_get())); + $date = new \DateTime($time); + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); $expected = $date->format('Y-m-d H:i:s'); $this->assertEquals($expected, $result); - $date = new DateTime(null, new DateTimeZone('America/New_York')); + $date = new \DateTime(null, new \DateTimeZone('America/New_York')); $result = $this->Time->toServer($date, 'Pacific/Tahiti'); - $date->setTimezone(new DateTimeZone(date_default_timezone_get())); + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); $expected = $date->format('Y-m-d H:i:s'); $this->assertEquals($expected, $result); @@ -472,17 +478,17 @@ public function testToServer() { date_default_timezone_set('UTC'); - $serverTime = new DateTime('now'); + $serverTime = new \DateTime('now'); $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); foreach ($timezones as $timezone) { $result = $this->Time->toServer($serverTime->format('Y-m-d H:i:s'), $timezone, 'U'); - $tz = new DateTimeZone($timezone); + $tz = new \DateTimeZone($timezone); $this->assertEquals($serverTime->format('U'), $result + $tz->getOffset($serverTime)); } date_default_timezone_set('UTC'); - $date = new DateTime('now', new DateTimeZone('America/New_York')); + $date = new \DateTime('now', new \DateTimeZone('America/New_York')); $result = $this->Time->toServer($date, null, 'Y-m-d H:i:s'); $date->setTimezone($this->Time->timezone()); @@ -512,8 +518,8 @@ public function testToRss() { if (!$this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) { $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); foreach ($timezones as $timezone) { - $yourTimezone = new DateTimeZone($timezone); - $yourTime = new DateTime('now', $yourTimezone); + $yourTimezone = new \DateTimeZone($timezone); + $yourTime = new \DateTime('now', $yourTimezone); $userOffset = $yourTimezone->getOffset($yourTime) / HOUR; $this->assertEquals($yourTime->format('r'), $this->Time->toRss(time(), $userOffset)); $this->assertEquals($yourTime->format('r'), $this->Time->toRss(time(), $timezone)); @@ -765,8 +771,8 @@ public function testIsWithinNext() { * @return void */ public function testUserOffset() { - $timezoneServer = new DateTimeZone(date_default_timezone_get()); - $timeServer = new DateTime('now', $timezoneServer); + $timezoneServer = new \DateTimeZone(date_default_timezone_get()); + $timeServer = new \DateTime('now', $timezoneServer); $yourTimezone = $timezoneServer->getOffset($timeServer) / HOUR; $expected = time(); @@ -820,18 +826,18 @@ public function testFromString() { public function testFromStringWithDateTime() { date_default_timezone_set('UTC'); - $date = new DateTime('+1 hour', new DateTimeZone('America/New_York')); + $date = new \DateTime('+1 hour', new \DateTimeZone('America/New_York')); $result = $this->Time->fromString($date, 'UTC'); - $date->setTimezone(new DateTimeZone('UTC')); + $date->setTimezone(new \DateTimeZone('UTC')); $expected = $date->format('U') + $date->getOffset(); $this->assertEquals($expected, $result); date_default_timezone_set('Australia/Melbourne'); - $date = new DateTime('+1 hour', new DateTimeZone('America/New_York')); + $date = new \DateTime('+1 hour', new \DateTimeZone('America/New_York')); $result = $this->Time->fromString($date, 'Asia/Kuwait'); - $date->setTimezone(new DateTimeZone('Asia/Kuwait')); + $date->setTimezone(new \DateTimeZone('Asia/Kuwait')); $expected = $date->format('U') + $date->getOffset(); $this->assertEquals($expected, $result); @@ -845,7 +851,7 @@ public function testFromStringWithDateTime() { */ public function testConvertSpecifiers() { App::build(array( - 'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS) + 'Locale' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Locale' . DS) ), App::RESET); Configure::write('Config.language', 'time_test'); $time = strtotime('Thu Jan 14 11:43:39 2010'); @@ -952,7 +958,7 @@ public function testConvertPercentE() { */ public function testI18nFormat() { App::build(array( - 'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS) + 'Locale' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Locale' . DS) ), App::RESET); Configure::write('Config.language', 'time_test'); @@ -1006,7 +1012,7 @@ public function testFormatNewSyntax() { * @return void */ public function testListTimezones() { - $return = CakeTime::listTimezones(); + $return = Time::listTimezones(); $this->assertTrue(isset($return['Asia']['Asia/Bangkok'])); $this->assertEquals('Bangkok', $return['Asia']['Asia/Bangkok']); $this->assertTrue(isset($return['America']['America/Argentina/Buenos_Aires'])); @@ -1015,20 +1021,20 @@ public function testListTimezones() { $this->assertFalse(isset($return['Cuba'])); $this->assertFalse(isset($return['US'])); - $return = CakeTime::listTimezones('#^Asia/#'); + $return = Time::listTimezones('#^Asia/#'); $this->assertTrue(isset($return['Asia']['Asia/Bangkok'])); $this->assertFalse(isset($return['Pacific'])); - $return = CakeTime::listTimezones('#^(America|Pacific)/#', null, false); + $return = Time::listTimezones('#^(America|Pacific)/#', null, false); $this->assertTrue(isset($return['America/Argentina/Buenos_Aires'])); $this->assertTrue(isset($return['Pacific/Tahiti'])); if (!$this->skipIf(version_compare(PHP_VERSION, '5.3.0', '<'))) { - $return = CakeTime::listTimezones(DateTimeZone::ASIA); + $return = Time::listTimezones(\DateTimeZone::ASIA); $this->assertTrue(isset($return['Asia']['Asia/Bangkok'])); $this->assertFalse(isset($return['Pacific'])); - $return = CakeTime::listTimezones(DateTimeZone::PER_COUNTRY, 'US', false); + $return = Time::listTimezones(\DateTimeZone::PER_COUNTRY, 'US', false); $this->assertTrue(isset($return['Pacific/Honolulu'])); $this->assertFalse(isset($return['Asia/Bangkok'])); } diff --git a/lib/Cake/Test/TestCase/Utility/ValidationTest.php b/lib/Cake/Test/TestCase/Utility/ValidationTest.php index 9bd7af11173..326add5f7b5 100644 --- a/lib/Cake/Test/TestCase/Utility/ValidationTest.php +++ b/lib/Cake/Test/TestCase/Utility/ValidationTest.php @@ -16,7 +16,10 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Validation', 'Utility'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\Core\Configure, + Cake\Utility\Validation; /** * CustomValidator class @@ -93,7 +96,7 @@ public static function phone($check) { * * @package Cake.Test.Case.Utility */ -class ValidationTest extends CakeTestCase { +class ValidationTest extends TestCase { /** * setUp method @@ -2049,9 +2052,9 @@ public function testPostal() { * @return void */ public function testPhonePostalSsnPass() { - $this->assertTrue(Validation::postal('text', null, 'testNl')); - $this->assertTrue(Validation::phone('text', null, 'testDe')); - $this->assertTrue(Validation::ssn('text', null, 'testNl')); + $this->assertTrue(Validation::postal('text', null, __NAMESPACE__ . '\TestNlValidation')); + $this->assertTrue(Validation::phone('text', null, __NAMESPACE__ . '\TestDeValidation')); + $this->assertTrue(Validation::ssn('text', null, __NAMESPACE__ . '\TestNlValidation')); } /** @@ -2061,7 +2064,7 @@ public function testPhonePostalSsnPass() { * @return void */ public function testPassThroughMethodFailure() { - Validation::phone('text', null, 'testNl'); + Validation::phone('text', null, __NAMESPACE__ . '\TestNlValidation'); } /** @@ -2080,7 +2083,7 @@ public function testPassThroughClassFailure() { * @return void */ public function testPassThroughMethod() { - $this->assertTrue(Validation::postal('text', null, 'testNl')); + $this->assertTrue(Validation::postal('text', null, __NAMESPACE__ . '\TestNlValidation')); } /** diff --git a/lib/Cake/Test/TestCase/Utility/XmlTest.php b/lib/Cake/Test/TestCase/Utility/XmlTest.php index a2693713a39..515c79b804f 100644 --- a/lib/Cake/Test/TestCase/Utility/XmlTest.php +++ b/lib/Cake/Test/TestCase/Utility/XmlTest.php @@ -16,15 +16,18 @@ * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('Xml', 'Utility'); -App::uses('CakeTestModel', 'TestSuite/Fixture'); +namespace Cake\Test\TestCase\Utility; +use Cake\TestSuite\TestCase, + Cake\TestSuite\Fixture\TestModel, + Cake\Utility\Xml, + Cake\Core\Configure; /** * Article class * * @package Cake.Test.Case.Utility */ -class XmlArticle extends CakeTestModel { +class XmlArticle extends TestModel { /** * name property @@ -51,7 +54,7 @@ class XmlArticle extends CakeTestModel { * * @package Cake.Test.Case.Utility */ -class XmlUser extends CakeTestModel { +class XmlUser extends TestModel { /** * name property @@ -77,7 +80,7 @@ class XmlUser extends CakeTestModel { * * @package Cake.Test.Case.Utility */ -class XmlTest extends CakeTestCase { +class XmlTest extends TestCase { /** * autoFixtures property @@ -123,7 +126,7 @@ public function tearDown() { public function testBuild() { $xml = 'value'; $obj = Xml::build($xml); - $this->assertTrue($obj instanceof SimpleXMLElement); + $this->assertTrue($obj instanceof \SimpleXMLElement); $this->assertEquals('tag', (string)$obj->getName()); $this->assertEquals('value', (string)$obj); @@ -131,7 +134,7 @@ public function testBuild() { $this->assertEquals($obj, Xml::build($xml)); $obj = Xml::build($xml, array('return' => 'domdocument')); - $this->assertTrue($obj instanceof DOMDocument); + $this->assertTrue($obj instanceof \DOMDocument); $this->assertEquals('tag', $obj->firstChild->nodeName); $this->assertEquals('value', $obj->firstChild->nodeValue); @@ -184,7 +187,7 @@ public static function invalidDataProvider() { * testBuildInvalidData * * @dataProvider invalidDataProvider - * @expectedException XmlException + * @expectedException Cake\Error\XmlException * return void */ public function testBuildInvalidData($value) { @@ -200,7 +203,7 @@ public function testBuildEmptyTag() { try { Xml::build(''); $this->fail('No exception'); - } catch (Exception $e) { + } catch (\Exception $e) { $this->assertTrue(true, 'An exception was raised'); } } @@ -241,7 +244,7 @@ public function testFromArray() { ) ); $obj = Xml::fromArray($xml, 'attributes'); - $this->assertTrue($obj instanceof SimpleXMLElement); + $this->assertTrue($obj instanceof \SimpleXMLElement); $this->assertEquals('tags', $obj->getName()); $this->assertEquals(2, count($obj)); $xmlText = <<assertXmlStringEqualsXmlString($xmlText, $obj->asXML()); $obj = Xml::fromArray($xml); - $this->assertTrue($obj instanceof SimpleXMLElement); + $this->assertTrue($obj instanceof \SimpleXMLElement); $this->assertEquals('tags', $obj->getName()); $this->assertEquals(2, count($obj)); $xmlText = <<fail('No exception.'); - } catch (Exception $e) { + } catch (\Exception $e) { $this->assertTrue(true, 'Caught exception.'); } } @@ -962,7 +965,7 @@ public function testCdata() { */ public static function invalidToArrayDataProvider() { return array( - array(new DateTime()), + array(new \DateTime()), array(array()) ); } @@ -971,7 +974,7 @@ public static function invalidToArrayDataProvider() { * testToArrayFail method * * @dataProvider invalidToArrayDataProvider - * @expectedException XmlException + * @expectedException Cake\Error\XmlException */ public function testToArrayFail($value) { Xml::toArray($value);