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 16:36:11 -04:30
|
|
|
* PHP version 5
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
2009-11-06 17:46:59 +11:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 17:31:39 -04:00
|
|
|
* Copyright 2005-2011, 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.
|
|
|
|
*
|
2011-05-29 17:31:39 -04:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
|
2009-11-06 17:00:11 +11:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.TestSuite
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP v 1.2.0.4487
|
2009-11-06 17:51:51 +11: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 00:43:11 -04:30
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
|
|
|
|
|
|
|
if (!class_exists('AppController', false)) {
|
2011-04-17 12:35:21 +02:00
|
|
|
require_once CAKE . '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
|
|
|
|
*
|
2011-07-26 01:46:14 -04:30
|
|
|
* @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 21:18:37 +02:00
|
|
|
|
2010-05-08 01:19:45 -04:30
|
|
|
public static function setUpBeforeClass() {
|
2011-04-17 12:35:21 +02:00
|
|
|
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'AssertTagsTestCase.php';
|
|
|
|
require_once CAKE . 'Test' . DS . 'Fixture' . DS . 'FixturizedTestCase.php';
|
2010-05-08 01:19:45 -04:30
|
|
|
}
|
|
|
|
|
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 22:02:32 +02:00
|
|
|
public function setUp() {
|
2009-10-20 22:19:32 -04:00
|
|
|
$this->_debug = Configure::read('debug');
|
2010-05-05 22:42:56 -04:30
|
|
|
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function tearDown() {
|
2009-10-20 22:19:32 -04:00
|
|
|
Configure::write('debug', $this->_debug);
|
2010-05-05 22:42:56 -04:30
|
|
|
unset($this->Result);
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Reporter);
|
|
|
|
}
|
2009-07-24 21:18:37 +02: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
|
|
|
*
|
|
|
|
* @return void
|
2010-04-04 21:43:29 -04:00
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testAssertTagsQuotes() {
|
2010-05-08 01:19:45 -04:30
|
|
|
$test = new AssertTagsTestCase('testAssertTagsQuotes');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertTrue($result->wasSuccessful());
|
|
|
|
$this->assertEquals(0, $result->failureCount());
|
2010-11-16 21:48:13 -05:00
|
|
|
|
2010-04-04 21:43:29 -04: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-16 21:48:13 -05:00
|
|
|
$this->assertTrue($test->assertTags($input, $pattern), 'Double quoted attributes %s');
|
2010-04-04 21:43:29 -04: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-16 21:48:13 -05:00
|
|
|
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
|
2010-11-10 15:35:00 -03:00
|
|
|
|
2010-04-04 21:43:29 -04: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-16 21:48:13 -05:00
|
|
|
$this->assertTrue($test->assertTags($input, $pattern), 'Single quoted attributes %s');
|
2011-08-21 10:28:36 -04:00
|
|
|
|
|
|
|
$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');
|
2010-04-04 21:43:29 -04:00
|
|
|
}
|
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
2009-10-28 19:14:50 +01:00
|
|
|
* testNumericValuesInExpectationForAssertTags
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testNumericValuesInExpectationForAssertTags() {
|
2010-05-08 01:19:45 -04:30
|
|
|
$test = new AssertTagsTestCase('testNumericValuesInExpectationForAssertTags');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
$this->assertTrue($result->wasSuccessful());
|
|
|
|
$this->assertEquals(0, $result->failureCount());
|
2009-10-28 19:14:50 +01:00
|
|
|
}
|
2009-12-02 11:37:43 -05:00
|
|
|
|
2010-05-08 01:19:45 -04:30
|
|
|
/**
|
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 22:02:32 +02:00
|
|
|
public function testBadAssertTags() {
|
2010-05-08 01:19:45 -04:30
|
|
|
$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 01:19:45 -04:30
|
|
|
$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 21:18:37 +02:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* testLoadFixtures
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testLoadFixtures() {
|
2010-05-08 01:19:45 -04:30
|
|
|
$test = new FixturizedTestCase('testFixturePresent');
|
2010-05-08 15:56:21 -04:30
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-27 23:37:56 -04:30
|
|
|
$test->fixtureManager = $manager;
|
2010-05-08 15:56:21 -04:30
|
|
|
$manager->expects($this->once())->method('load');
|
|
|
|
$manager->expects($this->once())->method('unload');
|
2010-05-08 01:19:45 -04:30
|
|
|
$result = $test->run();
|
2010-05-08 15:56:21 -04:30
|
|
|
$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 21:18:37 +02:00
|
|
|
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
2010-05-08 16:14:22 -04:30
|
|
|
* testLoadFixturesOnDemand
|
2008-08-23 17:28:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:19:25 +11:00
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testLoadFixturesOnDemand() {
|
2010-05-08 16:14:22 -04:30
|
|
|
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
|
|
|
$test->autoFixtures = false;
|
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-27 23:37:56 -04:30
|
|
|
$test->fixtureManager = $manager;
|
2010-05-08 16:14:22 -04:30
|
|
|
$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 21:18:37 +02:00
|
|
|
|
2010-05-31 23:07:21 -04:30
|
|
|
/**
|
|
|
|
* testLoadFixturesOnDemand
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testUnoadFixturesAfterFailure() {
|
2010-05-31 23:07:21 -04:30
|
|
|
$test = new FixturizedTestCase('testFixtureLoadOnDemand');
|
|
|
|
$test->autoFixtures = false;
|
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-27 23:37:56 -04:30
|
|
|
$test->fixtureManager = $manager;
|
2010-05-31 23:07:21 -04:30
|
|
|
$manager->expects($this->once())->method('loadSingle');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->errorCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testThrowException
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testThrowException() {
|
2010-05-31 23:07:21 -04:30
|
|
|
$test = new FixturizedTestCase('testThrowException');
|
|
|
|
$test->autoFixtures = false;
|
|
|
|
$manager = $this->getMock('CakeFixtureManager');
|
|
|
|
$manager->fixturize($test);
|
2010-09-27 23:37:56 -04:30
|
|
|
$test->fixtureManager = $manager;
|
2010-05-31 23:07:21 -04:30
|
|
|
$manager->expects($this->once())->method('unload');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(1, $result->errorCount());
|
2008-09-09 05:36:18 +00:00
|
|
|
|
2010-05-31 23:07:21 -04:30
|
|
|
}
|
2008-08-23 17:28:08 +00:00
|
|
|
/**
|
|
|
|
* testSkipIf
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 23:19:25 +11:00
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testSkipIf() {
|
2010-05-08 16:36:11 -04:30
|
|
|
$test = new FixturizedTestCase('testSkipIfTrue');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(1, $result->skippedCount());
|
2008-10-15 19:14:11 +00:00
|
|
|
|
2010-05-08 16:36:11 -04:30
|
|
|
$test = new FixturizedTestCase('testSkipIfFalse');
|
|
|
|
$result = $test->run();
|
|
|
|
$this->assertEquals(0, $result->skippedCount());
|
2008-08-23 17:28:08 +00:00
|
|
|
}
|
|
|
|
}
|