Skip to content
Permalink
Browse files

added missing assertText methods to assert cross OS

  • Loading branch information...
dereuromark committed Feb 17, 2012
1 parent bc98a5e commit 77624552ebb3fb5dc5ff652fbce73adc93eb3c77
Showing with 176 additions and 0 deletions.
  1. +82 −0 lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
  2. +94 −0 lib/Cake/TestSuite/CakeTestCase.php
@@ -256,4 +256,86 @@ public function testAssertTextEquals() {
$two = "\nOne\nTwo";
$this->assertTextEquals($one, $two);
}
/**
* test assertTextStartsWith()
*
* @return void
*/
public function testAssertTextStartsWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertStringStartsWith("some\nstring", $stringDirty);
$this->assertStringStartsNotWith("some\r\nstring\r\nwith", $stringDirty);
$this->assertStringStartsNotWith("some\nstring\nwith", $stringDirty);
$this->assertTextStartsWith("some\nstring\nwith", $stringDirty);
$this->assertTextStartsWith("some\r\nstring\r\nwith", $stringDirty);
}
/**
* test assertTextStartsNotWith()
*
* @return void
*/
public function testAssertTextStartsNotWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertTextStartsNotWith("some\nstring\nwithout", $stringDirty);
}
/**
* test assertTextEndsWith()
*
* @return void
*/
public function testAssertTextEndsWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertTextEndsWith("string\nwith\r\ndifferent\rline endings!", $stringDirty);
$this->assertTextEndsWith("string\r\nwith\ndifferent\nline endings!", $stringDirty);
}
/**
* test assertTextEndsNotWith()
*
* @return void
*/
public function testAssertTextEndsNotWith() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertStringEndsNotWith("different\nline endings", $stringDirty);
$this->assertTextEndsNotWith("different\rline endings", $stringDirty);
}
/**
* test assertTextContains()
*
* @return void
*/
public function testAssertTextContains() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertContains("different", $stringDirty);
$this->assertNotContains("different\rline", $stringDirty);
$this->assertTextContains("different\rline", $stringDirty);
}
/**
* test assertTextNotContains()
*
* @return void
*/
public function testAssertTextNotContains() {
$stringDirty = "some\nstring\r\nwith\rdifferent\nline endings!";
$stringClean = "some\nstring\nwith\ndifferent\nline endings!";
$this->assertTextNotContains("different\rlines", $stringDirty);
}
}
@@ -199,6 +199,7 @@ public function loadFixtures() {
* @param string $expected The expected value.
* @param string $result The actual value.
* @param message The message to use for failure.
* @return boolean
*/
public function assertTextNotEquals($expected, $result, $message = '') {
$expected = str_replace(array("\r\n", "\r"), "\n", $expected);
@@ -213,13 +214,106 @@ public function assertTextNotEquals($expected, $result, $message = '') {
* @param string $expected The expected value.
* @param string $result The actual value.
* @param message The message to use for failure.
* @return boolean
*/
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);
}
/**
* Asserts that a string starts with a given prefix, ignoring differences in newlines.
* Helpful for doing cross platform tests of blocks of text.
*
* @param string $prefix
* @param string $string
* @param string $message
* @return boolean
*/
public function assertTextStartsWith($prefix, $string, $message = '') {
$prefix = str_replace(array("\r\n", "\r"), "\n", $prefix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
return $this->assertStringStartsWith($prefix, $string, $message);
}
/**
* Asserts that a string starts not with a given prefix, ignoring differences in newlines.
* Helpful for doing cross platform tests of blocks of text.
*
* @param string $prefix
* @param string $string
* @param string $message
* @return boolean
*/
public function assertTextStartsNotWith($prefix, $string, $message = '') {
$prefix = str_replace(array("\r\n", "\r"), "\n", $prefix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
return $this->assertStringStartsNotWith($prefix, $string, $message);
}
/**
* Asserts that a string ends with a given prefix, ignoring differences in newlines.
* Helpful for doing cross platform tests of blocks of text.
*
* @param string $suffix
* @param string $string
* @param string $message
* @return boolean
*/
public function assertTextEndsWith($suffix, $string, $message = '') {
$suffix = str_replace(array("\r\n", "\r"), "\n", $suffix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
return $this->assertStringEndsWith($suffix, $string, $message);
}
/**
* Asserts that a string ends not with a given prefix, ignoring differences in newlines.
* Helpful for doing cross platform tests of blocks of text.
*
* @param string $suffix
* @param string $string
* @param string $message
* @return boolean
*/
public function assertTextEndsNotWith($suffix, $string, $message = '') {
$suffix = str_replace(array("\r\n", "\r"), "\n", $suffix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
return $this->assertStringEndsNotWith($suffix, $string, $message);
}
/**
* Assert that a string contains another string, ignoring differences in newlines.
* Helpful for doing cross platform tests of blocks of text.
*
* @param string $needle
* @param string $haystack
* @param string $message
* @param boolean $ignoreCase
* @return boolean
*/
public function assertTextContains($needle, $haystack, $message = '', $ignoreCase = false) {
$needle = str_replace(array("\r\n", "\r"), "\n", $needle);
$haystack = str_replace(array("\r\n", "\r"), "\n", $haystack);
return $this->assertContains($needle, $haystack, $message, $ignoreCase);
}
/**
* Assert that a text doesn't contain another text, ignoring differences in newlines.
* Helpful for doing cross platform tests of blocks of text.
*
* @param string $needle
* @param string $haystack
* @param string $message
* @param boolean $ignoreCase
* @return boolean
*/
public function assertTextNotContains($needle, $haystack, $message = '', $ignoreCase = false) {
$needle = str_replace(array("\r\n", "\r"), "\n", $needle);
$haystack = str_replace(array("\r\n", "\r"), "\n", $haystack);
return $this->assertNotContains($needle, $haystack, $message, $ignoreCase);
}
/**
* Takes an array $expected and generates a regex from it to match the provided $string.
* Samples for $expected:

0 comments on commit 7762455

Please sign in to comment.
You can’t perform that action at this time.