mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Add methods to CakeTestCase
Add assertTextEquals, and assertTextNotEquals for doing platform independant text comparisons. Refs #2148
This commit is contained in:
parent
29514b08fb
commit
bd0104d972
2 changed files with 50 additions and 6 deletions
|
@ -22,12 +22,6 @@
|
|||
App::uses('Controller', 'Controller');
|
||||
App::uses('CakeHtmlReporter', 'TestSuite/Reporter');
|
||||
|
||||
if (!class_exists('AppController', false)) {
|
||||
require_once CAKE . 'Controller' . DS . 'AppController.php';
|
||||
} elseif (!defined('APP_CONTROLLER_EXISTS')) {
|
||||
define('APP_CONTROLLER_EXISTS', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* CakeTestCaseTest
|
||||
*
|
||||
|
@ -240,4 +234,26 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,6 +192,34 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert text equality, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $expected The expected value.
|
||||
* @param string $result The actual value.
|
||||
* @param message The message to use for failure.
|
||||
*/
|
||||
public function assertTextNotEquals($expected, $result, $message = '') {
|
||||
$expected = str_replace(array("\r\n", "\r"), "\n", $expected);
|
||||
$result = str_replace(array("\r\n", "\r"), "\n", $result);
|
||||
return $this->assertNotEquals($expected, $result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert text equality, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $expected The expected value.
|
||||
* @param string $result The actual value.
|
||||
* @param message The message to use for failure.
|
||||
*/
|
||||
public function assertTextEquals($expected, $result, $message = '') {
|
||||
$expected = str_replace(array("\r\n", "\r"), "\n", $expected);
|
||||
$result = str_replace(array("\r\n", "\r"), "\n", $result);
|
||||
return $this->assertEquals($expected, $result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array $expected and generates a regex from it to match the provided $string.
|
||||
* Samples for $expected:
|
||||
|
|
Loading…
Add table
Reference in a new issue