mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing String::insert() to allow '.' in parameters, added tests to show usage of String::cleanInsert(). Closes #5627
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7764 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f9f1c4df50
commit
5f0fd5241e
2 changed files with 38 additions and 2 deletions
|
@ -210,6 +210,7 @@ class String extends Object {
|
|||
* @param string $options An array of options, see description above
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function insert($str, $data, $options = array()) {
|
||||
$options = array_merge(
|
||||
|
@ -267,6 +268,7 @@ class String extends Object {
|
|||
* @param string $options
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
function cleanInsert($str, $options) {
|
||||
$clean = $options['clean'];
|
||||
|
@ -282,7 +284,7 @@ class String extends Object {
|
|||
switch ($clean['method']) {
|
||||
case 'html':
|
||||
$clean = array_merge(array(
|
||||
'word' => '[\w,]+',
|
||||
'word' => '[\w,.]+',
|
||||
'andText' => true,
|
||||
'replacement' => '',
|
||||
), $clean);
|
||||
|
@ -300,7 +302,7 @@ class String extends Object {
|
|||
break;
|
||||
case 'text':
|
||||
$clean = array_merge(array(
|
||||
'word' => '[\w,]+',
|
||||
'word' => '[\w,.]+',
|
||||
'gap' => '[\s]*(?:(?:and|or)[\s]*)?',
|
||||
'replacement' => '',
|
||||
), $clean);
|
||||
|
|
|
@ -177,6 +177,40 @@ class StringTest extends CakeTestCase {
|
|||
$expected = "I :verb cake. cake is fantastic.";
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$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.";
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = String::insert(':I.am: :not.yet: passing.', array('I.am' => 'We are'), array('before' => ':', 'after' => ':', 'clean' => true));
|
||||
$expected = "We are passing.";
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* test Clean Insert
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testCleanInsert() {
|
||||
$result = String::cleanInsert(':incomplete', array('clean' => true, 'before' => ':', 'after' => ''));
|
||||
$this->assertEqual($result, '');
|
||||
|
||||
$result = String::cleanInsert(':incomplete', array(
|
||||
'clean' => array('method' => 'text', 'replacement' => 'complete'),
|
||||
'before' => ':', 'after' => '')
|
||||
);
|
||||
$this->assertEqual($result, 'complete');
|
||||
|
||||
$result = String::cleanInsert(':in.complete', array('clean' => true, 'before' => ':', 'after' => ''));
|
||||
$this->assertEqual($result, '');
|
||||
|
||||
$result = String::cleanInsert(':in.complete and', array('clean' => true, 'before' => ':', 'after' => ''));
|
||||
$this->assertEqual($result, '');
|
||||
|
||||
$result = String::cleanInsert(':in.complete or stuff', array('clean' => true, 'before' => ':', 'after' => ''));
|
||||
$this->assertEqual($result, 'stuff');
|
||||
|
||||
$result = String::cleanInsert('<p class=":missing" id=":missing">Text here</p>', array('clean' => 'html', 'before' => ':', 'after' => ''));
|
||||
$this->assertEqual($result, '<p>Text here</p>');
|
||||
}
|
||||
/**
|
||||
* testTokenize method
|
||||
|
|
Loading…
Reference in a new issue