Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -4,23 +4,57 @@
*
* Test Case for CakeTestCase class
*
* PHP version 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc.
* 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 2005-2012, Cake Software Foundation, Inc.
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakePlugin', 'Core');
App::uses('Controller', 'Controller');
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
App::uses('Model', 'Model');
/**
* Secondary Post stub class.
*/
class SecondaryPost extends Model {
/**
* @var string
*/
public $useTable = 'posts';
/**
* @var string
*/
public $useDbConfig = 'secondary';
}
/**
* ConstructorPost test stub.
*/
class ConstructorPost extends Model {
/**
* @var string
*/
public $useTable = 'posts';
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->getDataSource()->cacheMethods = false;
}
}
/**
* CakeTestCaseTest
@ -29,6 +63,18 @@ App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
*/
class CakeTestCaseTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
*/
public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
/**
* CakeTestCaseTest::setUpBeforeClass()
*
* @return void
*/
public static function setUpBeforeClass() {
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'FixturizedTestCase.php';
@ -56,24 +102,31 @@ class CakeTestCaseTest extends CakeTestCase {
}
/**
* testAssertGoodTags
* testAssertTags
*
* @return void
*/
public function testAssertTagsQuotes() {
public function testAssertTagsBasic() {
$test = new AssertTagsTestCase('testAssertTagsQuotes');
$result = $test->run();
$this->assertEquals(0, $result->errorCount());
$this->assertTrue($result->wasSuccessful());
$this->assertEquals(0, $result->failureCount());
}
/**
* test assertTags works with single and double quotes
*
* @return void
*/
public function testAssertTagsQuoting() {
$input = '<a href="/test.html" class="active">My link</a>';
$pattern = array(
'a' => array('href' => '/test.html', 'class' => 'active'),
'My link',
'/a'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Double quoted attributes %s');
$this->assertTags($input, $pattern);
$input = "<a href='/test.html' class='active'>My link</a>";
$pattern = array(
@ -81,7 +134,7 @@ class CakeTestCaseTest extends CakeTestCase {
'My link',
'/a'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
$this->assertTags($input, $pattern);
$input = "<a href='/test.html' class='active'>My link</a>";
$pattern = array(
@ -89,7 +142,7 @@ class CakeTestCaseTest extends CakeTestCase {
'My link',
'/a'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
$this->assertTags($input, $pattern);
$input = "<span><strong>Text</strong></span>";
$pattern = array(
@ -99,7 +152,7 @@ class CakeTestCaseTest extends CakeTestCase {
'/strong',
'/span'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Tags with no attributes');
$this->assertTags($input, $pattern);
$input = "<span class='active'><strong>Text</strong></span>";
$pattern = array(
@ -109,7 +162,34 @@ class CakeTestCaseTest extends CakeTestCase {
'/strong',
'/span'
);
$this->assertTrue($test->assertTags($input, $pattern), 'Test attribute presence');
$this->assertTags($input, $pattern);
}
/**
* Test that assertTags runs quickly.
*
* @return void
*/
public function testAssertTagsRuntimeComplexity() {
$pattern = array(
'div' => array(
'attr1' => 'val1',
'attr2' => 'val2',
'attr3' => 'val3',
'attr4' => 'val4',
'attr5' => 'val5',
'attr6' => 'val6',
'attr7' => 'val7',
'attr8' => 'val8',
),
'My div',
'/div'
);
$input = '<div attr8="val8" attr6="val6" attr4="val4" attr2="val2"' .
' attr1="val1" attr3="val3" attr5="val5" attr7="val7" />' .
'My div' .
'</div>';
$this->assertTags($input, $pattern);
}
/**
@ -264,7 +344,6 @@ class CakeTestCaseTest extends CakeTestCase {
*/
public function testAssertTextStartsWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertStringStartsWith("some\nstring", $stringDirty);
$this->assertStringStartsNotWith("some\r\nstring\r\nwith", $stringDirty);
@ -281,8 +360,6 @@ class CakeTestCaseTest extends CakeTestCase {
*/
public function testAssertTextStartsNotWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertTextStartsNotWith("some\nstring\nwithout", $stringDirty);
}
@ -293,8 +370,6 @@ class CakeTestCaseTest extends CakeTestCase {
*/
public function testAssertTextEndsWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertTextEndsWith("string\nwith\r\ndifferent\rline endings!", $stringDirty);
$this->assertTextEndsWith("string\r\nwith\ndifferent\nline endings!", $stringDirty);
}
@ -306,8 +381,6 @@ class CakeTestCaseTest extends CakeTestCase {
*/
public function testAssertTextEndsNotWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertStringEndsNotWith("different\nline endings", $stringDirty);
$this->assertTextEndsNotWith("different\rline endings", $stringDirty);
}
@ -319,11 +392,8 @@ class CakeTestCaseTest extends CakeTestCase {
*/
public function testAssertTextContains() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertContains("different", $stringDirty);
$this->assertNotContains("different\rline", $stringDirty);
$this->assertTextContains("different\rline", $stringDirty);
}
@ -334,9 +404,126 @@ class CakeTestCaseTest extends CakeTestCase {
*/
public function testAssertTextNotContains() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertTextNotContains("different\rlines", $stringDirty);
}
/**
* test getMockForModel()
*
* @return void
*/
public function testGetMockForModel() {
App::build(array(
'Model' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS
)
), App::RESET);
$Post = $this->getMockForModel('Post');
$this->assertEquals('test', $Post->useDbConfig);
$this->assertInstanceOf('Post', $Post);
$this->assertNull($Post->save(array()));
$this->assertNull($Post->find('all'));
$this->assertEquals('posts', $Post->useTable);
$Post = $this->getMockForModel('Post', array('save'));
$this->assertNull($Post->save(array()));
$this->assertInternalType('array', $Post->find('all'));
}
/**
* Test getMockForModel on secondary datasources.
*
* @return void
*/
public function testGetMockForModelSecondaryDatasource() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
'Model/Datasource/Database' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS . 'Datasource' . DS . 'Database' . DS
)
), App::RESET);
CakePlugin::load('TestPlugin');
ConnectionManager::create('test_secondary', array(
'datasource' => 'Database/TestLocalDriver'
));
$post = $this->getMockForModel('SecondaryPost', array('save'));
$this->assertEquals('test_secondary', $post->useDbConfig);
ConnectionManager::drop('test_secondary');
}
/**
* Test getMockForModel when the model accesses the datasource in the constructor.
*
* @return void
*/
public function testGetMockForModelConstructorDatasource() {
$post = $this->getMockForModel('ConstructorPost', array('save'), array('ds' => 'test'));
$this->assertEquals('test', $post->useDbConfig);
}
/**
* test getMockForModel() with plugin models
*
* @return void
*/
public function testGetMockForModelWithPlugin() {
App::build(array(
'Plugin' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
)
), App::RESET);
CakePlugin::load('TestPlugin');
$this->getMockForModel('TestPlugin.TestPluginAppModel');
$this->getMockForModel('TestPlugin.TestPluginComment');
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
$this->assertInstanceOf('TestPluginComment', $result);
$this->assertEquals('test', $result->useDbConfig);
$TestPluginComment = $this->getMockForModel('TestPlugin.TestPluginComment', array('save'));
$this->assertInstanceOf('TestPluginComment', $TestPluginComment);
$TestPluginComment->expects($this->at(0))
->method('save')
->will($this->returnValue(true));
$TestPluginComment->expects($this->at(1))
->method('save')
->will($this->returnValue(false));
$this->assertTrue($TestPluginComment->save(array()));
$this->assertFalse($TestPluginComment->save(array()));
}
/**
* testGetMockForModelModel
*
* @return void
*/
public function testGetMockForModelModel() {
$Mock = $this->getMockForModel('Model', array('save', 'setDataSource'), array('name' => 'Comment'));
$result = ClassRegistry::init('Comment');
$this->assertInstanceOf('Model', $result);
$Mock->expects($this->at(0))
->method('save')
->will($this->returnValue(true));
$Mock->expects($this->at(1))
->method('save')
->will($this->returnValue(false));
$this->assertTrue($Mock->save(array()));
$this->assertFalse($Mock->save(array()));
}
/**
* testGetMockForModelDoesNotExist
*
* @expectedException MissingModelException
* @expectedExceptionMessage Model IDoNotExist could not be found
* @return void
*/
public function testGetMockForModelDoesNotExist() {
$this->getMockForModel('IDoNotExist');
}
}

View file

@ -2,20 +2,20 @@
/**
* CakeTestFixture file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* 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 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.TestSuite
* @since CakePHP(tm) v 1.2.0.4667
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DboSource', 'Model/Datasource');
App::uses('Model', 'Model');
App::uses('CakeTestFixture', 'TestSuite/Fixture');
@ -47,7 +47,7 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'length' => '255'),
'created' => array('type' => 'datetime')
);
@ -65,10 +65,9 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
}
/**
* StringFieldsTestFixture class
* StringTestFixture class
*
* @package Cake.Test.Case.TestSuite
* @subpackage cake.cake.tests.cases.libs
*/
class StringsTestFixture extends CakeTestFixture {
@ -92,7 +91,7 @@ class StringsTestFixture extends CakeTestFixture {
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'length' => '255'),
'email' => array('type' => 'string', 'length' => '255'),
'age' => array('type' => 'integer', 'default' => 10)
@ -110,6 +109,49 @@ class StringsTestFixture extends CakeTestFixture {
);
}
/**
* InvalidTestFixture class
*
* @package Cake.Test.Case.TestSuite
*/
class InvalidTestFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
public $name = 'Invalid';
/**
* Table property
*
* @var string
*/
public $table = 'invalid';
/**
* Fields array - missing "email" row
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'length' => '255'),
'age' => array('type' => 'integer', 'default' => 10)
);
/**
* Records property
*
* @var array
*/
public $records = array(
array('name' => 'Mark Doe', 'email' => 'mark.doe@email.com'),
array('name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20),
array('email' => 'jane.doe@email.com', 'name' => 'Jane Doe', 'age' => 30)
);
}
/**
* CakeTestFixtureImportFixture class
@ -152,7 +194,6 @@ class CakeTestFixtureDefaultImportFixture extends CakeTestFixture {
* FixtureImportTestModel class
*
* @package Cake.Test.Case.TestSuite
* @package Cake.Test.Case.TestSuite
*/
class FixtureImportTestModel extends Model {
@ -175,7 +216,6 @@ class FixturePrefixTest extends Model {
public $useDbConfig = 'test';
}
/**
* Test case for CakeTestFixture
*
@ -189,6 +229,7 @@ class CakeTestFixtureTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
$methods = array_diff(get_class_methods('DboSource'), array('enabled'));
$methods[] = 'connect';
@ -204,6 +245,7 @@ class CakeTestFixtureTest extends CakeTestCase {
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->criticDb);
$this->db->config = $this->_backupConfig;
}
@ -352,7 +394,7 @@ class CakeTestFixtureTest extends CakeTestCase {
}
/**
* test that importing with records works. Make sure to try with postgres as its
* test that importing with records works. Make sure to try with postgres as its
* handling of aliases is a workaround at best.
*
* @return void
@ -429,12 +471,16 @@ class CakeTestFixtureTest extends CakeTestCase {
* @param string $table
* @param string $fields
* @param string $values
* @return boolean true
* @return bool true
*/
public function insertCallback($table, $fields, $values) {
$this->insertMulti['table'] = $table;
$this->insertMulti['fields'] = $fields;
$this->insertMulti['values'] = $values;
$this->insertMulti['fields_values'] = array();
foreach ($values as $record) {
$this->insertMulti['fields_values'][] = array_combine($fields, $record);
}
return true;
}
@ -453,13 +499,42 @@ class CakeTestFixtureTest extends CakeTestCase {
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
$this->assertEquals('strings', $this->insertMulti['table']);
$this->assertEquals(array('email', 'name', 'age'), $this->insertMulti['fields']);
$this->assertEquals(array('name', 'email', 'age'), array_values($this->insertMulti['fields']));
$expected = array(
array('Mark Doe', 'mark.doe@email.com', null),
array('John Doe', 'john.doe@email.com', 20),
array('Jane Doe', 'jane.doe@email.com', 30),
);
$this->assertEquals($expected, $this->insertMulti['values']);
$expected = array(
array(
'name' => 'Mark Doe',
'email' => 'mark.doe@email.com',
'age' => null
),
array(
'name' => 'John Doe',
'email' => 'john.doe@email.com',
'age' => 20
),
array(
'name' => 'Jane Doe',
'email' => 'jane.doe@email.com',
'age' => 30
),
);
$this->assertEquals($expected, $this->insertMulti['fields_values']);
}
/**
* test the insert method with invalid fixture
*
* @expectedException CakeException
* @return void
*/
public function testInsertInvalid() {
$Fixture = new InvalidTestFixture();
$Fixture->insert($this->criticDb);
}
/**

View file

@ -1,16 +1,17 @@
<?php
/**
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc.
* 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 2005-2012, Cake Software Foundation, Inc.
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
@ -61,7 +62,7 @@ class CakeTestSuiteTest extends CakeTestCase {
* @return void
*/
public function testAddTestDirectoryRecursiveWithHidden() {
$this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
$this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
mkdir($Folder->path . DS . '.svn', 0777, true);
@ -85,7 +86,7 @@ class CakeTestSuiteTest extends CakeTestCase {
* @return void
*/
public function testAddTestDirectoryRecursiveWithNonPhp() {
$this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
$this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
touch($Folder->path . DS . 'BackupTest.php~');

View file

@ -4,19 +4,18 @@
*
* Test Case for ControllerTestCase class
*
* PHP version 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc.
* 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 2005-2012, Cake Software Foundation, Inc.
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
@ -26,11 +25,6 @@ App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
/**
* AppController class
*
* @package Cake.Test.Case.TestSuite
*/
if (!class_exists('AppController', false)) {
/**
* AppController class
@ -43,7 +37,6 @@ if (!class_exists('AppController', false)) {
* helpers property
*
* @var array
* @access public
*/
public $helpers = array('Html');
@ -51,7 +44,6 @@ if (!class_exists('AppController', false)) {
* uses property
*
* @var array
* @access public
*/
public $uses = array('ControllerPost');
@ -59,7 +51,6 @@ if (!class_exists('AppController', false)) {
* components property
*
* @var array
* @access public
*/
public $components = array('Cookie');
@ -72,6 +63,12 @@ if (!class_exists('AppController', false)) {
* PostsController class
*/
if (!class_exists('PostsController')) {
/**
* PostsController
*
* @package Cake.Test.Case.TestSuite
*/
class PostsController extends AppController {
/**
@ -89,6 +86,8 @@ if (!class_exists('PostsController')) {
/**
* ControllerTestCaseTest controller
*
* @package Cake.Test.Case.TestSuite
*/
class ControllerTestCaseTestController extends AppController {
@ -146,6 +145,8 @@ class ControllerTestCaseTest extends CakeTestCase {
/**
* Test that ControllerTestCase::generate() creates mock objects correctly
*
* @return void
*/
public function testGenerate() {
if (defined('APP_CONTROLLER_EXISTS')) {
@ -209,8 +210,34 @@ class ControllerTestCaseTest extends CakeTestCase {
$this->assertEquals('written!', $Posts->Auth->Session->write('something'));
}
/**
* testGenerateWithComponentConfig
*
* @return void
*/
public function testGenerateWithComponentConfig() {
$Tests = $this->Case->generate('TestConfigs', array(
));
$expected = array('some' => 'config');
$settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo'));
$this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component');
$Tests = $this->Case->generate('TestConfigs', array(
'components' => array(
'RequestHandler' => array('isPut')
)
));
$expected = array('some' => 'config');
$settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo'));
$this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component');
}
/**
* Tests ControllerTestCase::generate() using classes from plugins
*
* @return void
*/
public function testGenerateWithPlugin() {
$Tests = $this->Case->generate('TestPlugin.Tests', array(
@ -245,9 +272,11 @@ class ControllerTestCaseTest extends CakeTestCase {
/**
* Tests testAction
*
* @return void
*/
public function testTestAction() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->generate('TestsApps');
$this->Case->testAction('/tests_apps/index');
$this->assertInternalType('array', $this->Case->controller->viewVars);
@ -268,6 +297,30 @@ class ControllerTestCaseTest extends CakeTestCase {
'Location' => 'http://cakephp.org'
);
$this->assertEquals($expected, $results);
$this->assertSame(302, $Controller->response->statusCode());
}
/**
* Test array URLs with testAction()
*
* @return void
*/
public function testTestActionArrayUrls() {
$this->Case->generate('TestsApps');
$this->Case->testAction(array('controller' => 'tests_apps', 'action' => 'index'));
$this->assertInternalType('array', $this->Case->controller->viewVars);
}
/**
* Test that file responses don't trigger errors.
*
* @return void
*/
public function testActionWithFile() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->testAction('/tests_apps/file');
$this->assertArrayHasKey('Content-Disposition', $Controller->response->header());
$this->assertArrayHasKey('Content-Length', $Controller->response->header());
}
/**
@ -276,7 +329,7 @@ class ControllerTestCaseTest extends CakeTestCase {
* @return void
*/
public function testTestActionWithPlugin() {
$Controller = $this->Case->generate('TestPlugin.Tests');
$this->Case->generate('TestPlugin.Tests');
$this->Case->testAction('/test_plugin/tests/index');
$this->assertEquals('It is a variable', $this->Case->controller->viewVars['test_value']);
}
@ -306,17 +359,20 @@ class ControllerTestCaseTest extends CakeTestCase {
* Tests not using loaded routes during tests
*
* @expectedException MissingActionException
* @return void
*/
public function testSkipRoutes() {
Router::connect('/:controller/:action/*');
include CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'routes.php';
$this->Case->loadRoutes = false;
$result = $this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
$this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
}
/**
* Tests backwards compatibility with setting the return type
*
* @return void
*/
public function testBCSetReturn() {
$this->Case->autoMock = true;
@ -346,6 +402,8 @@ class ControllerTestCaseTest extends CakeTestCase {
/**
* Tests sending POST data to testAction
*
* @return void
*/
public function testTestActionPostData() {
$this->Case->autoMock = true;
@ -388,11 +446,13 @@ class ControllerTestCaseTest extends CakeTestCase {
/**
* Tests sending GET data to testAction
*
* @return void
*/
public function testTestActionGetData() {
$this->Case->autoMock = true;
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
$this->Case->testAction('/tests_apps_posts/url_var', array(
'method' => 'get',
'data' => array(
'some' => 'var',
@ -414,7 +474,7 @@ class ControllerTestCaseTest extends CakeTestCase {
));
$this->assertEquals(array('gogo', 'val2'), $result['params']['pass']);
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
$this->Case->testAction('/tests_apps_posts/url_var', array(
'return' => 'vars',
'method' => 'get',
'data' => array(
@ -444,6 +504,8 @@ class ControllerTestCaseTest extends CakeTestCase {
/**
* Tests autoMock ability
*
* @return void
*/
public function testAutoMock() {
$this->Case->autoMock = true;
@ -457,6 +519,8 @@ class ControllerTestCaseTest extends CakeTestCase {
/**
* Test using testAction and not mocking
*
* @return void
*/
public function testNoMocking() {
$result = $this->Case->testAction('/tests_apps/some_method');
@ -520,7 +584,7 @@ class ControllerTestCaseTest extends CakeTestCase {
* @return void
*/
public function testTestActionWithMultipleRedirect() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->generate('TestsApps');
$options = array('method' => 'get');
$this->Case->testAction('/tests_apps/redirect_to', $options);
@ -532,7 +596,6 @@ class ControllerTestCaseTest extends CakeTestCase {
* will always have a fresh reference to those object available
*
* @return void
* @see http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2705-requesthandler-weird-behavior
*/
public function testComponentsSameRequestAndResponse() {
$this->Case->generate('TestsApps');

View file

@ -0,0 +1,103 @@
<?php
/**
* CakeFixtureManager file
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* 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://cakephp.org CakePHP Project
* @package Cake.Test.Case.TestSuite.Fixture
* @since CakePHP v 2.5
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DboSource', 'Model/Datasource');
App::uses('CakeFixtureManager', 'TestSuite/Fixture');
App::uses('UuidFixture', 'Test/Fixture');
/**
* Test Case for CakeFixtureManager class
*
* @package Cake.Test.Case.TestSuite
*/
class CakeFixtureManagerTest extends CakeTestCase {
/**
* reset environment.
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->fixtureManager = new CakeFixtureManager();
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->fixtureManager);
}
/**
* testLoadTruncatesTable
*
* @return void
*/
public function testLoadTruncatesTable() {
$MockFixture = $this->getMock('UuidFixture', array('truncate'));
$MockFixture
->expects($this->once())
->method('truncate')
->will($this->returnValue(true));
$fixtureManager = $this->fixtureManager;
$fixtureManagerReflection = new ReflectionClass($fixtureManager);
$loadedProperty = $fixtureManagerReflection->getProperty('_loaded');
$loadedProperty->setAccessible(true);
$loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture));
$TestCase = $this->getMock('CakeTestCase');
$TestCase->fixtures = array('core.uuid');
$TestCase->autoFixtures = true;
$TestCase->dropTables = false;
$fixtureManager->load($TestCase);
}
/**
* testLoadSingleTruncatesTable
*
* @return void
*/
public function testLoadSingleTruncatesTable() {
$MockFixture = $this->getMock('UuidFixture', array('truncate'));
$MockFixture
->expects($this->once())
->method('truncate')
->will($this->returnValue(true));
$fixtureManager = $this->fixtureManager;
$fixtureManagerReflection = new ReflectionClass($fixtureManager);
$fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap');
$fixtureMapProperty->setAccessible(true);
$fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture));
$dboMethods = array_diff(get_class_methods('DboSource'), array('enabled'));
$dboMethods[] = 'connect';
$db = $this->getMock('DboSource', $dboMethods);
$db->config['prefix'] = '';
$fixtureManager->loadSingle('Uuid', $db, false);
}
}

View file

@ -5,21 +5,27 @@
* PHP5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* 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 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.TestSuite
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('HtmlCoverageReport', 'TestSuite/Coverage');
App::uses('CakeBaseReporter', 'TestSuite/Reporter');
/**
* HtmlCoverageReportTest
*
* @package Cake.Test.Case.TestSuite
*/
class HtmlCoverageReportTest extends CakeTestCase {
/**
@ -113,7 +119,7 @@ class HtmlCoverageReportTest extends CakeTestCase {
);
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php-' . md5('myfile.php') . '"/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
@ -121,7 +127,7 @@ class HtmlCoverageReportTest extends CakeTestCase {
if (in_array($i + 1, array(5, 9, 2))) {
$class = 'uncovered';
}
if ($i + 1 == 2) {
if ($i + 1 === 2) {
$class .= ' dead';
}
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);
@ -161,7 +167,7 @@ class HtmlCoverageReportTest extends CakeTestCase {
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php"/', $result);
$this->assertRegExp('/<div class="code-coverage-results" id\="coverage\-myfile\.php-' . md5('myfile.php') . '"/', $result);
$this->assertRegExp('/<pre>/', $result);
foreach ($file as $i => $line) {
$this->assertTrue(strpos($line, $result) !== 0, 'Content is missing ' . $i);
@ -169,7 +175,7 @@ class HtmlCoverageReportTest extends CakeTestCase {
if (in_array($i + 1, array(5, 9, 2))) {
$class = 'uncovered';
}
if ($i + 1 == 2) {
if ($i + 1 === 2) {
$class .= ' dead';
}
$this->assertTrue(strpos($class, $result) !== 0, 'Class name is wrong ' . $i);

View file

@ -0,0 +1,62 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* 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://cakephp.org CakePHP(tm) Project
* @since 2.8
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses("ConsoleOutputStub", "TestSuite/Stub");
/*
* ConsoleOutputStub test
*/
class ConsoleOutputStubTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->stub = new ConsoleOutputStub();
}
/**
* Test that stub can be used as an instance of ConsoleOutput
*
* @return void
*/
public function testCanActAsConsoleOutput() {
$this->assertInstanceOf("ConsoleOutput", $this->stub);
}
/**
* Test write method
*
* @return void
*/
public function testWrite() {
$this->stub->write(array("foo", "bar", "baz"));
$this->assertEquals(array("foo", "bar", "baz"), $this->stub->messages());
}
/**
* Test overwrite method
*
* @return void
*/
public function testOverwrite() {
$this->stub->write(array("foo", "bar", "baz"));
$this->stub->overwrite("bat");
$this->assertEquals(array("foo", "bar", "baz", "", "bat"), $this->stub->messages());
}
}