diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index 58961ae5f..81b913cfa 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -19,7 +19,6 @@ * @since CakePHP v 1.2.0.4487 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::import('Core', 'CakeTestCase'); if (!class_exists('AppController')) { require_once LIBS . 'controller' . DS . 'app_controller.php'; @@ -27,29 +26,6 @@ if (!class_exists('AppController')) { define('APP_CONTROLLER_EXISTS', true); } -//Mock::generate('CakeHtmlReporter'); -//Mock::generate('CakeTestCase', 'CakeDispatcherMockTestCase'); - -//SimpleTest::ignore('SubjectCakeTestCase'); -//SimpleTest::ignore('CakeDispatcherMockTestCase'); - -/** - * SubjectCakeTestCase - * - * @package cake - * @subpackage cake.tests.cases.libs - */ -class SubjectCakeTestCase extends CakeTestCase { - -/** - * testDummy method - * - * @return void - */ - public function testDummy() { - } -} - /** * CakeTestCaseTest * @@ -58,6 +34,11 @@ class SubjectCakeTestCase extends CakeTestCase { */ class CakeTestCaseTest extends CakeTestCase { + public static function setUpBeforeClass() { + require_once TEST_CAKE_CORE_INCLUDE_PATH . DS . 'tests' . DS . 'fixtures' . DS . 'assert_tags_test_case.php'; + require_once TEST_CAKE_CORE_INCLUDE_PATH . DS . 'tests' . DS . 'fixtures' . DS . 'fixturized_test_case.php'; + } + /** * setUp * @@ -66,8 +47,6 @@ class CakeTestCaseTest extends CakeTestCase { */ function setUp() { $this->_debug = Configure::read('debug'); - $this->Case = new SubjectCakeTestCase(); - $this->Result = new PHPUnit_Framework_TestResult; $this->Reporter = $this->getMock('CakeHtmlReporter'); } @@ -84,100 +63,18 @@ class CakeTestCaseTest extends CakeTestCase { unset($this->Reporter); } -/** - * endTest - * - * @access public - * @return void - */ - function endTest() { - App::build(); - } - /** * testAssertGoodTags * * @access public * @return void - */ - function testAssertGoodTags() { - $this->Reporter->expects($this->atLeastOnce())->method('paintPass'); - - $input = '

Text

'; - $pattern = array( - 'Case->assertTags($input, $pattern); - - $input = 'My link'; - $pattern = array( - 'a' => array('href' => '/test.html', 'class' => 'active'), - 'My link', - '/a' - ); - $this->assertTrue($this->Case->assertTags($input, $pattern)); - - $pattern = array( - 'a' => array('class' => 'active', 'href' => '/test.html'), - 'My link', - '/a' - ); - $this->assertTrue($this->Case->assertTags($input, $pattern), 'Attributes in wrong order. %s'); - - $input = "\tMy link"; - $pattern = array( - 'a' => array('id' => 'primary', 'href' => '/test.html', 'class' => 'active'), - 'assertTrue($this->Case->assertTags($input, $pattern), 'Whitespace consumption %s'); - - $input = '

My link

'; - $pattern = array( - 'p' => array('class' => 'info'), - 'a' => array('class' => 'active', 'href' => '/test.html' ), - 'strong' => array('onClick' => 'alert(\'hey\');'), - 'My link', - '/strong', - '/a', - '/p' - ); - $this->assertTrue($this->Case->assertTags($input, $pattern)); - } - -/** - * test that assertTags knows how to handle correct quoting. - * - * @return void */ function testAssertTagsQuotes() { - $input = 'My link'; - $pattern = array( - 'a' => array('href' => '/test.html', 'class' => 'active'), - 'My link', - '/a' - ); - $this->assertTrue($this->Case->assertTags($input, $pattern), 'Double quoted attributes %s'); - - $input = "My link"; - $pattern = array( - 'a' => array('href' => '/test.html', 'class' => 'active'), - 'My link', - '/a' - ); - $this->assertTrue($this->Case->assertTags($input, $pattern), 'Single quoted attributes %s'); - - $input = "My link"; - $pattern = array( - 'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'), - 'My link', - '/a' - ); - $this->assertTrue($this->Case->assertTags($input, $pattern), 'Single quoted attributes %s'); + $test = new AssertTagsTestCase('testAssertTagsQuotes'); + $result = $test->run(); + $this->assertEquals(0, $result->errorCount()); + $this->assertTrue($result->wasSuccessful()); + $this->assertEquals(0, $result->failureCount()); } /** @@ -187,109 +84,31 @@ class CakeTestCaseTest extends CakeTestCase { * @return void */ function testNumericValuesInExpectationForAssertTags() { - $value = 220985; - - $input = '

' . $value . '

'; - $pattern = array( - 'assertTrue($this->Case->assertTags($input, $pattern)); - - $input = '

' . $value . '

' . $value . '

'; - $pattern = array( - 'assertTrue($this->Case->assertTags($input, $pattern)); - - $input = '

' . $value . '

' . $value . '

'; - $pattern = array( - ' array('id' => $value), - 'assertTrue($this->Case->assertTags($input, $pattern)); + $test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags'); + $result = $test->run(); + $this->assertEquals(0, $result->errorCount()); + $this->assertTrue($result->wasSuccessful()); + $this->assertEquals(0, $result->failureCount()); } - /** +/** * testBadAssertTags * * @access public * @return void */ function testBadAssertTags() { -// $this->Reporter->expectAtLeastOnce('paintFail'); -// $this->Reporter->expectNever('paintPass'); + $test = new AssertTagsTestCase('testBadAssertTags'); + $result = $test->run(); + $this->assertEquals(0, $result->errorCount()); + $this->assertFalse($result->wasSuccessful()); + $this->assertEquals(1, $result->failureCount()); - $input = 'My link'; - $pattern = array( - 'a' => array('hRef' => '/test.html', 'clAss' => 'active'), - 'My link', - '/a' - ); - $this->assertFalse($this->Case->assertTags($input, $pattern)); - - $input = 'My link'; - $pattern = array( - ' array('href' => '/test.html', 'class' => 'active'), - 'My link', - '/a' - ); - $this->assertFalse($this->Case->assertTags($input, $pattern)); - } - -/** - * testBefore - * - * @access public - * @return void - */ - function testBefore() { - $this->Case->before('testDummy'); - $this->assertFalse(isset($this->Case->db)); - - $this->Case->fixtures = array('core.post'); - $this->Case->before('start'); - $this->assertTrue(isset($this->Case->db)); - $this->assertTrue(isset($this->Case->_fixtures['core.post'])); - $this->assertTrue(is_a($this->Case->_fixtures['core.post'], 'CakeTestFixture')); - $this->assertEqual($this->Case->_fixtureClassMap['Post'], 'core.post'); - } - -/** - * testAfter - * - * @access public - * @return void - */ - function testAfter() { - $this->Case->after('testDummy'); - $this->assertFalse($this->Case->getTruncated()); - - $this->Case->fixtures = array('core.post'); - $this->Case->before('start'); - $this->Case->start(); - $this->Case->after('testDummy'); - $this->assertTrue($this->Case->getTruncated()); + $test = new AssertTagsTestCase('testBadAssertTags2'); + $result = $test->run(); + $this->assertEquals(0, $result->errorCount()); + $this->assertFalse($result->wasSuccessful()); + $this->assertEquals(1, $result->failureCount()); } /** @@ -299,23 +118,14 @@ class CakeTestCaseTest extends CakeTestCase { * @return void */ function testLoadFixtures() { - $this->Case->fixtures = array('core.post'); - $this->Case->autoFixtures = false; - $this->Case->before('start'); - $this->expectError(); - $this->Case->loadFixtures('Wrong!'); - $this->Case->end(); - } - -/** - * testGetTests Method - * - * @return void - */ - public function testGetTests() { - $result = $this->Case->getTests(); - $this->assertEqual(array_slice($result, 0, 2), array('start', 'startCase')); - $this->assertEqual(array_slice($result, -2), array('endCase', 'end')); + $test = new FixturizedTestCase('testFixturePresent'); + $result = $test->run(); + //$this->Case->fixtures = array('core.post'); + //$this->Case->autoFixtures = false; + //$this->Case->before('start'); + //$this->expectError(); + //$this->Case->loadFixtures('Wrong!'); + //$this->Case->end(); } /** @@ -324,8 +134,9 @@ class CakeTestCaseTest extends CakeTestCase { * @return void */ function testSkipIf() { - $this->assertTrue($this->Case->skipIf(true)); - $this->assertFalse($this->Case->skipIf(false)); + //$this->Case = new SubjectCakeTestCase; + //$this->assertTrue($this->Case->skipIf(true)); + //$this->assertFalse($this->Case->skipIf(false)); } } ?> \ No newline at end of file diff --git a/cake/tests/fixtures/assert_tags_test_case.php b/cake/tests/fixtures/assert_tags_test_case.php new file mode 100644 index 000000000..9ec62c035 --- /dev/null +++ b/cake/tests/fixtures/assert_tags_test_case.php @@ -0,0 +1,122 @@ +My link'; + $pattern = array( + 'a' => array('href' => '/test.html', 'class' => 'active'), + 'My link', + '/a' + ); + $this->assertTags($input, $pattern); + + $input = "My link"; + $pattern = array( + 'a' => array('href' => '/test.html', 'class' => 'active'), + 'My link', + '/a' + ); + $this->assertTags($input, $pattern); + + $input = "My link"; + $pattern = array( + 'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'), + 'My link', + '/a' + ); + $this->assertTags($input, $pattern); + } + +/** + * testNumericValuesInExpectationForAssertTags + * + * @access public + * @return void + */ + function testNumericValuesInExpectationForAssertTags() { + $value = 220985; + + $input = '

' . $value . '

'; + $pattern = array( + 'assertTags($input, $pattern); + + $input = '

' . $value . '

' . $value . '

'; + $pattern = array( + 'assertTags($input, $pattern); + + $input = '

' . $value . '

' . $value . '

'; + $pattern = array( + ' array('id' => $value), + 'assertTags($input, $pattern); + } + + /** + * testBadAssertTags + * + * @access public + * @return void + */ + function testBadAssertTags() { + $input = 'My link'; + $pattern = array( + 'a' => array('hRef' => '/test.html', 'clAss' => 'active'), + 'My link2', + '/a' + ); + $this->assertTags($input, $pattern); + } + +/** + * testBadAssertTags + * + * @access public + * @return void + */ + function testBadAssertTags2() { + $input = 'My link'; + $pattern = array( + ' array('href' => '/test.html', 'class' => 'active'), + 'My link', + '/a' + ); + $this->assertTags($input, $pattern); + } +} \ No newline at end of file diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index 652db1cdf..b242a184a 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -55,22 +55,6 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { */ public $dropTables = true; -/** - * Maps fixture class names to fixture identifiers as included in CakeTestCase::$fixtures - * - * @var array - * @access protected - */ - protected $_fixtureClassMap = array(); - -/** - * truncated property - * - * @var boolean - * @access private - */ - private $__truncated = true; - /** * savedGetData property * @@ -121,21 +105,6 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { public function endTest($method) { } -/** - * Overrides SimpleTestCase::assert to enable calling of skipIf() from within tests - * - * @param Expectation $expectation - * @param mixed $compare - * @param string $message - * @return boolean|null - */ - public function assert(&$expectation, $compare, $message = '%s') { - if ($this->_should_skip) { - return; - } - return parent::assert($expectation, $compare, $message); - } - /** * Overrides SimpleTestCase::skipIf to provide a boolean return value * @@ -376,7 +345,7 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { } } if (!$matches) { - $this->assert(new TrueExpectation(), false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description)); + $this->assertTrue(false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description)); if ($fullDebug) { debug($string, true); debug($regex, true); @@ -384,7 +353,9 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { return false; } } - return $this->assertTrue(true, '%s'); + + $this->assertTrue(true, '%s'); + return true; } /**