Skip to content
This repository
Browse code

legacy support with test cases

  • Loading branch information...
commit 79690626141b9ccb7fd05f4440b76f133e4869a8 1 parent 4039842
Mark authored August 17, 2012
21  lib/Cake/Test/Case/Utility/StringTest.php
@@ -460,6 +460,27 @@ public function testTruncate() {
460 460
 	}
461 461
 
462 462
 /**
  463
+ * testTruncate method with non utf8 sites
  464
+ *
  465
+ * @return void
  466
+ */
  467
+	public function testTruncateLegacy() {
  468
+		Configure::write('App.encoding', 'ISO-8859-1');
  469
+		$text = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
  470
+		$result = $this->Text->truncate($text, 31, array(
  471
+			'exact' => false,
  472
+		));
  473
+		$expected = '<b>&copy; 2005-2007, Cake...';
  474
+		$this->assertEquals($expected, $result);
  475
+		
  476
+		$result = $this->Text->truncate($text, 31, array(
  477
+			'exact' => true,
  478
+		));
  479
+		$expected = '<b>&copy; 2005-2007, Cake So...';
  480
+		$this->assertEquals($expected, $result);
  481
+	}
  482
+
  483
+/**
463 484
  * testTail method
464 485
  *
465 486
  * @return void
5  lib/Cake/Utility/String.php
@@ -480,11 +480,10 @@ public static function truncate($text, $length = 100, $options = array()) {
480 480
 		$default = array(
481 481
 			'ellipsis' => '...', 'exact' => true, 'html' => false
482 482
 		);
483  
-		if (!empty($options['html'])) {
484  
-			$default['ellipsis'] = chr(226);
485  
-		}
486 483
 		if (isset($options['ending'])) {
487 484
 			$default['ellipsis'] = $options['ending'];
  485
+		} elseif (!empty($options['html']) && Configure::read('App.encoding') == 'UTF-8') {
  486
+			$default['ellipsis'] = chr(226);
488 487
 		}
489 488
 		$options = array_merge($default, $options);
490 489
 		extract($options);

0 notes on commit 7969062

Please sign in to comment.
Something went wrong with that request. Please try again.