From d41e5621b7af60c233e9965c0baab5a3bfe24b41 Mon Sep 17 00:00:00 2001 From: Majna Date: Thu, 16 Feb 2012 19:28:21 +0100 Subject: [PATCH] Fix missing and invalid assertions in tests. Remove unused variables and dead code. --- .../Test/Case/Console/AllConsoleLibsTest.php | 1 - .../Console/Command/Task/ControllerTaskTest.php | 4 ---- .../Case/Console/Command/Task/ModelTaskTest.php | 16 +++++++++++++++- .../Component/RequestHandlerComponentTest.php | 1 - .../Component/SecurityComponentTest.php | 1 - lib/Cake/Test/Case/Controller/ControllerTest.php | 3 --- lib/Cake/Test/Case/I18n/I18nTest.php | 3 +-- lib/Cake/Test/Case/I18n/MultibyteTest.php | 2 -- .../Case/Model/Datasource/Database/MysqlTest.php | 1 - lib/Cake/Test/Case/Model/ModelDeleteTest.php | 2 +- lib/Cake/Test/Case/Model/ModelReadTest.php | 2 +- lib/Cake/Test/Case/Network/CakeSocketTest.php | 1 + lib/Cake/Test/Case/Routing/RouterTest.php | 3 ++- .../Test/Case/TestSuite/CakeTestSuiteTest.php | 2 +- .../Case/View/Helper/PaginatorHelperTest.php | 3 ++- .../Test/Case/View/Helper/SessionHelperTest.php | 1 + lib/Cake/Test/Case/View/MediaViewTest.php | 1 - lib/Cake/Test/Case/View/ViewTest.php | 1 - 18 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/Cake/Test/Case/Console/AllConsoleLibsTest.php b/lib/Cake/Test/Case/Console/AllConsoleLibsTest.php index de409552ce9..9206b617fd8 100644 --- a/lib/Cake/Test/Case/Console/AllConsoleLibsTest.php +++ b/lib/Cake/Test/Case/Console/AllConsoleLibsTest.php @@ -34,7 +34,6 @@ class AllConsoleLibsTest extends PHPUnit_Framework_TestSuite { public static function suite() { $suite = new CakeTestSuite('All console lib classes'); - $path = CORE_TEST_CASES . DS . 'Console'; foreach (new DirectoryIterator(dirname(__FILE__)) as $file) { if (!$file->isFile() || strpos($file, 'All') === 0) { continue; diff --git a/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php index a294fe8fbbc..7b37154d122 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php @@ -253,7 +253,6 @@ public function testConfirmController() { $scaffold = false; $helpers = array('Ajax', 'Time'); $components = array('Acl', 'Auth'); - $uses = array('Comment', 'User'); $this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller"); $this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time"); @@ -302,9 +301,6 @@ public function testBake() { */ public function testBakeWithPlugin() { $this->Task->plugin = 'ControllerTest'; - $helpers = array('Ajax', 'Time'); - $components = array('Acl', 'Auth'); - $uses = array('Comment', 'User'); //fake plugin path CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS)); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index 166d51aafb0..46a6b677e2d 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -283,21 +283,27 @@ public function testFieldValidationGuessing() { $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $expected = array('notempty' => 'notempty'); + $this->assertEquals($expected, $result); $result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false)); $expected = array('date' => 'date'); + $this->assertEquals($expected, $result); $result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false)); $expected = array('time' => 'time'); + $this->assertEquals($expected, $result); $result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false)); $expected = array('email' => 'email'); + $this->assertEquals($expected, $result); $result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false)); $expected = array('numeric' => 'numeric'); + $this->assertEquals($expected, $result); $result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false)); - $expected = array('numeric' => 'numeric'); + $expected = array('boolean' => 'boolean'); + $this->assertEquals($expected, $result); } /** @@ -589,6 +595,13 @@ public function testDoAssociationsNonInteractive() { $model = new Model(array('ds' => 'test', 'name' => 'BakeArticle')); $result = $this->Task->doAssociations($model); $expected = array( + 'belongsTo' => array( + array( + 'alias' => 'BakeUser', + 'className' => 'BakeUser', + 'foreignKey' => 'bake_user_id', + ), + ), 'hasMany' => array( array( 'alias' => 'BakeComment', @@ -606,6 +619,7 @@ public function testDoAssociationsNonInteractive() { ), ), ); + $this->assertEquals($result, $expected); } /** diff --git a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php index d36199e63ed..a7241be70f1 100644 --- a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php @@ -428,7 +428,6 @@ public function testRespondAs() { $this->RequestHandler->response->expects($this->at(1))->method('type') ->with('text/xml'); - $RequestHandler = $this->getMock('RequestHandlerComponent', array('_header'), array(&$this->Controller->Components)); $result = $this->RequestHandler->respondAs('json'); $this->assertTrue($result); $result = $this->RequestHandler->respondAs('text/xml'); diff --git a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php index 79b6fecd90a..e0b502a2d4f 100644 --- a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php @@ -480,7 +480,6 @@ public function testValidatePostNoSession() { public function testValidatePostFormHacking() { $this->Controller->Security->startup($this->Controller); $key = $this->Controller->params['_Token']['key']; - $fields = 'a5475372b40f6e3ccbf9f8af191f20e1642fd877%3AModel.valid'; $unlocked = ''; $this->Controller->request->data = array( diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index c5d85dcc616..2810f7c68c8 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -490,7 +490,6 @@ public function testLoadModelInPlugins() { */ public function testConstructClasses() { $request = new CakeRequest('controller_posts/index'); - $Controller = new Controller($request); $Controller = new Controller($request); $Controller->uses = array('ControllerPost', 'ControllerComment'); @@ -511,8 +510,6 @@ public function testConstructClasses() { $this->assertTrue(isset($Controller->TestPluginPost)); $this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost')); - - unset($Controller); } /** diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index d68ecce48f1..6eb56690362 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -57,13 +57,12 @@ public function tearDown() { */ public function testTranslationCaching() { Configure::write('Config.language', 'cache_test_po'); - $i18n = I18n::getInstance(); // reset internally stored entries I18n::clear(); Cache::clear(false, '_cake_core_'); - $lang = Configure::read('Config.language');#$i18n->l10n->locale; + $lang = Configure::read('Config.language'); Cache::config('_cake_core_', Cache::config('default')); diff --git a/lib/Cake/Test/Case/I18n/MultibyteTest.php b/lib/Cake/Test/Case/I18n/MultibyteTest.php index 16dd920ed76..134f05d21fc 100644 --- a/lib/Cake/Test/Case/I18n/MultibyteTest.php +++ b/lib/Cake/Test/Case/I18n/MultibyteTest.php @@ -8800,7 +8800,6 @@ public function testUsingMbSubstr() { $this->assertEquals($expected, $result); $string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ'; - $find = 'Ċ'; $result = mb_substr($string, 4, 7); $expected = 'ĈĊČĎĐĒĔ'; $this->assertEquals($expected, $result); @@ -8958,7 +8957,6 @@ public function testMultibyteSubstr() { $this->assertEquals($expected, $result); $string = 'ĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŹŻŽ'; - $find = 'Ċ'; $result = Multibyte::substr($string, 4, 7); $expected = 'ĈĊČĎĐĒĔ'; $this->assertEquals($expected, $result); diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 0e4f8235dab..2ef9c39983d 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -1142,7 +1142,6 @@ public function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBindin $null = null; $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); - $_queryData = $queryData; $result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet); $this->assertTrue($result); diff --git a/lib/Cake/Test/Case/Model/ModelDeleteTest.php b/lib/Cake/Test/Case/Model/ModelDeleteTest.php index e3a64e0b115..306aa9d7a1f 100644 --- a/lib/Cake/Test/Case/Model/ModelDeleteTest.php +++ b/lib/Cake/Test/Case/Model/ModelDeleteTest.php @@ -636,7 +636,7 @@ public function testDeleteDependent() { $this->assertEquals(4, $result); $result = $Article->delete(1, true); - $this->assertIdentical(true, true); + $this->assertSame($result, true); $result = $Article->Comment->find('count', array( 'conditions' => array('Comment.article_id' => 1) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 6e220e3fdc7..401c87adf89 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -76,7 +76,6 @@ public function testFetchingNonUniqueFKJoinTableRecords() { * @return void */ public function testGroupBy() { - $db = ConnectionManager::getDataSource('test'); $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver; $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.'; @@ -6769,6 +6768,7 @@ public function testFindCount() { $this->db->fullDebug = true; $TestModel->order = 'User.id'; $result = $TestModel->find('count'); + $this->db->fullDebug = $fullDebug; $this->assertEquals($result, 4); $log = $this->db->getLog(); diff --git a/lib/Cake/Test/Case/Network/CakeSocketTest.php b/lib/Cake/Test/Case/Network/CakeSocketTest.php index 65a5713e16b..4161a0cbd78 100644 --- a/lib/Cake/Test/Case/Network/CakeSocketTest.php +++ b/lib/Cake/Test/Case/Network/CakeSocketTest.php @@ -181,6 +181,7 @@ public function testTimeOutConnection() { $this->assertTrue($this->Socket->connect()); $config = array('host' => '127.0.0.1', 'timeout' => 0.00001); + $this->Socket = new CakeSocket($config); $this->assertFalse($this->Socket->read(1024 * 1024)); $this->assertEquals($this->Socket->lastError(), '2: ' . __d('cake_dev', 'Connection timed out')); } diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 272fb6de6ad..25e333c4903 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -969,7 +969,8 @@ public function testUrlParsing() { Router::reload(); Router::connect('/page/*', array('controller' => 'test')); $result = Router::parse('/page/my-page'); - $expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index'); + $expected = array('pass' => array('my-page'), 'plugin' => null, 'controller' => 'test', 'action' => 'index', 'named' => array()); + $this->assertEquals($expected, $result); Router::reload(); Router::connect('/:language/contact', array('language' => 'eng', 'plugin' => 'contact', 'controller' => 'contact', 'action' => 'index'), array('language' => '[a-z]{3}')); diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php index aa5529305ad..25b5608ffb0 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php @@ -60,7 +60,7 @@ public function testAddTestDirectory() { * * @return void */ - public function testAddTestDirectoryRecursive() {return; + public function testAddTestDirectoryRecursive() { $testFolder = CORE_TEST_CASES . DS . 'Cache'; $count = count(glob($testFolder . DS . '*Test.php')); $count += count(glob($testFolder . DS . 'Engine' . DS . '*Test.php')); diff --git a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php index 28fd7f59bfe..f1f37af44d1 100644 --- a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php @@ -2140,8 +2140,9 @@ public function testWithPlugin() { $this->Paginator->options(array('url' => array('plugin' => null))); $result = $this->Paginator->link('Page 3', array('page' => 3)); $expected = array( - 'a' => array('/magazines/index/page:3'), 'Page 3', '/a' + 'a' => array('href' => '/magazines/index/page:3'), 'Page 3', '/a' ); + $this->assertTags($result, $expected); $this->Paginator->options(array('url' => array('plugin' => null, 'controller' => 'issues'))); $result = $this->Paginator->link('Page 3', array('page' => 3)); diff --git a/lib/Cake/Test/Case/View/Helper/SessionHelperTest.php b/lib/Cake/Test/Case/View/Helper/SessionHelperTest.php index e82fca5a649..ba0e3877b09 100644 --- a/lib/Cake/Test/Case/View/Helper/SessionHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/SessionHelperTest.php @@ -168,6 +168,7 @@ public function testFlashElementInAttrs() { 'params' => array('title' => 'Notice!', 'name' => 'Alert!') )); $expected = "
\n\t

Alert!

\n\t

Notice!

\n\t

This is a calling

\n
"; + $this->assertEquals($expected, $result); } /** diff --git a/lib/Cake/Test/Case/View/MediaViewTest.php b/lib/Cake/Test/Case/View/MediaViewTest.php index 38d68a239fd..ed4f7f7418d 100644 --- a/lib/Cake/Test/Case/View/MediaViewTest.php +++ b/lib/Cake/Test/Case/View/MediaViewTest.php @@ -35,7 +35,6 @@ class MediaViewTest extends CakeTestCase { */ public function setUp() { parent::setUp(); - $controller = new Controller(); $this->MediaView = $this->getMock('MediaView', array('_isActive', '_clearBuffer', '_flushBuffer')); $this->MediaView->response = $this->getMock('CakeResponse'); } diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 9986793fe77..f5c2a3cc6db 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1082,7 +1082,6 @@ public function testRenderCache() { $View->renderCache($path, '+1 second'); $result = ob_get_clean(); - $expected = 'some cacheText'; $this->assertRegExp('/^some cacheText/', $result); @unlink($path);