mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Cleaning up CakeTestCase and adding some tests for it
This commit is contained in:
parent
e81cc684ef
commit
82a1bd6f80
3 changed files with 163 additions and 259 deletions
|
@ -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 = '<p>Text</p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'Text',
|
||||
'/p',
|
||||
);
|
||||
$this->Case->assertTags($input, $pattern);
|
||||
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$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 = "<a href=\"/test.html\"\t\n\tclass=\"active\"\tid=\"primary\">\t<span>My link</span></a>";
|
||||
$pattern = array(
|
||||
'a' => array('id' => 'primary', 'href' => '/test.html', 'class' => 'active'),
|
||||
'<span',
|
||||
'My link',
|
||||
'/span',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Whitespace consumption %s');
|
||||
|
||||
$input = '<p class="info"><a href="/test.html" class="active"><strong onClick="alert(\'hey\');">My link</strong></a></p>';
|
||||
$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 = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->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($this->Case->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($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 = '<p><strong>' . $value . '</strong></p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
||||
|
||||
$input = '<p><strong>' . $value . '</strong></p><p><strong>' . $value . '</strong></p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
||||
|
||||
$input = '<p><strong>' . $value . '</strong></p><p id="' . $value . '"><strong>' . $value . '</strong></p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
'p' => array('id' => $value),
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
);
|
||||
$this->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 = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'a' => array('hRef' => '/test.html', 'clAss' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertFalse($this->Case->assertTags($input, $pattern));
|
||||
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'<a' => 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));
|
||||
}
|
||||
}
|
||||
?>
|
122
cake/tests/fixtures/assert_tags_test_case.php
vendored
Normal file
122
cake/tests/fixtures/assert_tags_test_case.php
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* This class helpes in indirectly testing the functionaliteies of CakeTestCase::assertTags
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
*/
|
||||
class AssertTagsTestCase extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* test that assertTags knows how to handle correct quoting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testAssertTagsQuotes() {
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
||||
$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 = '<p><strong>' . $value . '</strong></p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = '<p><strong>' . $value . '</strong></p><p><strong>' . $value . '</strong></p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
|
||||
$input = '<p><strong>' . $value . '</strong></p><p id="' . $value . '"><strong>' . $value . '</strong></p>';
|
||||
$pattern = array(
|
||||
'<p',
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
'p' => array('id' => $value),
|
||||
'<strong',
|
||||
$value,
|
||||
'/strong',
|
||||
'/p',
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* testBadAssertTags
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testBadAssertTags() {
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'a' => array('hRef' => '/test.html', 'clAss' => 'active'),
|
||||
'My link2',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* testBadAssertTags
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testBadAssertTags2() {
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'<a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($input, $pattern);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue