mscherer 6 年 前
コミット
7449cbe05c

+ 1 - 1
docs/TestSuite/Testing.md

@@ -102,7 +102,7 @@ $this->assertEmpty($output);
 
 $output = $this->out->output();
 $expected = 'FooBars';
-$this->assertContains($expected, $output);
+$this->assertStringContainsString($expected, $output);
 ```
 
 Also see the above trait features. By using `-v` or `-vv` you can directly see any stderr or stdout output on the screen.

+ 2 - 4
src/View/Helper/CommonHelper.php

@@ -154,7 +154,7 @@ class CommonHelper extends Helper {
 	 * @return string HTML Markup
 	 */
 	public function metaCanonical($url = null, $full = false) {
-		$canonical = $this->Url->build($url, $full);
+		$canonical = $this->Url->build($url, ['full' => $full]);
 		$options = ['rel' => 'canonical', 'link' => $canonical];
 		return $this->Html->meta($options);
 	}
@@ -172,9 +172,7 @@ class CommonHelper extends Helper {
 	 * @return string HTML Markup
 	 */
 	public function metaAlternate($url, $lang, $full = false) {
-		//$canonical = $this->Url->build($url, $full);
-		$url = $this->Url->build($url, $full);
-		//return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
+		$url = $this->Url->build($url, ['full' => $full]);
 		$lang = (array)$lang;
 		$res = [];
 		foreach ($lang as $language => $countries) {

+ 1 - 1
src/View/Helper/QrCodeHelper.php

@@ -136,7 +136,7 @@ class QrCodeHelper extends Helper {
 			case 'text':
 				break;
 			case 'url':
-				$text = $this->Url->build($text, true);
+				$text = $this->Url->build($text, ['full' => true]);
 				break;
 			case 'sms':
 				$text = 'smsto:' . implode(':', (array)$text);

+ 9 - 9
src/View/Helper/UrlHelper.php

@@ -29,7 +29,7 @@ class UrlHelper extends CoreUrlHelper {
 	 * @param array $url
 	 * @return array
 	 */
-	public function resetArray(array $url) {
+	public function resetArray(array $url): array {
 		$url += $this->defaults();
 
 		return $url;
@@ -39,7 +39,7 @@ class UrlHelper extends CoreUrlHelper {
 	 * @param array $url
 	 * @return array
 	 */
-	public function completeArray(array $url) {
+	public function completeArray(array $url): array {
 		$url = $this->addQueryStrings($url);
 
 		return $url;
@@ -52,15 +52,15 @@ class UrlHelper extends CoreUrlHelper {
 	 * Can only add defaults for array URLs.
 	 *
 	 * @param string|array|null $url URL.
-	 * @param bool $full If true, the full base URL will be prepended to the result
+	 * @param array $options
 	 * @return string Full translated URL with base path.
 	 */
-	public function buildReset($url = null, $full = false) {
+	public function buildReset($url = null, array $options = []): string {
 		if (is_array($url)) {
 			$url += $this->defaults();
 		}
 
-		return parent::build($url, $full);
+		return parent::build($url, $options);
 	}
 
 	/**
@@ -69,21 +69,21 @@ class UrlHelper extends CoreUrlHelper {
 	 * Can only add query strings for array URLs.
 	 *
 	 * @param string|array|null $url URL.
-	 * @param bool $full If true, the full base URL will be prepended to the result
+	 * @param array $options
 	 * @return string Full translated URL with base path.
 	 */
-	public function buildComplete($url = null, $full = false) {
+	public function buildComplete($url = null, array $options = []): string {
 		if (is_array($url)) {
 			$url = $this->addQueryStrings($url);
 		}
 
-		return parent::build($url, $full);
+		return parent::build($url, $options);
 	}
 
 	/**
 	 * @return array
 	 */
-	public function defaults() {
+	public function defaults(): array {
 		return [
 			'prefix' => false,
 			'plugin' => false

+ 4 - 4
tests/TestCase/Mailer/EmailTest.php

@@ -221,7 +221,7 @@ class EmailTest extends TestCase {
 		$cid = $this->Email->addEmbeddedAttachment($file);
 		$cid2 = $this->Email->addEmbeddedAttachment($file);
 		$this->assertSame($cid, $cid2);
-		$this->assertContains('@' . env('HTTP_HOST'), $cid);
+		$this->assertStringContainsString('@' . env('HTTP_HOST'), $cid);
 
 		$res = $this->Email->getProtected('attachments');
 		$this->assertSame(1, count($res));
@@ -251,7 +251,7 @@ class EmailTest extends TestCase {
 
 		$cid2 = $this->Email->addEmbeddedAttachment($file);
 
-		$this->assertContains('@' . env('HTTP_HOST'), $cid);
+		$this->assertStringContainsString('@' . env('HTTP_HOST'), $cid);
 
 		$html = '<head>
 	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
@@ -286,7 +286,7 @@ html-part
 		$this->Email->setEmailFormat('both');
 		$cid = $this->Email->addEmbeddedBlobAttachment(file_get_contents($file), 'my_hotel.png');
 
-		$this->assertContains('@' . env('HTTP_HOST'), $cid);
+		$this->assertStringContainsString('@' . env('HTTP_HOST'), $cid);
 
 		$res = $this->Email->getProtected('attachments');
 		$this->assertSame(1, count($res));
@@ -352,7 +352,7 @@ html-part
 		$this->Email->setTo(Configure::read('Config.adminEmail'));
 		$cid = $this->Email->addEmbeddedBlobAttachment(file_get_contents($file), 'my_hotel.png', 'image/png');
 
-		$this->assertContains('@' . env('HTTP_HOST'), $cid);
+		$this->assertStringContainsString('@' . env('HTTP_HOST'), $cid);
 
 		$html = '<head>
 	<meta http-equiv="content-type" content="text/html; charset=utf-8" />

+ 9 - 13
tests/TestCase/View/Helper/CommonHelperTest.php

@@ -35,7 +35,7 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaRobots() {
 		$result = $this->Common->metaRobots();
-		$this->assertContains('<meta name="robots" content="', $result);
+		$this->assertStringContainsString('<meta name="robots" content="', $result);
 	}
 
 	/**
@@ -101,7 +101,7 @@ class CommonHelperTest extends TestCase {
 		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1') . '" rel="canonical"/>', trim($is));
 
 		$is = $this->Common->metaCanonical('/some/url/param1', true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', true) . '" rel="canonical"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', ['full' => true]) . '" rel="canonical"/>', trim($is));
 	}
 
 	/**
@@ -109,24 +109,22 @@ class CommonHelperTest extends TestCase {
 	 */
 	public function testMetaAlternate() {
 		$is = $this->Common->metaAlternate('/some/url/param1', 'de-de', true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', true) . '" rel="alternate" hreflang="de-de"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', ['full' => true]) . '" rel="alternate" hreflang="de-de"/>', trim($is));
 
 		$is = $this->Common->metaAlternate(['controller' => 'some', 'action' => 'url'], 'de', true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['full' => true]) . '" rel="alternate" hreflang="de"/>', trim($is));
 
 		$is = $this->Common->metaAlternate(['controller' => 'some', 'action' => 'url'], ['de', 'de-ch'], true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de"/>' . PHP_EOL . '<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-ch"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['full' => true]) . '" rel="alternate" hreflang="de"/>' . PHP_EOL . '<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-ch"/>', trim($is));
 
 		$is = $this->Common->metaAlternate(['controller' => 'some', 'action' => 'url'], ['de' => ['ch', 'at'], 'en' => ['gb', 'us']], true);
-		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-ch"/>' . PHP_EOL .
-			'<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-at"/>' . PHP_EOL .
-			'<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="en-gb"/>' . PHP_EOL .
-			'<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="en-us"/>', trim($is));
+		$this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', ['full' => true]) . '" rel="alternate" hreflang="de-ch"/>' . PHP_EOL .
+			'<link href="' . $this->Common->Url->build('/some/url', ['full' => true]) . '" rel="alternate" hreflang="de-at"/>' . PHP_EOL .
+			'<link href="' . $this->Common->Url->build('/some/url', ['full' => true]) . '" rel="alternate" hreflang="en-gb"/>' . PHP_EOL .
+			'<link href="' . $this->Common->Url->build('/some/url', ['full' => true]) . '" rel="alternate" hreflang="en-us"/>', trim($is));
 	}
 
 	/**
-	 * CommonHelperTest::testAsp()
-	 *
 	 * @return void
 	 */
 	public function testAsp() {
@@ -140,8 +138,6 @@ class CommonHelperTest extends TestCase {
 	}
 
 	/**
-	 * CommonHelperTest::testSp()
-	 *
 	 * @return void
 	 */
 	public function testSp() {

+ 3 - 3
tests/TestCase/View/Helper/FormHelperTest.php

@@ -38,16 +38,16 @@ class FormHelperTest extends TestCase {
 		$expected = 'novalidate="novalidate"';
 
 		$result = $this->Form->create();
-		$this->assertNotContains($expected, $result);
+		$this->assertStringNotContainsString($expected, $result);
 
 		Configure::write('FormConfig.novalidate', true);
 		$this->Form = new FormHelper($this->View);
 
 		$result = $this->Form->create();
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 
 		$result = $this->Form->create(null, ['novalidate' => false]);
-		$this->assertNotContains($expected, $result);
+		$this->assertStringNotContainsString($expected, $result);
 	}
 
 }

+ 3 - 4
tests/TestCase/View/Helper/FormatHelperTest.php

@@ -249,7 +249,7 @@ class FormatHelperTest extends TestCase {
 		$result = $this->Format->siteIcon('http://www.example.org');
 		$this->debug($result);
 		$expected = '<img src="http://www.google.com/s2/favicons?domain=www.example.org';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 	}
 
 	/**
@@ -325,9 +325,8 @@ class FormatHelperTest extends TestCase {
 		$text .= "fooo\t\tbar\t\tbla\n";
 		$text .= "foooo\t\tbar\t\tbla\n";
 		$result = $this->Format->tab2space($text);
-		//echo "<pre>" . $text . "</pre>";
-		//echo'becomes';
-		//echo "<pre>" . $result . "</pre>";
+
+		$this->assertTrue(strpos($result, "\t") === false);
 	}
 
 	/**

+ 5 - 0
tests/TestCase/View/Helper/GravatarHelperTest.php

@@ -12,6 +12,11 @@ use Tools\View\Helper\GravatarHelper;
 class GravatarHelperTest extends TestCase {
 
 	/**
+	 * @var \Tools\View\Helper\GravatarHelper
+	 */
+	protected $Gravatar;
+
+	/**
 	 * SetUp method
 	 *
 	 * @return void

+ 18 - 13
tests/TestCase/View/Helper/NumberHelperTest.php

@@ -14,6 +14,11 @@ use Tools\View\Helper\NumberHelper;
 class NumberHelperTest extends TestCase {
 
 	/**
+	 * @var \Tools\View\Helper\NumberHelper|\Tools\Utility\Number
+	 */
+	protected $Number;
+
+	/**
 	 * @return void
 	 */
 	public function setUp(): void {
@@ -43,47 +48,47 @@ class NumberHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testFormat() {
-		$is = $this->Number->format('22');
+		$is = $this->Number->format(22);
 		$expected = '22';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.01');
+		$is = $this->Number->format(22.01);
 		$expected = '22,01';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22', ['places' => 2]);
+		$is = $this->Number->format(22, ['places' => 2]);
 		$expected = '22,00';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.30', ['places' => 1]);
+		$is = $this->Number->format(22.30, ['places' => 1]);
 		$expected = '22,3';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.30', ['precision' => -1]);
+		$is = $this->Number->format(22.30, ['precision' => -1]);
 		$expected = '22';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.30', ['places' => 3]);
+		$is = $this->Number->format(22.30, ['places' => 3]);
 		$expected = '22,300';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('abc', ['places' => 2]);
-		$expected = '0,00';
-		$this->assertEquals($expected, $is);
+		//$is = $this->Number->format('abc', ['places' => 2]);
+		//$expected = '0,00';
+		//$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.3', ['places' => 2, 'before' => 'EUR ']);
+		$is = $this->Number->format(22.3, ['places' => 2, 'before' => 'EUR ']);
 		$expected = 'EUR 22,30';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.3', ['places' => 2, 'after' => ' EUR']);
+		$is = $this->Number->format(22.3, ['places' => 2, 'after' => ' EUR']);
 		$expected = '22,30 EUR';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.3', ['places' => 2, 'after' => 'x', 'before' => 'v']);
+		$is = $this->Number->format(22.3, ['places' => 2, 'after' => 'x', 'before' => 'v']);
 		$expected = 'v22,30x';
 		$this->assertEquals($expected, $is);
 
-		$is = $this->Number->format('22.3', ['places' => 2, 'locale' => 'en-US']);
+		$is = $this->Number->format(22.3, ['places' => 2, 'locale' => 'en-US']);
 		$expected = '22.30';
 		$this->assertEquals($expected, $is);
 	}

+ 8 - 3
tests/TestCase/View/Helper/ObfuscateHelperTest.php

@@ -9,6 +9,11 @@ use Tools\View\Helper\ObfuscateHelper;
 class ObfuscateHelperTest extends TestCase {
 
 	/**
+	 * @var \Tools\View\Helper\ObfuscateHelper
+	 */
+	protected $Obfuscate;
+
+	/**
 	 * @return void
 	 */
 	public function setUp(): void {
@@ -39,7 +44,7 @@ class ObfuscateHelperTest extends TestCase {
 	public function testEncodeEmail() {
 		$result = $this->Obfuscate->encodeEmail('foobar@somedomain.com');
 		$expected = '<span>@</span>';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 	}
 
 	/**
@@ -48,7 +53,7 @@ class ObfuscateHelperTest extends TestCase {
 	public function testEncodeEmailUrl() {
 		$result = $this->Obfuscate->encodeEmailUrl('foobar@somedomain.com');
 		$expected = '<script language=javascript>';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 	}
 
 	/**
@@ -57,7 +62,7 @@ class ObfuscateHelperTest extends TestCase {
 	public function testEncodeText() {
 		$result = $this->Obfuscate->encodeText('foobar@somedomain.com');
 		$expected = ';&#';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 	}
 
 	/**

+ 9 - 4
tests/TestCase/View/Helper/TimeHelperTest.php

@@ -13,6 +13,11 @@ use Tools\View\Helper\TimeHelper;
 class TimeHelperTest extends TestCase {
 
 	/**
+	 * @var \Tools\View\Helper\TimeHelper|\Tools\Utility\Time
+	 */
+	protected $Time;
+
+	/**
 	 * @return void
 	 */
 	public function setUp(): void {
@@ -57,7 +62,7 @@ class TimeHelperTest extends TestCase {
 	 */
 	public function testTimeAgoInWords() {
 		$res = $this->Time->timeAgoInWords(date(FORMAT_DB_DATETIME, time() - 4 * DAY - 5 * HOUR));
-		$this->debug($res);
+		$this->assertSame('4 day, 5 hour ago', $res);
 	}
 
 	/**
@@ -68,15 +73,15 @@ class TimeHelperTest extends TestCase {
 	public function testPublished() {
 		$result = $this->Time->published((new Time(date(FORMAT_DB_DATETIME)))->addSeconds(1));
 		$expected = 'class="published today';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 
 		$result = $this->Time->published((new Time(date(FORMAT_DB_DATETIME)))->addDays(1));
 		$expected = 'class="published notyet';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 
 		$result = $this->Time->published((new Time(date(FORMAT_DB_DATETIME)))->subDays(2));
 		$expected = 'class="published already';
-		$this->assertContains($expected, $result);
+		$this->assertStringContainsString($expected, $result);
 	}
 
 	/**

+ 2 - 2
tests/TestCase/View/Helper/TimelineHelperTest.php

@@ -71,7 +71,7 @@ class TimelineHelperTest extends TestCase {
 
 		$this->Timeline->finalize();
 		$result = $this->Timeline->getView()->fetch('script');
-		$this->assertContains('\'start\': new Date(', $result);
+		$this->assertStringContainsString('\'start\': new Date(', $result);
 	}
 
 	/**
@@ -91,7 +91,7 @@ class TimelineHelperTest extends TestCase {
 		$this->Timeline->addItem($data);
 
 		$result = $this->Timeline->finalize(true);
-		$this->assertContains('\'start\': new Date(', $result);
+		$this->assertStringContainsString('\'start\': new Date(', $result);
 	}
 
 	/**

+ 7 - 2
tests/bootstrap.php

@@ -33,12 +33,15 @@ require CORE_PATH . 'config/bootstrap.php';
 
 Cake\Core\Configure::write('App', [
 		'namespace' => 'App',
-		'encoding' => 'UTF-8']);
+		'encoding' => 'UTF-8',
+		'fullBaseUrl' => '/',
+]);
 Cake\Core\Configure::write('debug', true);
 
 Cake\Core\Configure::write('Config', [
 		'adminEmail' => 'test@example.com',
-		'adminName' => 'Mark']);
+		'adminName' => 'Mark'
+]);
 Cake\Mailer\Email::setConfig('default', ['transport' => 'Debug']);
 Cake\Mailer\TransportFactory::setConfig('Debug', [
 		'className' => 'Debug'
@@ -74,6 +77,8 @@ $cache = [
 
 Cake\Cache\Cache::setConfig($cache);
 
+Cake\Utility\Security::setSalt('foo');
+
 // Why is this required?
 require ROOT . DS . 'config' . DS . 'bootstrap.php';