Browse Source

Fix tests

euromark 11 years ago
parent
commit
3d9ae7edcc
2 changed files with 10 additions and 73 deletions
  1. 7 70
      Test/Case/View/Helper/CommonHelperTest.php
  2. 3 3
      View/Helper/CommonHelper.php

+ 7 - 70
Test/Case/View/Helper/CommonHelperTest.php

@@ -24,17 +24,6 @@ class CommonHelperTest extends MyCakeTestCase {
 	}
 
 	/**
-	 * CommonHelperTest::testFlashMessage()
-	 *
-	 * @return void
-	 */
-	public function testFlashMessage() {
-		$result = $this->Flash->message(h('Foo & bar'), 'success');
-		$expected = '<div class="flash-messages flashMessages"><div class="message success">Foo &amp;amp; bar</div></div>';
-		$this->assertEquals($expected, $result);
-	}
-
-	/**
 	 * CommonHelperTest::testAlternate()
 	 *
 	 * @return void
@@ -124,60 +113,6 @@ class CommonHelperTest extends MyCakeTestCase {
 	}
 
 	/**
-	 * CommonHelperTest::testFlash()
-	 *
-	 * @return void
-	 */
-	public function testFlash() {
-		$this->Common->addFlashMessage(h('Foo & bar'), 'success');
-
-		$result = $this->Common->flash();
-		$expected = '<div class="flash-messages flashMessages"><div class="message success">Foo &amp; bar</div></div>';
-		$this->assertEquals($expected, $result);
-
-		$this->Common->addFlashMessage('I am an error', 'error');
-		$this->Common->addFlashMessage('I am a warning', 'warning');
-		$this->Common->addFlashMessage('I am some info', 'info');
-		$this->Common->addFlashMessage('I am also some info');
-		$this->Common->addFlashMessage('I am sth custom', 'custom');
-
-		$result = $this->Common->flash();
-		$this->assertTextContains('message error', $result);
-		$this->assertTextContains('message warning', $result);
-		$this->assertTextContains('message info', $result);
-		$this->assertTextContains('message custom', $result);
-
-		$result = substr_count($result, 'message info');
-		$this->assertSame(2, $result);
-	}
-
-	/**
-	 * Test that you can define your own order or just output a subpart of
-	 * the types.
-	 *
-	 * @return void
-	 */
-	public function testFlashWithTypes() {
-		$this->Common->addFlashMessage('I am an error', 'error');
-		$this->Common->addFlashMessage('I am a warning', 'warning');
-		$this->Common->addFlashMessage('I am some info', 'info');
-		$this->Common->addFlashMessage('I am also some info');
-		$this->Common->addFlashMessage('I am sth custom', 'custom');
-
-		$result = $this->Common->flash(array('warning', 'error'));
-		$expected = '<div class="flash-messages flashMessages"><div class="message warning">I am a warning</div><div class="message error">I am an error</div></div>';
-		$this->assertEquals($expected, $result);
-
-		$result = $this->Common->flash(array('info'));
-		$expected = '<div class="flash-messages flashMessages"><div class="message info">I am some info</div><div class="message info">I am also some info</div></div>';
-		$this->assertEquals($expected, $result);
-
-		$result = $this->Common->flash();
-		$expected = '<div class="flash-messages flashMessages"><div class="message custom">I am sth custom</div></div>';
-		$this->assertEquals($expected, $result);
-	}
-
-	/**
 	 * @return void
 	 */
 	public function testMetaCanonical() {
@@ -217,17 +152,19 @@ class CommonHelperTest extends MyCakeTestCase {
 	 */
 	public function testEsc() {
 		$is = $this->Common->esc('Some Cool Text with <b>Html</b>');
-		$this->assertEquals($is, 'Some Cool Text with &lt;b&gt;Html&lt;/b&gt;');
+		$this->assertEquals('Some Cool Text with &lt;b&gt;Html&lt;/b&gt;', $is);
 
 		$is = $this->Common->esc('Some Cool Text' . PHP_EOL . 'with <b>Html</b>');
-		$this->assertEquals($is, 'Some Cool Text<br />' . PHP_EOL . 'with &lt;b&gt;Html&lt;/b&gt;');
+		$this->assertEquals('Some Cool Text<br />' . PHP_EOL . 'with &lt;b&gt;Html&lt;/b&gt;', $is);
 
 		$is = $this->Common->esc('Some Cool' . PHP_EOL . '  2 indends and' . PHP_EOL . '     5 indends' . PHP_EOL . 'YEAH');
-		$this->assertEquals($is, 'Some Cool<br />' . PHP_EOL . '&nbsp;&nbsp;2 indends and<br />' . PHP_EOL . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5 indends<br />' . PHP_EOL . 'YEAH');
+		$expected = 'Some Cool<br />' . PHP_EOL . '&nbsp;&nbsp;2 indends and<br />' . PHP_EOL . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5 indends<br />' . PHP_EOL . 'YEAH';
+		$this->assertEquals($expected, $is);
 
 		$options = array('tabsToSpaces' => 2);
-		$is = $this->Common->esc('Some Cool' . PHP_EOL . TB . '1 tab and' . PHP_EOL . TB . TB . '2 tabs' . PHP_EOL . 'YEAH', $options);
-		$this->assertEquals($is, 'Some Cool<br />' . PHP_EOL . '&nbsp;&nbsp;1 tab and<br />' . PHP_EOL . '&nbsp;&nbsp;&nbsp;&nbsp;2 tabs<br />' . PHP_EOL . 'YEAH');
+		$is = $this->Common->esc('Some Cool' . PHP_EOL . "\t" . '1 tab and' . PHP_EOL . "\t" . "\t" . '2 tabs' . PHP_EOL . 'YEAH', $options);
+		$expected = 'Some Cool<br />' . PHP_EOL . '&nbsp;&nbsp;1 tab and<br />' . PHP_EOL . '&nbsp;&nbsp;&nbsp;&nbsp;2 tabs<br />' . PHP_EOL . 'YEAH';
+		$this->assertEquals($expected, $is);
 	}
 
 	/**

+ 3 - 3
View/Helper/CommonHelper.php

@@ -138,7 +138,7 @@ class CommonHelper extends AppHelper {
 			//$text = str_replace(' ', '&nbsp;', h($text));
 			$text = h($text);
 			// try to fix indends made out of spaces
-			$text = explode(NL, $text);
+			$text = explode("\n", $text);
 			foreach ($text as $key => $t) {
 				$i = 0;
 				while (!empty($t[$i]) && $t[$i] === ' ') {
@@ -149,7 +149,7 @@ class CommonHelper extends AppHelper {
 					$text[$key] = $t;
 				}
 			}
-			$text = implode(NL, $text);
+			$text = implode("\n", $text);
 			$esc = true;
 		}
 		if (!isset($options['nl2br']) || $options['nl2br'] !== false) {
@@ -160,7 +160,7 @@ class CommonHelper extends AppHelper {
 		}
 		if (!empty($options['tabsToSpaces'])) {
 
-			$text = str_replace(TB, str_repeat(!empty($esc) ? '&nbsp;' : ' ', $options['tabsToSpaces']), $text);
+			$text = str_replace("\t", str_repeat(!empty($esc) ? '&nbsp;' : ' ', $options['tabsToSpaces']), $text);
 		}
 
 		return $text;