2008-08-23 17:28:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* CakeTestCaseTest file
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* Test Case for CakeTestCase class
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 12:28:17 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-08-23 17:28:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 12:28:17 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.TestSuite
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP v 1.2.0.4487
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-08-23 17:28:08 +00:00
|
|
|
*/
|
2014-10-13 02:14:47 +00:00
|
|
|
App::uses('CakePlugin', 'Core');
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
2014-10-13 02:14:47 +00:00
|
|
|
App::uses('Model', 'Model');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Secondary Post stub class.
|
|
|
|
*/
|
|
|
|
class SecondaryPost extends Model {
|
2014-10-14 01:05:33 +00:00
|
|
|
|
2014-10-13 02:14:47 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $useTable = 'posts';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $useDbConfig = 'secondary';
|
2014-10-14 01:05:33 +00:00
|
|
|
|
2014-10-13 02:14:47 +00:00
|
|
|
}
|
2010-12-09 05:13:11 +00:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* CakeTestCaseTest
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.TestSuite
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2008-08-23 17:28:08 +00:00
|
|
|
class CakeTestCaseTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-11-13 01:10:53 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
|
|
|
|
|
2014-04-02 01:02:37 +00:00
|
|
|
/**
|
|
|
|
* CakeTestCaseTest::setUpBeforeClass()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-08 05:49:45 +00:00
|
|
|
public static function setUpBeforeClass() {
|
2011-04-17 10:35:21 +00:00
|
|
|
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
|
|
|
|
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'FixturizedTestCase.php';
|
2010-05-08 05:49:45 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* setUp
|
2008-10-15 19:14:11 +00:00
|
|
|
*
|
2008-08-23 17:28:08 +00:00
|
|
|
* @return void
|
2008-10-15 19:14:11 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2011-08-30 02:07:23 +00:00
|
|
|
parent::setUp();
|
2010-05-06 03:12:56 +00:00
|
|
|
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2011-08-30 02:07:23 +00:00
|
|
|
parent::tearDown();
|
2010-05-06 03:12:56 +00:00
|
|
|
unset($this->Result);
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
2014-03-22 01:24:10 +00:00
|
|
|
* testAssertTags
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2010-04-05 01:43:29 +00:00
|
|
|
*/
|
2014-03-22 01:24:10 +00:00
|
|
|
public function testAssertTagsBasic() {
|
2010-05-08 05:49:45 +00:00
|
|
|
$test = new AssertTagsTestCase('testAssertTagsQuotes');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertTrue($result->wasSuccessful());
|
|
|
|
$this->assertEquals(0, $result->failureCount());
|
2014-03-22 01:24:10 +00:00
|
|
|
}
|
2010-11-17 02:48:13 +00:00
|
|
|
|
2014-03-22 01:24:10 +00:00
|
|
|
/**
|
|
|
|
* test assertTags works with single and double quotes
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssertTagsQuoting() {
|
2010-04-05 01:43:29 +00:00
|
|
|
$input = '<a href="/test.html" class="active">My link</a>';
|
|
|
|
$pattern = array(
|
|
|
|
'a' => array('href' => '/test.html', 'class' => 'active'),
|
|
|
|
'My link',
|
|
|
|
'/a'
|
|
|
|
);
|
2014-03-22 01:24:10 +00:00
|
|
|
$this->assertTags($input, $pattern);
|
2010-04-05 01:43:29 +00:00
|
|
|
|
|
|
|
$input = "<a href='/test.html' class='active'>My link</a>";
|
|
|
|
$pattern = array(
|
|
|
|
'a' => array('href' => '/test.html', 'class' => 'active'),
|
|
|
|
'My link',
|
|
|
|
'/a'
|
|
|
|
);
|
2014-03-22 01:24:10 +00:00
|
|
|
$this->assertTags($input, $pattern);
|
2010-11-10 18:35:00 +00:00
|
|
|
|
2010-04-05 01:43:29 +00:00
|
|
|
$input = "<a href='/test.html' class='active'>My link</a>";
|
|
|
|
$pattern = array(
|
|
|
|
'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
|
|
|
|
'My link',
|
|
|
|
'/a'
|
|
|
|
);
|
2014-03-22 01:24:10 +00:00
|
|
|
$this->assertTags($input, $pattern);
|
2011-08-21 14:28:36 +00:00
|
|
|
|
|
|
|
$input = "<span><strong>Text</strong></span>";
|
|
|
|
$pattern = array(
|
|
|
|
'<span',
|
|
|
|
'<strong',
|
|
|
|
'Text',
|
|
|
|
'/strong',
|
|
|
|
'/span'
|
|
|
|
);
|
2014-03-22 01:24:10 +00:00
|
|
|
$this->assertTags($input, $pattern);
|
2011-08-21 14:28:36 +00:00
|
|
|
|
|
|
|
$input = "<span class='active'><strong>Text</strong></span>";
|
|
|
|
$pattern = array(
|
|
|
|
'span' => array('class'),
|
|
|
|
'<strong',
|
|
|
|
'Text',
|
|
|
|
'/strong',
|
|
|
|
'/span'
|
|
|
|
);
|
2014-03-22 01:24:10 +00:00
|
|
|
$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);
|
2010-04-05 01:43:29 +00:00
|
|
|
}
|
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
2009-10-28 18:14:50 +00:00
|
|
|
* testNumericValuesInExpectationForAssertTags
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNumericValuesInExpectationForAssertTags() {
|
2010-05-08 05:49:45 +00:00
|
|
|
$test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertTrue($result->wasSuccessful());
|
|
|
|
$this->assertEquals(0, $result->failureCount());
|
2009-10-28 18:14:50 +00:00
|
|
|
}
|
2009-12-02 16:37:43 +00:00
|
|
|
|
2010-05-08 05:49:45 +00:00
|
|
|
/**
|
2008-08-23 17:28:08 +00:00
|
|
|
* testBadAssertTags
|
2008-10-15 19:14:11 +00:00
|
|
|
*
|
2008-08-23 17:28:08 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBadAssertTags() {
|
2010-05-08 05:49:45 +00:00
|
|
|
$test = new AssertTagsTestCase('testBadAssertTags');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertFalse($result->wasSuccessful());
|
|
|
|
$this->assertEquals(1, $result->failureCount());
|
2008-10-15 19:14:11 +00:00
|
|
|
|
2010-05-08 05:49:45 +00:00
|
|
|
$test = new AssertTagsTestCase('testBadAssertTags2');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertFalse($result->wasSuccessful());
|
|
|
|
$this->assertEquals(1, $result->failureCount());
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* testLoadFixtures
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadFixtures() {
|
2010-05-08 05:49:45 +00:00
|
|
|
$test = new FixturizedTestCase('testFixturePresent');
|
2010-05-08 20:26:21 +00:00
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-28 04:07:56 +00:00
|
|
|
$test->fixtureManager = $manager;
|
2010-05-08 20:26:21 +00:00
|
|
|
$manager->expects($this->once())->method('load');
|
|
|
|
$manager->expects($this->once())->method('unload');
|
2010-05-08 05:49:45 +00:00
|
|
|
$result = $test->run();
|
2010-05-08 20:26:21 +00:00
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertTrue($result->wasSuccessful());
|
|
|
|
$this->assertEquals(0, $result->failureCount());
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
2010-05-08 20:44:22 +00:00
|
|
|
* testLoadFixturesOnDemand
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadFixturesOnDemand() {
|
2010-05-08 20:44:22 +00:00
|
|
|
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
|
|
|
$test->autoFixtures = false;
|
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-28 04:07:56 +00:00
|
|
|
$test->fixtureManager = $manager;
|
2010-05-08 20:44:22 +00:00
|
|
|
$manager->expects($this->once())->method('loadSingle');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
2008-09-09 05:36:18 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-01 03:37:21 +00:00
|
|
|
/**
|
|
|
|
* testLoadFixturesOnDemand
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUnoadFixturesAfterFailure() {
|
2010-06-01 03:37:21 +00:00
|
|
|
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
|
|
|
$test->autoFixtures = false;
|
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-28 04:07:56 +00:00
|
|
|
$test->fixtureManager = $manager;
|
2010-06-01 03:37:21 +00:00
|
|
|
$manager->expects($this->once())->method('loadSingle');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testThrowException
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testThrowException() {
|
2010-06-01 03:37:21 +00:00
|
|
|
$test = new FixturizedTestCase('testThrowException');
|
|
|
|
$test->autoFixtures = false;
|
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-28 04:07:56 +00:00
|
|
|
$test->fixtureManager = $manager;
|
2010-06-01 03:37:21 +00:00
|
|
|
$manager->expects($this->once())->method('unload');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(1, $result->errorCount());
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* testSkipIf
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSkipIf() {
|
2010-05-08 21:06:11 +00:00
|
|
|
$test = new FixturizedTestCase('testSkipIfTrue');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(1, $result->skippedCount());
|
2008-10-15 19:14:11 +00:00
|
|
|
|
2010-05-08 21:06:11 +00:00
|
|
|
$test = new FixturizedTestCase('testSkipIfFalse');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->skippedCount());
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|
2011-08-30 02:07:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that CakeTestCase::setUp() backs up values.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetupBackUpValues() {
|
|
|
|
$this->assertArrayHasKey('debug', $this->_configure);
|
2011-09-13 03:25:13 +00:00
|
|
|
$this->assertArrayHasKey('Plugin', $this->_pathRestore);
|
2011-08-30 02:07:23 +00:00
|
|
|
}
|
2012-01-25 02:08:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test assertTextNotEquals()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssertTextNotEquals() {
|
|
|
|
$one = "\r\nOne\rTwooo";
|
|
|
|
$two = "\nOne\nTwo";
|
|
|
|
$this->assertTextNotEquals($one, $two);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test assertTextEquals()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssertTextEquals() {
|
|
|
|
$one = "\r\nOne\rTwo";
|
|
|
|
$two = "\nOne\nTwo";
|
|
|
|
$this->assertTextEquals($one, $two);
|
|
|
|
}
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
/**
|
|
|
|
* test assertTextStartsWith()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssertTextStartsWith() {
|
|
|
|
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
|
|
|
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
$this->assertStringStartsWith("some\nstring", $stringDirty);
|
|
|
|
$this->assertStringStartsNotWith("some\r\nstring\r\nwith", $stringDirty);
|
|
|
|
$this->assertStringStartsNotWith("some\nstring\nwith", $stringDirty);
|
|
|
|
|
|
|
|
$this->assertTextStartsWith("some\nstring\nwith", $stringDirty);
|
|
|
|
$this->assertTextStartsWith("some\r\nstring\r\nwith", $stringDirty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test assertTextStartsNotWith()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssertTextStartsNotWith() {
|
|
|
|
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
|
|
|
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
$this->assertTextStartsNotWith("some\nstring\nwithout", $stringDirty);
|
|
|
|
}
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
/**
|
|
|
|
* test assertTextEndsWith()
|
|
|
|
*
|
|
|
|
* @return void
|
2012-03-18 21:31:53 +00:00
|
|
|
*/
|
2012-02-17 22:36:57 +00:00
|
|
|
public function testAssertTextEndsWith() {
|
|
|
|
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
|
|
|
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
$this->assertTextEndsWith("string\nwith\r\ndifferent\rline endings!", $stringDirty);
|
|
|
|
$this->assertTextEndsWith("string\r\nwith\ndifferent\nline endings!", $stringDirty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test assertTextEndsNotWith()
|
|
|
|
*
|
|
|
|
* @return void
|
2012-03-18 21:31:53 +00:00
|
|
|
*/
|
2012-02-17 22:36:57 +00:00
|
|
|
public function testAssertTextEndsNotWith() {
|
|
|
|
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
|
|
|
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
$this->assertStringEndsNotWith("different\nline endings", $stringDirty);
|
|
|
|
$this->assertTextEndsNotWith("different\rline endings", $stringDirty);
|
|
|
|
}
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
/**
|
|
|
|
* test assertTextContains()
|
|
|
|
*
|
|
|
|
* @return void
|
2012-03-18 21:31:53 +00:00
|
|
|
*/
|
2012-02-17 22:36:57 +00:00
|
|
|
public function testAssertTextContains() {
|
|
|
|
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
|
|
|
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
$this->assertContains("different", $stringDirty);
|
|
|
|
$this->assertNotContains("different\rline", $stringDirty);
|
2012-03-18 21:31:53 +00:00
|
|
|
|
|
|
|
$this->assertTextContains("different\rline", $stringDirty);
|
2012-02-17 22:36:57 +00:00
|
|
|
}
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-02-17 22:36:57 +00:00
|
|
|
/**
|
|
|
|
* test assertTextNotContains()
|
|
|
|
*
|
|
|
|
* @return void
|
2012-03-18 21:31:53 +00:00
|
|
|
*/
|
2012-02-17 22:36:57 +00:00
|
|
|
public function testAssertTextNotContains() {
|
|
|
|
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
|
|
|
|
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
|
2012-03-18 21:31:53 +00:00
|
|
|
|
|
|
|
$this->assertTextNotContains("different\rlines", $stringDirty);
|
2012-02-17 22:36:57 +00:00
|
|
|
}
|
2012-03-18 21:31:53 +00:00
|
|
|
|
2012-11-13 01:10:53 +00:00
|
|
|
/**
|
|
|
|
* test getMockForModel()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetMockForModel() {
|
2013-08-03 12:20:12 +00:00
|
|
|
App::build(array(
|
2014-10-13 02:14:47 +00:00
|
|
|
'Model' => array(
|
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS
|
|
|
|
)
|
2013-08-03 12:20:12 +00:00
|
|
|
), App::RESET);
|
2012-11-13 01:10:53 +00:00
|
|
|
$Post = $this->getMockForModel('Post');
|
2015-02-27 14:25:23 +00:00
|
|
|
$this->assertEquals('test', $Post->useDbConfig);
|
2012-11-13 01:10:53 +00:00
|
|
|
$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'));
|
|
|
|
}
|
|
|
|
|
2014-10-13 02:14:47 +00:00
|
|
|
/**
|
|
|
|
* 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');
|
2014-10-14 01:05:33 +00:00
|
|
|
ConnectionManager::create('test_secondary', array(
|
2014-10-13 02:14:47 +00:00
|
|
|
'datasource' => 'Database/TestLocalDriver'
|
2014-10-14 01:05:33 +00:00
|
|
|
));
|
2014-10-13 02:14:47 +00:00
|
|
|
$post = $this->getMockForModel('SecondaryPost', array('save'));
|
|
|
|
$this->assertEquals('test_secondary', $post->useDbConfig);
|
|
|
|
ConnectionManager::drop('test_secondary');
|
|
|
|
}
|
|
|
|
|
2012-11-13 01:10:53 +00:00
|
|
|
/**
|
|
|
|
* test getMockForModel() with plugin models
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetMockForModelWithPlugin() {
|
2013-08-03 12:20:12 +00:00
|
|
|
App::build(array(
|
2014-10-13 02:14:47 +00:00
|
|
|
'Plugin' => array(
|
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
|
|
|
)
|
2013-08-03 12:20:12 +00:00
|
|
|
), App::RESET);
|
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
$this->getMockForModel('TestPlugin.TestPluginAppModel');
|
2012-11-13 01:10:53 +00:00
|
|
|
$TestPluginComment = $this->getMockForModel('TestPlugin.TestPluginComment');
|
|
|
|
|
|
|
|
$result = ClassRegistry::init('TestPlugin.TestPluginComment');
|
|
|
|
$this->assertInstanceOf('TestPluginComment', $result);
|
2014-10-13 02:14:47 +00:00
|
|
|
$this->assertEquals('test', $result->useDbConfig);
|
2012-11-13 01:10:53 +00:00
|
|
|
|
|
|
|
$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()));
|
|
|
|
}
|
2013-08-03 12:20:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testGetMockForModelModel
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetMockForModelModel() {
|
2014-10-13 02:14:47 +00:00
|
|
|
$Mock = $this->getMockForModel('Model', array('save', 'setDataSource'), array('name' => 'Comment'));
|
2013-08-03 12:20:12 +00:00
|
|
|
|
|
|
|
$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()));
|
|
|
|
}
|
2013-08-03 14:46:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testGetMockForModelDoesNotExist
|
|
|
|
*
|
|
|
|
* @expectedException MissingModelException
|
|
|
|
* @expectedExceptionMessage Model IDoNotExist could not be found
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetMockForModelDoesNotExist() {
|
|
|
|
$this->getMockForModel('IDoNotExist');
|
|
|
|
}
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|