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
|
|
|
*
|
2010-05-08 21:06:11 +00:00
|
|
|
* PHP version 5
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2010-01-14 04:47:14 +00:00
|
|
|
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-14 04:47:14 +00:00
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs.
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP v 1.2.0.4487
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-08-23 17:28:08 +00:00
|
|
|
*/
|
2009-03-21 23:55:39 +00:00
|
|
|
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
|
|
|
|
|
|
|
if (!class_exists('AppController', false)) {
|
2010-12-11 05:47:55 +00:00
|
|
|
require_once LIBS . 'Controller' . DS . 'AppController.php';
|
2009-03-21 23:55:39 +00:00
|
|
|
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
|
|
|
|
define('APP_CONTROLLER_EXISTS', true);
|
|
|
|
}
|
2008-08-23 17:28:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CakeTestCaseTest
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
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
|
|
|
|
2010-05-08 05:49:45 +00:00
|
|
|
public static function setUpBeforeClass() {
|
2011-05-13 08:01:12 +00:00
|
|
|
require_once LIBS . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
|
|
|
|
require_once LIBS . '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
|
|
|
* @access public
|
|
|
|
* @return void
|
2008-10-15 19:14:11 +00:00
|
|
|
*/
|
2008-08-23 17:28:08 +00:00
|
|
|
function setUp() {
|
2009-10-21 02:19:32 +00:00
|
|
|
$this->_debug = Configure::read('debug');
|
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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
2009-10-21 02:19:32 +00:00
|
|
|
Configure::write('debug', $this->_debug);
|
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
|
|
|
/**
|
2008-10-15 19:14:11 +00:00
|
|
|
* testAssertGoodTags
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2010-04-05 01:43:29 +00:00
|
|
|
*/
|
|
|
|
function testAssertTagsQuotes() {
|
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());
|
2010-11-17 02:48:13 +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' => '/test.html', 'class' => 'active'),
|
|
|
|
'My link',
|
|
|
|
'/a'
|
|
|
|
);
|
2010-11-17 02:48:13 +00:00
|
|
|
$this->assertTrue($test->assertTags($input, $pattern), 'Double quoted attributes %s');
|
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'
|
|
|
|
);
|
2010-11-17 02:48:13 +00:00
|
|
|
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
|
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'
|
|
|
|
);
|
2010-11-17 02:48:13 +00:00
|
|
|
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
|
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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-05-08 20:44:22 +00:00
|
|
|
function testLoadFixturesOnDemand() {
|
|
|
|
$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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUnoadFixturesAfterFailure() {
|
|
|
|
$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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testThrowException() {
|
|
|
|
$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());
|
2008-09-09 05:36:18 +00:00
|
|
|
|
2010-06-01 03:37:21 +00:00
|
|
|
}
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* testSkipIf
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-08-23 17:28:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|