Skip to content
Permalink
Browse files

changing methods in String class to static

  • Loading branch information...
rchavik committed Feb 13, 2012
1 parent 25ee90a commit abd6d22445b2fce3d4c7556e468e9d9ff237fde6
@@ -22,12 +22,18 @@
class TextHelperTestObject extends TextHelper {
public function attach(String $string) {
public function attach(StringMock $string) {
$this->_String = $string;
}
}
/**
* StringMock class
*/
class StringMock {
}
/**
* TextHelperTest class
*
@@ -41,8 +47,8 @@ class TextHelperTest extends CakeTestCase {
* @return void
*/
public function setUp() {
$controller = null;
$this->View = new View($controller);
parent::setUp();
$this->View = new View(null);
$this->Text = new TextHelper($this->View);
}
@@ -52,23 +58,23 @@ public function setUp() {
* @return void
*/
public function tearDown() {
unset($this->View, $this->Text);
unset($this->View);
parent::tearDown();
}
/**
* test String class methods are called correctly
*/
public function testTextHelperProxyMethodCalls() {
$this->String = $this->getMock('String');
unset($this->Text);
$this->Text = new TextHelperTestObject($this->View);
$this->Text->attach($this->String);
$methods = array(
'highlight', 'stripLinks', 'truncate', 'excerpt', 'toList',
);
$String = $this->getMock('StringMock', $methods);
$Text = new TextHelperTestObject($this->View, array('engine' => 'StringMock'));
$Text->attach($String);
foreach ($methods as $method) {
$this->String->expects($this->at(0))->method($method);
$this->Text->{$method}('who', 'what', 'when', 'where', 'how');
$String->expects($this->at(0))->method($method);
$Text->{$method}('who', 'what', 'when', 'where', 'how');
}
}
@@ -368,7 +368,7 @@ public static function wrap($text, $options = array()) {
* @return string The highlighted text
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlight
*/
public function highlight($text, $phrase, $options = array()) {
public static function highlight($text, $phrase, $options = array()) {
if (empty($phrase)) {
return $text;
}
@@ -412,7 +412,7 @@ public function highlight($text, $phrase, $options = array()) {
* @return string The text without links
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::stripLinks
*/
public function stripLinks($text) {
public static function stripLinks($text) {
return preg_replace('|<a\s+[^>]+>|im', '', preg_replace('|<\/a>|im', '', $text));
}
@@ -434,7 +434,7 @@ public function stripLinks($text) {
* @return string Trimmed string.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate
*/
public function truncate($text, $length = 100, $options = array()) {
public static function truncate($text, $length = 100, $options = array()) {
$default = array(
'ending' => '...', 'exact' => true, 'html' => false
);
@@ -550,9 +550,9 @@ class_exists('Multibyte');
* @return string Modified string
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt
*/
public function excerpt($text, $phrase, $radius = 100, $ending = '...') {
public static function excerpt($text, $phrase, $radius = 100, $ending = '...') {
if (empty($text) or empty($phrase)) {
return $this->truncate($text, $radius * 2, array('ending' => $ending));
return self::truncate($text, $radius * 2, array('ending' => $ending));
}
$append = $prepend = $ending;
@@ -592,7 +592,7 @@ public function excerpt($text, $phrase, $radius = 100, $ending = '...') {
* @return string The glued together string.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList
*/
public function toList($list, $and = 'and', $separator = ', ') {
public static function toList($list, $and = 'and', $separator = ', ') {
if (count($list) > 1) {
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
} else {
@@ -60,8 +60,15 @@ class TextHelper extends AppHelper {
* @param array $settings Settings array Settings array
*/
public function __construct(View $View, $settings = array()) {
$settings = Set::merge(array('engine' => 'String'), $settings);
parent::__construct($View, $settings);
$this->_String = new String($settings);
$engineClass = $settings['engine'];
App::uses($engineClass, 'Utility');
if (class_exists($engineClass)) {
$this->_String = new $engineClass($settings);
} else {
throw new CakeException(__d('cake_dev', '%s could not be found', $engineClass));
}
}
/**

0 comments on commit abd6d22

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