euromark 11 年之前
父节点
当前提交
e1e9ef26c2

+ 1 - 0
Controller/Component/MobileComponent.php

@@ -301,6 +301,7 @@ class MobileComponent extends Component {
 			$result &= !$MobileDetect->isTablet();
 		}
 
+		$this->Session->write('Session.mobile', (bool)$result);
 		return (bool)$result;
 	}
 

+ 2 - 2
Model/MyModel.php

@@ -1006,11 +1006,11 @@ class MyModel extends Model {
 		}
 
 		// validation
-		if (!Validation::url($url, $options['strict']) && env('REMOTE_ADDR') !== '127.0.0.1') {
+		if (!Validation::url($url, $options['strict']) && env('REMOTE_ADDR') && env('REMOTE_ADDR') !== '127.0.0.1') {
 			return false;
 		}
 		// same domain?
-		if (!empty($options['sameDomain']) && !empty($_SERVER['HTTP_HOST'])) {
+		if (!empty($options['sameDomain']) && env('HTTP_HOST')) {
 			$is = parse_url($url, PHP_URL_HOST);
 			$expected = env('HTTP_HOST');
 			if (mb_strtolower($is) !== mb_strtolower($expected)) {

+ 4 - 0
Test/Case/Controller/Component/MobileComponentTest.php

@@ -1,6 +1,7 @@
 <?php
 
 App::uses('MobileComponent', 'Tools.Controller/Component');
+App::uses('CakeSession', 'Model/Datasource');
 App::uses('Component', 'Controller');
 App::uses('AppController', 'Controller');
 
@@ -23,7 +24,10 @@ class MobileComponentTest extends CakeTestCase {
 		$this->Controller->constructClasses();
 		$this->Controller->Mobile->Controller = $this->Controller;
 
+		CakeSession::write('User', '');
 		CakeSession::delete('User');
+		CakeSession::write('Session', '');
+		CakeSession::delete('Session');
 		Configure::delete('User');
 	}
 

+ 1 - 6
Test/Case/Model/QurlTest.php

@@ -21,18 +21,13 @@ class QurlTest extends MyCakeTestCase {
 	}
 
 	public function testGenerate() {
-		$url = Router::url(array('admin' => false, 'plugin' => 'tools', 'controller' => 'qurls', 'action' => 'go'), true) . '/';
-		$this->debug($url);
-		$this->assertNotEmpty($url);
-		//$this->assertContains('/tools/qurl/go', $url);
+		$url = Router::url(array('admin' => false, 'plugin' => 'tools', 'controller' => 'qurls', 'action' => 'go'), true);
 
 		$res = $this->Qurl->url(array('controller' => 'test', 'action' => 'foo', 'bar'), array('note' => 'x'));
-		$this->debug($res);
 		$this->assertTrue(is_string($res) && !empty($res));
 		$this->assertTrue(strpos($res, $url) === 0);
 
 		$res = $this->Qurl->url('/test/foo/bar');
-		$this->debug($res);
 		$this->assertTrue(is_string($res) && !empty($res));
 	}
 

+ 4 - 9
Test/Case/View/Helper/CommonHelperTest.php

@@ -14,9 +14,6 @@ class CommonHelperTest extends MyCakeTestCase {
 
 	public function setUp() {
 		parent::setUp();
-		if (!Configure::read('App.fullBaseUrl')) {
-			Configure::write('App.fullBaseUrl', 'http://localhost');
-		}
 
 		$View = new View(null);
 		$this->Common = new CommonHelper($View);
@@ -27,19 +24,17 @@ class CommonHelperTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testMetaCanonical() {
-		$this->skipIf(php_sapi_name() === 'cli', 'Strange result on travis - skip for now');
-
 		$is = $this->Common->metaCanonical('/some/url/param1');
-		$this->out(h($is));
-		$this->assertEquals('<link href="' . Configure::read('App.fullBaseUrl') . $this->Html->url('/some/url/param1') . '" rel="canonical" />', trim($is));
+		$this->assertEquals('<link href="' . $this->Html->url('/some/url/param1') . '" rel="canonical" />', trim($is));
+
+		$is = $this->Common->metaCanonical('/some/url/param1', true);
+		$this->assertEquals('<link href="' . $this->Html->url('/some/url/param1', true) . '" rel="canonical" />', trim($is));
 	}
 
 	/**
 	 * @return void
 	 */
 	public function testMetaAlternate() {
-		$this->skipIf(php_sapi_name() === 'cli', 'Strange result on travis - skip for now');
-
 		$is = $this->Common->metaAlternate('/some/url/param1', 'de-de', true);
 		$this->out(h($is));
 		$this->assertEquals('<link href="' . $this->Html->url('/some/url/param1', true) . '" rel="alternate" hreflang="de-de" />', trim($is));

+ 0 - 1
Test/Case/View/Helper/MyHelperTest.php

@@ -78,7 +78,6 @@ class MyHelperTest extends MyCakeTestCase {
 	 */
 	public function testAssetUrl() {
 		$result = $this->MyHelper->assetUrl('/some/string');
-		debug($result);
 		$this->assertEquals('/some/string', $result);
 
 		Configure::write('App.assetBaseUrl', 'http://cdn.domain.com');

+ 2 - 1
View/Helper/CommonHelper.php

@@ -123,7 +123,8 @@ class CommonHelper extends AppHelper {
 	 * @return string htmlMarkup
 	 */
 	public function metaAlternate($url, $lang, $full = false) {
-		$canonical = $this->Html->url($url, $full);
+		//$canonical = $this->Html->url($url, $full);
+		$url = $this->Html->url($url, $full);
 		//return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
 		$lang = (array)$lang;
 		$res = array();