123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- <?php
- /**
- * CakeTestCaseTest file
- *
- * Test Case for CakeTestCase class
- *
- * PHP version 5
- *
- * CakePHP : Rapid Development Framework (http://cakephp.org)
- * Copyright 2005-2012, Cake Software Foundation, Inc.
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
- * @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)
- */
- App::uses('Controller', 'Controller');
- App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
- /**
- * CakeTestCaseTest
- *
- * @package Cake.Test.Case.TestSuite
- */
- class CakeTestCaseTest extends CakeTestCase {
- /**
- * fixtures property
- *
- * @var array
- */
- public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment');
- public static function setUpBeforeClass() {
- require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
- require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'FixturizedTestCase.php';
- }
- /**
- * setUp
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $this->Reporter = $this->getMock('CakeHtmlReporter');
- }
- /**
- * tearDown
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->Result);
- unset($this->Reporter);
- }
- /**
- * testAssertGoodTags
- *
- * @return void
- */
- public function testAssertTagsQuotes() {
- $test = new AssertTagsTestCase('testAssertTagsQuotes');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- $this->assertTrue($result->wasSuccessful());
- $this->assertEquals(0, $result->failureCount());
- $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');
- $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), 'Single quoted attributes %s');
- $input = "<a href='/test.html' class='active'>My link</a>";
- $pattern = array(
- 'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
- 'My link',
- '/a'
- );
- $this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
- $input = "<span><strong>Text</strong></span>";
- $pattern = array(
- '<span',
- '<strong',
- 'Text',
- '/strong',
- '/span'
- );
- $this->assertTrue($test->assertTags($input, $pattern), 'Tags with no attributes');
- $input = "<span class='active'><strong>Text</strong></span>";
- $pattern = array(
- 'span' => array('class'),
- '<strong',
- 'Text',
- '/strong',
- '/span'
- );
- $this->assertTrue($test->assertTags($input, $pattern), 'Test attribute presence');
- }
- /**
- * testNumericValuesInExpectationForAssertTags
- *
- * @return void
- */
- public function testNumericValuesInExpectationForAssertTags() {
- $test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- $this->assertTrue($result->wasSuccessful());
- $this->assertEquals(0, $result->failureCount());
- }
- /**
- * testBadAssertTags
- *
- * @return void
- */
- public function testBadAssertTags() {
- $test = new AssertTagsTestCase('testBadAssertTags');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- $this->assertFalse($result->wasSuccessful());
- $this->assertEquals(1, $result->failureCount());
- $test = new AssertTagsTestCase('testBadAssertTags2');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- $this->assertFalse($result->wasSuccessful());
- $this->assertEquals(1, $result->failureCount());
- }
- /**
- * testLoadFixtures
- *
- * @return void
- */
- public function testLoadFixtures() {
- $test = new FixturizedTestCase('testFixturePresent');
- $manager = $this->getMock('CakeFixtureManager');
- $manager->fixturize($test);
- $test->fixtureManager = $manager;
- $manager->expects($this->once())->method('load');
- $manager->expects($this->once())->method('unload');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- $this->assertTrue($result->wasSuccessful());
- $this->assertEquals(0, $result->failureCount());
- }
- /**
- * testLoadFixturesOnDemand
- *
- * @return void
- */
- public function testLoadFixturesOnDemand() {
- $test = new FixturizedTestCase('testFixtureLoadOnDemand');
- $test->autoFixtures = false;
- $manager = $this->getMock('CakeFixtureManager');
- $manager->fixturize($test);
- $test->fixtureManager = $manager;
- $manager->expects($this->once())->method('loadSingle');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- }
- /**
- * testLoadFixturesOnDemand
- *
- * @return void
- */
- public function testUnoadFixturesAfterFailure() {
- $test = new FixturizedTestCase('testFixtureLoadOnDemand');
- $test->autoFixtures = false;
- $manager = $this->getMock('CakeFixtureManager');
- $manager->fixturize($test);
- $test->fixtureManager = $manager;
- $manager->expects($this->once())->method('loadSingle');
- $result = $test->run();
- $this->assertEquals(0, $result->errorCount());
- }
- /**
- * testThrowException
- *
- * @return void
- */
- public function testThrowException() {
- $test = new FixturizedTestCase('testThrowException');
- $test->autoFixtures = false;
- $manager = $this->getMock('CakeFixtureManager');
- $manager->fixturize($test);
- $test->fixtureManager = $manager;
- $manager->expects($this->once())->method('unload');
- $result = $test->run();
- $this->assertEquals(1, $result->errorCount());
- }
- /**
- * testSkipIf
- *
- * @return void
- */
- public function testSkipIf() {
- $test = new FixturizedTestCase('testSkipIfTrue');
- $result = $test->run();
- $this->assertEquals(1, $result->skippedCount());
- $test = new FixturizedTestCase('testSkipIfFalse');
- $result = $test->run();
- $this->assertEquals(0, $result->skippedCount());
- }
- /**
- * Test that CakeTestCase::setUp() backs up values.
- *
- * @return void
- */
- public function testSetupBackUpValues() {
- $this->assertArrayHasKey('debug', $this->_configure);
- $this->assertArrayHasKey('Plugin', $this->_pathRestore);
- }
- /**
- * 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);
- }
- /**
- * test assertTextStartsWith()
- *
- * @return void
- */
- 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);
- $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!";
- $this->assertTextStartsNotWith("some\nstring\nwithout", $stringDirty);
- }
- /**
- * test assertTextEndsWith()
- *
- * @return void
- */
- 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);
- }
- /**
- * test assertTextEndsNotWith()
- *
- * @return void
- */
- 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);
- }
- /**
- * test assertTextContains()
- *
- * @return void
- */
- 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);
- }
- /**
- * test assertTextNotContains()
- *
- * @return void
- */
- 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() {
- $Post = $this->getMockForModel('Post');
- $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() with plugin models
- *
- * @return void
- */
- public function testGetMockForModelWithPlugin() {
- $TestPluginComment = $this->getMockForModel('TestPlugin.TestPluginComment');
- $result = ClassRegistry::init('TestPlugin.TestPluginComment');
- $this->assertInstanceOf('TestPluginComment', $result);
- $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()));
- }
- }
|