Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,27 +2,31 @@
/**
* TextHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
App::uses('TextHelper', 'View/Helper');
/**
* TextHelperTestObject
*
* @package Cake.Test.Case.View.Helper
*/
class TextHelperTestObject extends TextHelper {
public function attach(StringMock $string) {
public function attach(CakeTextMock $string) {
$this->_engine = $string;
}
@ -33,9 +37,11 @@ class TextHelperTestObject extends TextHelper {
}
/**
* StringMock class
* CakeTextMock class
*
* @package Cake.Test.Case.View.Helper
*/
class StringMock {
class CakeTextMock {
}
/**
@ -68,22 +74,26 @@ class TextHelperTest extends CakeTestCase {
/**
* test String class methods are called correctly
*
* @return void
*/
public function testTextHelperProxyMethodCalls() {
$methods = array(
'highlight', 'stripLinks', 'truncate', 'excerpt', 'toList',
'highlight', 'stripLinks', 'truncate', 'tail', 'excerpt', 'toList',
);
$String = $this->getMock('StringMock', $methods);
$Text = new TextHelperTestObject($this->View, array('engine' => 'StringMock'));
$Text->attach($String);
$CakeText = $this->getMock('CakeTextMock', $methods);
$Text = new TextHelperTestObject($this->View, array('engine' => 'CakeTextMock'));
$Text->attach($CakeText);
foreach ($methods as $method) {
$String->expects($this->at(0))->method($method);
$CakeText->expects($this->at(0))->method($method);
$Text->{$method}('who', 'what', 'when', 'where', 'how');
}
}
/**
* test engine override
*
* @return void
*/
public function testEngineOverride() {
App::build(array(
@ -107,6 +117,10 @@ class TextHelperTest extends CakeTestCase {
* @return void
*/
public function testAutoLink() {
$text = 'The AWWWARD show happened today';
$result = $this->Text->autoLink($text);
$this->assertEquals($text, $result);
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLink($text);
@ -117,6 +131,10 @@ class TextHelperTest extends CakeTestCase {
$expected = 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL and <a href="mailto:test@cakephp\.org">test@cakephp\.org</a> email address';
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = 'Text with a partial <a href="//www.cakephp.org">link</a> link';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($text, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text);
@ -137,6 +155,51 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets';
$expected = 'This is a test text with URL (<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>) in brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL [http://www.cakephp.org/page/4] in square brackets';
$expected = 'This is a test text with URL [<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>] in square brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets';
$expected = 'This is a test text with URL [<a href="http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3">http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3</a>] in square brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon';
$expected = 'This is a test text with URL ;<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>; semi-colon';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets';
$expected = 'This is a test text with URL (<a href="http://www.cakephp.org/page/4/other(thing)">http://www.cakephp.org/page/4/other(thing)</a>) brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
}
/**
* Test mixing URLs and Email addresses in one confusing string.
*
* @return void
*/
public function testAutoLinkMixed() {
$text = 'Text with a url/email http://example.com/store?email=mark@example.com and email.';
$expected = 'Text with a url/email <a href="http://example.com/store?email=mark@example.com">' .
'http://example.com/store?email=mark@example.com</a> and email.';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
}
/**
* test autoLink() and options.
*
* @return void
*/
public function testAutoLinkOptions() {
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('class' => 'link'));
@ -163,10 +226,23 @@ class TextHelperTest extends CakeTestCase {
$expected = 'This is a <b>test</b> text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'test <ul>
<li>lorem: http://example.org?some</li>
<li>ipsum: http://othersite.com/abc</li>
</ul> test';
$expected = 'test <ul>
<li>lorem: <a href="http://example.org?some">http://example.org?some</a></li>
<li>ipsum: <a href="http://othersite.com/abc">http://othersite.com/abc</a></li>
</ul> test';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($expected, $result);
}
/**
* Data provider for autoLinking
*
* @return array
*/
public static function autoLinkProvider() {
return array(
@ -222,6 +298,18 @@ class TextHelperTest extends CakeTestCase {
'Text with a url http://www.not--work.com and more',
'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
),
array(
'Text with a url http://www.sub_domain.domain.pl and more',
'Text with a url <a href="http://www.sub_domain.domain.pl">http://www.sub_domain.domain.pl</a> and more',
),
array(
'Text with a partial www.küchenschöhn-not-working.de URL',
'Text with a partial <a href="http://www.küchenschöhn-not-working.de">www.küchenschöhn-not-working.de</a> URL'
),
array(
'Text with a partial http://www.küchenschöhn-not-working.de URL',
'Text with a partial <a href="http://www.küchenschöhn-not-working.de">http://www.küchenschöhn-not-working.de</a> URL'
),
);
}
@ -259,6 +347,16 @@ class TextHelperTest extends CakeTestCase {
* @return void
*/
public function testAutoLinkUrlsEscape() {
$text = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
$expected = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
$expected = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$expected = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
@ -276,50 +374,115 @@ class TextHelperTest extends CakeTestCase {
$text = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$expected = 'Text with a url &lt;a href=&quot;http://www.not-working-www.com&quot;&gt;www.not-working-www.com&lt;/a&gt; and more';
$result = $this->Text->autoLinkUrls($text);
$result = $this->Text->autoLinkUrls($text, array('escape' => true));
$this->assertEquals($expected, $result);
$text = 'Text with a url www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a url http://www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">http://www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a url http://www.www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.www.not-working-www.com">http://www.www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
}
/**
* Test autoLinkUrls with query strings.
*
* @return void
*/
public function testAutoLinkUrlsQueryString() {
$text = 'Text with a partial http://www.cakephp.org?product_id=123&foo=bar link';
$expected = 'Text with a partial <a href="http://www.cakephp.org?product_id=123&amp;foo=bar">http://www.cakephp.org?product_id=123&amp;foo=bar</a> link';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
}
/**
* testAutoLinkEmails method
* Data provider for autoLinkEmail.
*
* @return void
*/
public function testAutoLinkEmails() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLinkUrls($text);
public function autoLinkEmailProvider() {
return array(
array(
'This is a test text',
'This is a test text',
),
array(
'email@example.com address',
'<a href="mailto:email@example.com">email@example.com</a> address',
),
array(
'email@example.com address',
'<a href="mailto:email@example.com">email@example.com</a> address',
),
array(
'(email@example.com) address',
'(<a href="mailto:email@example.com">email@example.com</a>) address',
),
array(
'Text with email@example.com address',
'Text with <a href="mailto:email@example.com">email@example.com</a> address',
),
array(
"Text with o'hare._-bob@example.com address",
'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address',
),
array(
'Text with düsentrieb@küchenschöhn-not-working.de address',
'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
),
array(
'Text with me@subdomain.küchenschöhn.de address',
'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
),
array(
'Text with email@example.com address',
'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address',
array('class' => 'link'),
),
array(
'<p>mark@example.com</p>',
'<p><a href="mailto:mark@example.com">mark@example.com</a></p>',
array('escape' => false)
),
array(
'Some&nbsp;mark@example.com&nbsp;Text',
'Some&nbsp;<a href="mailto:mark@example.com">mark@example.com</a>&nbsp;Text',
array('escape' => false)
),
);
}
/**
* testAutoLinkEmails method
*
* @param string $text The text to link
* @param string $expected The expected results.
* @dataProvider autoLinkEmailProvider
* @return void
*/
public function testAutoLinkEmails($text, $expected, $attrs = array()) {
$result = $this->Text->autoLinkEmails($text, $attrs);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
$this->assertRegExp('#^' . $expected . '$#', $result);
}
/**
@ -333,5 +496,58 @@ class TextHelperTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
}
/**
* testAutoParagraph method
*
* @return void
*/
public function testAutoParagraph() {
$text = 'This is a test text';
$expected = <<<TEXT
<p>This is a test text</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$text = 'This is a <br/> <BR> test text';
$expected = <<<TEXT
<p>This is a </p>
<p> test text</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
$result = $this->Text->autoParagraph($text);
$text = 'This is a <BR id="test"/><br class="test"> test text';
$expected = <<<TEXT
<p>This is a </p>
<p> test text</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
$text = <<<TEXT
This is a test text.
This is a line return.
TEXT;
$expected = <<<TEXT
<p>This is a test text.<br />
This is a line return.</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
$text = <<<TEXT
This is a test text.
This is a new line.
TEXT;
$expected = <<<TEXT
<p>This is a test text.</p>
<p>This is a new line.</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
}
}