2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* StringTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2009-05-01 21:05:46 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('String', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* StringTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class StringTest extends CakeTestCase {
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testUuidGeneration method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUuidGeneration() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = String::uuid();
|
2009-03-09 20:03:02 +00:00
|
|
|
$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";
|
2010-05-19 04:35:49 +00:00
|
|
|
$match = (bool) preg_match($pattern, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($match);
|
|
|
|
}
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMultipleUuidGeneration method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleUuidGeneration() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$check = array();
|
2008-07-05 14:31:22 +00:00
|
|
|
$count = mt_rand(10, 1000);
|
2009-03-09 20:03:02 +00:00
|
|
|
$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
for($i = 0; $i < $count; $i++) {
|
|
|
|
$result = String::uuid();
|
2010-05-19 04:35:49 +00:00
|
|
|
$match = (bool) preg_match($pattern, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($match);
|
|
|
|
$this->assertFalse(in_array($result, $check));
|
|
|
|
$check[] = $result;
|
|
|
|
}
|
|
|
|
}
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInsert method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInsert() {
|
2009-11-03 23:21:01 +00:00
|
|
|
$string = 'some string';
|
|
|
|
$expected = 'some string';
|
|
|
|
$result = String::insert($string, array());
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-11-03 23:21:01 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$string = '2 + 2 = :sum. Cake is :adjective.';
|
|
|
|
$expected = '2 + 2 = 4. Cake is yummy.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '2 + 2 = %sum. Cake is %adjective.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '%'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '2 + 2 = 2sum2. Cake is 9adjective9.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('format' => '/([\d])%s\\1/'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '2 + 2 = 12sum21. Cake is 23adjective45.';
|
|
|
|
$expected = '2 + 2 = 4. Cake is 23adjective45.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('format' => '/([\d])([\d])%s\\2\\1/'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-04-09 13:15:43 +00:00
|
|
|
$string = ':web :web_site';
|
|
|
|
$expected = 'www http';
|
|
|
|
$result = String::insert($string, array('web' => 'www', 'web_site' => 'http'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-04-09 13:15:43 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$string = '2 + 2 = <sum. Cake is <adjective>.';
|
|
|
|
$expected = '2 + 2 = <sum. Cake is yummy.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '<', 'after' => '>'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '2 + 2 = \:sum. Cake is :adjective.';
|
|
|
|
$expected = '2 + 2 = :sum. Cake is yummy.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '2 + 2 = !:sum. Cake is :adjective.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('escape' => '!'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '2 + 2 = \%sum. Cake is %adjective.';
|
|
|
|
$expected = '2 + 2 = %sum. Cake is yummy.';
|
|
|
|
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '%'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = ':a :b \:a :a';
|
|
|
|
$expected = '1 2 :a 1';
|
|
|
|
$result = String::insert($string, array('a' => 1, 'b' => 2));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = ':a :b :c';
|
|
|
|
$expected = '2 3';
|
|
|
|
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = ':a :b :c';
|
|
|
|
$expected = '1 3';
|
|
|
|
$result = String::insert($string, array('a' => 1, 'c' => 3), array('clean' => true));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = ':a :b :c';
|
|
|
|
$expected = '2 3';
|
|
|
|
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = ':a, :b and :c';
|
|
|
|
$expected = '2 and 3';
|
|
|
|
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '":a, :b and :c"';
|
|
|
|
$expected = '"1, 2"';
|
|
|
|
$result = String::insert($string, array('a' => 1, 'b' => 2), array('clean' => true));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '"${a}, ${b} and ${c}"';
|
|
|
|
$expected = '"1, 2"';
|
|
|
|
$result = String::insert($string, array('a' => 1, 'b' => 2), array('before' => '${', 'after' => '}', 'clean' => true));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '<img src=":src" alt=":alt" class="foo :extra bar"/>';
|
|
|
|
$expected = '<img src="foo" class="foo bar"/>';
|
|
|
|
$result = String::insert($string, array('src' => 'foo'), array('clean' => 'html'));
|
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '<img src=":src" class=":no :extra"/>';
|
|
|
|
$expected = '<img src="foo"/>';
|
|
|
|
$result = String::insert($string, array('src' => 'foo'), array('clean' => 'html'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$string = '<img src=":src" class=":no :extra"/>';
|
|
|
|
$expected = '<img src="foo" class="bar"/>';
|
|
|
|
$result = String::insert($string, array('src' => 'foo', 'extra' => 'bar'), array('clean' => 'html'));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-31 12:36:38 +00:00
|
|
|
|
|
|
|
$result = String::insert("this is a ? string", "test");
|
|
|
|
$expected = "this is a test string";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-07-03 02:19:19 +00:00
|
|
|
$result = String::insert("this is a ? string with a ? ? ?", array('long', 'few?', 'params', 'you know'));
|
|
|
|
$expected = "this is a long string with a few? params you know";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-07-07 23:24:39 +00:00
|
|
|
|
2008-11-08 02:58:37 +00:00
|
|
|
$result = String::insert('update saved_urls set url = :url where id = :id', array('url' => 'http://www.testurl.com/param1:url/param2:id','id' => 1));
|
2008-07-07 23:24:39 +00:00
|
|
|
$expected = "update saved_urls set url = http://www.testurl.com/param1:url/param2:id where id = 1";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-07-07 23:24:39 +00:00
|
|
|
|
2008-11-08 02:58:37 +00:00
|
|
|
$result = String::insert('update saved_urls set url = :url where id = :id', array('id' => 1, 'url' => 'http://www.testurl.com/param1:url/param2:id'));
|
2008-07-07 23:24:39 +00:00
|
|
|
$expected = "update saved_urls set url = http://www.testurl.com/param1:url/param2:id where id = 1";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
|
|
|
$result = String::insert(':me cake. :subject :verb fantastic.', array('me' => 'I :verb', 'subject' => 'cake', 'verb' => 'is'));
|
2008-07-07 23:24:39 +00:00
|
|
|
$expected = "I :verb cake. cake is fantastic.";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-10-18 23:56:41 +00:00
|
|
|
$result = String::insert(':I.am: :not.yet: passing.', array('I.am' => 'We are'), array('before' => ':', 'after' => ':', 'clean' => array('replacement' => ' of course', 'method' => 'text')));
|
|
|
|
$expected = "We are of course passing.";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-07-07 23:24:39 +00:00
|
|
|
|
2009-03-09 20:03:02 +00:00
|
|
|
$result = String::insert(
|
|
|
|
':I.am: :not.yet: passing.',
|
|
|
|
array('I.am' => 'We are'),
|
|
|
|
array('before' => ':', 'after' => ':', 'clean' => true)
|
|
|
|
);
|
2008-10-18 23:56:41 +00:00
|
|
|
$expected = "We are passing.";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-03-09 20:03:02 +00:00
|
|
|
|
|
|
|
$result = String::insert('?-pended result', array('Pre'));
|
|
|
|
$expected = "Pre-pended result";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-08-03 08:10:14 +00:00
|
|
|
|
|
|
|
$string = 'switching :timeout / :timeout_count';
|
|
|
|
$expected = 'switching 5 / 10';
|
|
|
|
$result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-08-03 08:10:14 +00:00
|
|
|
|
|
|
|
$string = 'switching :timeout / :timeout_count';
|
|
|
|
$expected = 'switching 5 / 10';
|
|
|
|
$result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-08-03 08:10:14 +00:00
|
|
|
|
|
|
|
$string = 'switching :timeout_count by :timeout';
|
|
|
|
$expected = 'switching 10 by 5';
|
|
|
|
$result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-08-03 08:10:14 +00:00
|
|
|
|
|
|
|
$string = 'switching :timeout_count by :timeout';
|
|
|
|
$expected = 'switching 10 by 5';
|
|
|
|
$result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5));
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-10-18 23:56:41 +00:00
|
|
|
}
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2008-10-18 23:56:41 +00:00
|
|
|
/**
|
|
|
|
* test Clean Insert
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCleanInsert() {
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = String::cleanInsert(':incomplete', array(
|
|
|
|
'clean' => true, 'before' => ':', 'after' => ''
|
|
|
|
));
|
2008-10-18 23:56:41 +00:00
|
|
|
$this->assertEqual($result, '');
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-10-18 23:56:41 +00:00
|
|
|
$result = String::cleanInsert(':incomplete', array(
|
2008-11-08 02:58:37 +00:00
|
|
|
'clean' => array('method' => 'text', 'replacement' => 'complete'),
|
2008-10-18 23:56:41 +00:00
|
|
|
'before' => ':', 'after' => '')
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, 'complete');
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = String::cleanInsert(':in.complete', array(
|
|
|
|
'clean' => true, 'before' => ':', 'after' => ''
|
|
|
|
));
|
2008-10-18 23:56:41 +00:00
|
|
|
$this->assertEqual($result, '');
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = String::cleanInsert(':in.complete and', array(
|
|
|
|
'clean' => true, 'before' => ':', 'after' => '')
|
|
|
|
);
|
2008-10-18 23:56:41 +00:00
|
|
|
$this->assertEqual($result, '');
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = String::cleanInsert(':in.complete or stuff', array(
|
|
|
|
'clean' => true, 'before' => ':', 'after' => ''
|
|
|
|
));
|
2008-10-18 23:56:41 +00:00
|
|
|
$this->assertEqual($result, 'stuff');
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = String::cleanInsert(
|
|
|
|
'<p class=":missing" id=":missing">Text here</p>',
|
|
|
|
array('clean' => 'html', 'before' => ':', 'after' => '')
|
|
|
|
);
|
2008-10-18 23:56:41 +00:00
|
|
|
$this->assertEqual($result, '<p>Text here</p>');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that non-insertable variables (i.e. arrays) are skipped when used as values in
|
|
|
|
* String::insert().
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoIgnoreBadInsertData() {
|
2009-05-01 21:05:46 +00:00
|
|
|
$data = array('foo' => 'alpha', 'bar' => 'beta', 'fale' => array());
|
|
|
|
$result = String::insert('(:foo > :bar || :fale!)', $data, array('clean' => 'text'));
|
|
|
|
$this->assertEqual($result, '(alpha > beta || !)');
|
|
|
|
}
|
|
|
|
|
2008-07-03 02:19:19 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testTokenize method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTokenize() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = String::tokenize('A,(short,boring test)');
|
|
|
|
$expected = array('A', '(short,boring test)');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = String::tokenize('A,(short,more interesting( test)');
|
|
|
|
$expected = array('A', '(short,more interesting( test)');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = String::tokenize('A,(short,very interesting( test))');
|
|
|
|
$expected = array('A', '(short,very interesting( test))');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = String::tokenize('"single tag"', ' ', '"', '"');
|
|
|
|
$expected = array('"single tag"');
|
|
|
|
$this->assertEqual($expected, $result);
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"');
|
|
|
|
$expected = array('tagA', '"single tag"', 'tagB');
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
}
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReplaceWithQuestionMarkInString() {
|
2009-10-13 15:15:17 +00:00
|
|
|
$string = ':a, :b and :c?';
|
|
|
|
$expected = '2 and 3?';
|
|
|
|
$result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
}
|
2010-10-15 02:32:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test wrap method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWrap() {
|
2010-10-15 02:32:56 +00:00
|
|
|
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
|
|
|
|
$result = String::wrap($text, 33);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
This is the song that never ends.
|
|
|
|
This is the song that never ends.
|
|
|
|
This is the song that never ends.
|
|
|
|
TEXT;
|
|
|
|
$this->assertEquals($expected, $result, 'Text not wrapped.');
|
|
|
|
|
|
|
|
$result = String::wrap($text, array('width' => 20, 'wordWrap' => false));
|
|
|
|
$expected = <<<TEXT
|
|
|
|
This is the song th
|
|
|
|
at never ends. This
|
|
|
|
is the song that n
|
2011-05-17 04:23:30 +00:00
|
|
|
ever ends. This is
|
2010-10-15 02:32:56 +00:00
|
|
|
the song that never
|
|
|
|
ends.
|
|
|
|
TEXT;
|
|
|
|
$this->assertEquals($expected, $result, 'Text not wrapped.');
|
|
|
|
}
|
2010-10-16 02:46:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test wrap() indenting
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWrapIndent() {
|
2010-10-16 02:46:03 +00:00
|
|
|
$text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
|
|
|
|
$result = String::wrap($text, array('width' => 33, 'indent' => "\t", 'indentAt' => 1));
|
|
|
|
$expected = <<<TEXT
|
|
|
|
This is the song that never ends.
|
|
|
|
This is the song that never ends.
|
|
|
|
This is the song that never ends.
|
|
|
|
TEXT;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|