Browse Source

more tests

euromark 12 years ago
parent
commit
f2ecd41e85

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

@@ -25,8 +25,6 @@ class MobileComponentTest extends CakeTestCase {
 
 		CakeSession::delete('User');
 		Configure::delete('User');
-
-		$this->skipIf(php_sapi_name() === 'cli', 'Currently not testable via CLI');
 	}
 
 	/**

+ 56 - 0
Test/Case/Model/QurlTest.php

@@ -0,0 +1,56 @@
+<?php
+
+App::uses('Qurl', 'Tools.Model');
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+App::uses('Router', 'Routing');
+
+class QurlTest extends MyCakeTestCase {
+
+	public $Qurl = null;
+
+	public $fixtures = array('plugin.tools.qurl');
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->Qurl = ClassRegistry::init('Tools.Qurl');
+	}
+
+	public function testQurlInstance() {
+		$this->assertInstanceOf('Qurl', $this->Qurl);
+	}
+
+	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);
+
+		$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));
+	}
+
+	public function testUse() {
+		$key = $this->Qurl->generate(array('controller' => 'test', 'action' => 'foo', 'bar'), array('note' => 'x'));
+		$res = $this->Qurl->translate($key);
+		$this->assertTrue(is_array($res) && !empty($res));
+		$this->assertSame('x', $res['Qurl']['note']);
+		$this->assertTrue(is_array($res['Qurl']['content']));
+
+		$key = $this->Qurl->generate('/test/foo/bar');
+		$res = $this->Qurl->translate($key);
+		$this->assertTrue(is_array($res) && !empty($res));
+
+		$res = $this->Qurl->translate('foobar');
+		$this->assertFalse($res);
+	}
+
+	//TODO
+
+}

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

@@ -40,6 +40,58 @@ class MyHelperTest extends MyCakeTestCase {
 		$this->assertTrue(class_exists('QrCodeHelper'));
 	}
 
+	/**
+	 * MyHelperTest::testBeforeRender()
+	 *
+	 * @return void
+	 */
+	public function testBeforeRender() {
+		$this->MyHelper->beforeRender('');
+	}
+
+	/**
+	 * MyHelperTest::testAfterLayout()
+	 *
+	 * @return void
+	 */
+	public function testAfterLayout() {
+		$this->MyHelper->afterLayout('');
+	}
+
+	/**
+	 * MyHelperTest::testUrl()
+	 *
+	 * @return void
+	 */
+	public function testUrl() {
+		$result = $this->MyHelper->url();
+		$this->assertEquals('/', $result);
+
+		$result = $this->MyHelper->url(null, true);
+		$this->assertEquals(Configure::read('App.fullBaseUrl') . '/', $result);
+	}
+
+	/**
+	 * MyHelperTest::testAssetUrl()
+	 *
+	 * @return void
+	 */
+	public function testAssetUrl() {
+		$result = $this->MyHelper->assetUrl('/some/string');
+		debug($result);
+		$this->assertEquals('/some/string', $result);
+
+		Configure::write('App.assetBaseUrl', 'http://cdn.domain.com');
+		$result = $this->MyHelper->assetUrl('/some/string');
+		$this->assertEquals(Configure::read('App.assetBaseUrl') . '/some/string', $result);
+
+		$result = $this->MyHelper->assetUrl('/some/string', array('ext' => 'json'));
+		$this->assertEquals(Configure::read('App.assetBaseUrl') . '/some/string.json', $result);
+
+		$result = $this->MyHelper->assetUrl('some/string', array('pathPrefix' => 'foo/'));
+		$this->assertEquals(Configure::read('App.assetBaseUrl') . '/foo/some/string', $result);
+	}
+
 }
 
 class MyHtmlHelper extends MyHelper {

+ 38 - 6
Test/Case/View/Helper/WeatherHelperTest.php

@@ -14,18 +14,50 @@ class WeatherHelperTest extends MyCakeTestCase {
 
 		$this->Weather = new WeatherHelper(new View(null));
 		$this->Weather->Html = new HtmlHelper(new View(null));
+	}
+
+	/**
+	 * WeatherHelperTest::testImageUrl()
+	 *
+	 * @return void
+	 */
+	public function testImageUrl() {
+		$res = $this->Weather->imageUrl('sunny', 'gif');
+		$this->assertEquals('http://www.google.com/ig/images/weather/sunny.gif', $res);
+
+		Configure::write('Weather.imageUrl', '/img/');
+		$this->Weather = new WeatherHelper(new View(null));
+		$this->Weather->Html = new HtmlHelper(new View(null));
+		$res = $this->Weather->imageUrl('foo', 'jpg');
+		$this->assertEquals('/img/foo.jpg', $res);
 
-		$this->skipIf(!Configure::read('Weather.key'));
+		$res = $this->Weather->imageUrl('foo', 'jpg', true);
+		$this->assertEquals(Configure::read('App.fullBaseUrl') . '/img/foo.jpg', $res);
 	}
 
-	/** TODO **/
+	/**
+	 * WeatherHelperTest::testGet()
+	 *
+	 * @return void
+	 */
+	public function testGet() {
+		$this->skipIf(!Configure::read('Weather.key'), 'Only for webrunner');
+		$res = $this->Weather->get('Berlin, Deutschland');
+		$this->out($res);
+	}
+
+	/**
+	 * WeatherHelperTest::testDisplayDebug()
+	 *
+	 * @return void
+	 */
+	public function testDisplayDebug() {
+		$this->skipIf(!Configure::read('Weather.key'), 'Only for webrunner');
 
-	public function testDisplay() {
 		$res = $this->Weather->get('51.0872,13.8028');
 		$res = $this->_displayForecast($res);
 		$this->out($res);
-		//debug($res);
-		$this->assertTrue(empty($res)); // NEW
+		$this->assertTrue(!empty($res));
 
 		$res = $this->Weather->get('Berlin, Deutschland');
 		$res = $this->_displayForecast($res);
@@ -42,7 +74,7 @@ class WeatherHelperTest extends MyCakeTestCase {
 		$this->assertTrue(empty($res));
 	}
 
-	public function _displayForecast($w) {
+	protected function _displayForecast($w) {
 		$res = '';
 		if (empty($w['request'])) {
 			return $res;

+ 2 - 2
View/Helper/MyHelper.php

@@ -135,9 +135,9 @@ class MyHelper extends Helper {
 		if (
 			!empty($options['ext']) &&
 			strpos($path, '?') === false &&
-			substr($path, -strlen($options['ext'])) !== $options['ext']
+			substr($path, -strlen($options['ext']) + 1) !== '.' . $options['ext']
 		) {
-			$path .= $options['ext'];
+			$path .= '.' . $options['ext'];
 		}
 		if (isset($plugin)) {
 			$path = Inflector::underscore($plugin) . '/' . $path;

+ 14 - 32
View/Helper/WeatherHelper.php

@@ -12,48 +12,30 @@ class WeatherHelper extends AppHelper {
 
 	public $helpers = array('Html');
 
-	public $imagePath = ''; //'http://www.google.com/ig/images/weather/';
-
-	public $imageUrl = '';
+	protected $_defaults = array(
+		'imageUrl' => 'http://www.google.com/ig/images/weather/'
+	);
 
 	public function __construct($View = null, $settings = array()) {
-		parent::__construct($View, $settings);
-
-		$this->imageUrl = $this->imagePath;
+		$this->_defaults = (array)Configure::read('Weather') + $this->_defaults;
+		parent::__construct($View, $settings + $this->_defaults);
 	}
 
 	/**
-	 * Display a ready table
-	 *
-	 * //TODO
+	 * Generates icon URL.
 	 *
-	 * @return string
-	 */
-	public function display($location) {
-		$weather = $this->get($location);
-
-		$res = '';
-		if (empty($weather)) {
-			return $res;
-		}
-
-		$res .= '<table><tr>';
-		//$res .= '<td>'.[].'</td>';
-		$res .= '</tr></table>';
-
-		$res .= '<h1>' . h($weather['city']) . ':</h1>';
-
-		return $res;
-	}
-
-	/**
-	 * @return string
+	 * @param string $icon
+	 * @param string $ext
+	 * @param boolean $full
+	 * @return string URL
 	 */
-	public function imageUrl($icon, $full = false) {
-		return $this->imageUrl . $icon;
+	public function imageUrl($icon, $ext = 'gif', $full = false) {
+		return $this->Html->url($this->settings['imageUrl'] . $icon . '.' . $ext, $full);
 	}
 
 	/**
+	 * Gets weather data.
+	 *
 	 * @return array
 	 */
 	public function get($location, $cOptions = array()) {