Browse Source

Remove outdated stuff.

mscherer 8 years ago
parent
commit
a490ac1543

+ 1 - 10
src/Utility/Mime.php

@@ -2,7 +2,7 @@
 
 namespace Tools\Utility;
 
-use Cake\Network\Response;
+use Cake\Http\Response;
 
 /**
  * Wrapper to be able to read cake core's mime types as well as fix for missing ones
@@ -28,11 +28,8 @@ class Mime extends Response {
 		'afl' => 'video/animaflex',
 		'ai' => 'application/postscript',
 		'aif' => 'audio/aiff',
-		'aif' => 'audio/x-aiff',
 		'aifc' => 'audio/aiff',
-		'aifc' => 'audio/x-aiff',
 		'aiff' => 'audio/aiff',
-		'aiff' => 'audio/x-aiff',
 		'aim' => 'application/x-aim',
 		'aip' => 'text/x-audiosoft-intra',
 		'ani' => 'application/x-navi-animation',
@@ -40,7 +37,6 @@ class Mime extends Response {
 		'aps' => 'application/mime',
 		'arc' => 'application/octet-stream',
 		'arj' => 'application/arj',
-		'arj' => 'application/octet-stream',
 		'art' => 'image/x-jg',
 		'asf' => 'video/x-ms-asf',
 		'asm' => 'text/x-asm',
@@ -103,7 +99,6 @@ class Mime extends Response {
 		'crt' => 'application/x-x509-user-cert',
 		'csh' => 'application/x-csh',
 		'csh' => 'text/x-script.csh',
-		'css' => 'application/x-pointplus',
 		'css' => 'text/css',
 		'cxx' => 'text/plain',
 		'dcr' => 'application/x-director',
@@ -113,7 +108,6 @@ class Mime extends Response {
 		'dif' => 'video/x-dv',
 		'dir' => 'application/x-director',
 		'dl' => 'video/dl',
-		'dl' => 'video/x-dl',
 		'doc' => 'application/msword',
 		'dot' => 'application/msword',
 		'dp' => 'application/commonground',
@@ -124,10 +118,8 @@ class Mime extends Response {
 		'dwf' => 'model/vnd.dwf',
 		'dwg' => 'application/acad',
 		'dwg' => 'image/vnd.dwg',
-		'dwg' => 'image/x-dwg',
 		'dxf' => 'application/dxf',
 		'dxf' => 'image/vnd.dwg',
-		'dxf' => 'image/x-dwg',
 		'dxr' => 'application/x-director',
 		'el' => 'text/x-script.elisp',
 		'elc' => 'application/x-bytecode.elisp',
@@ -664,7 +656,6 @@ class Mime extends Response {
 		'js' => 'application/javascript',
 		'json' => 'application/json',
 		'xml' => 'application/xml',
-		'swf' => 'application/x-shockwave-flash',
 		'flv' => 'video/x-flv',
 		'asc' => 'text/plain',
 		'atom' => 'application/atom+xml',

+ 30 - 7
src/View/Helper/TimelineHelper.php

@@ -15,13 +15,14 @@ use Cake\View\Helper;
  * @link http://almende.github.io/chap-links-library/timeline.html
  * @author Mark Scherer
  * @license MIT
+ * @property \Cake\View\Helper\HtmlHelper $Html
  */
 class TimelineHelper extends Helper {
 
 	/**
 	 * @var array
 	 */
-	public $helpers = ['Tools.Js'];
+	public $helpers = ['Html'];
 
 	/**
 	 * Possible values are (with their default values):
@@ -100,10 +101,12 @@ class TimelineHelper extends Helper {
 	 * Make sure that your view does also output the buffer at some place!
 	 *
 	 * @param bool $return If the output should be returned instead
-	 * @return void|string Javascript if $return is true
+	 * @param array $scriptOptions
+	 *
+	 * @return null|string Javascript if $return is true
 	 */
-	public function finalize($return = false) {
-		$settings = $this->config();
+	public function finalize($return = false, array $scriptOptions = []) {
+		$settings = $this->getConfig();
 		$timelineId = $settings['id'];
 		$data = $this->_format($this->_items);
 
@@ -140,7 +143,7 @@ JS;
 		if ($return) {
 			return $script;
 		}
-		$this->Js->buffer($script);
+		$this->_buffer($script, $scriptOptions);
 	}
 
 	/**
@@ -203,11 +206,11 @@ JS;
 	/**
 	 * Format date to JS code.
 	 *
-	 * @param \DateTime|null $date
+	 * @param \DateTimeInterface|null $date
 	 * @return string
 	 */
 	protected function _date($date = null) {
-		if ($date === null || !$date instanceof \DateTime) {
+		if ($date === null || !$date instanceof \DateTimeInterface) {
 			return '';
 		}
 		$datePieces = [];
@@ -222,4 +225,24 @@ JS;
 		return 'new Date(' . implode(', ', $datePieces) . ')';
 	}
 
+	/**
+	 * Options:
+	 * - `safe` (boolean) Whether or not the $script should be wrapped in `<![CDATA[ ]]>`.
+	 *   Defaults to `false`.
+	 * - `block` You can chose a different view block to write to (defaults to "script" one).
+	 *
+	 * @param string $script
+	 * @param array $options
+	 *
+	 * @return void
+	 */
+	protected function _buffer($script, array $options = []) {
+		$defaults = [
+			'block' => true
+		];
+		$options += $defaults;
+
+		$this->Html->scriptBlock($script, $options);
+	}
+
 }

+ 15 - 0
tests/TestApp/View/Helper/TimelineHelper.php

@@ -0,0 +1,15 @@
+<?php
+namespace TestApp\View\Helper;
+
+use Tools\View\Helper\TimelineHelper as ToolsTimelineHelper;
+
+class TimelineHelper extends ToolsTimelineHelper {
+
+	/**
+	 * @return array
+	 */
+	public function items() {
+		return $this->_items;
+	}
+
+}

+ 1 - 1
tests/TestCase/Utility/MimeTest.php

@@ -3,7 +3,7 @@
 namespace Tools\Test\TestCase\Utility;
 
 use Cake\Core\Plugin;
-use Cake\Network\Response;
+use Cake\Http\Response;
 use Tools\TestSuite\TestCase;
 use Tools\Utility\Mime;
 

+ 24 - 16
tests/TestCase/View/Helper/TimelineHelperTest.php

@@ -5,7 +5,7 @@ namespace Tools\Test\TestCase\View\Helper;
 use Cake\View\View;
 use DateTime;
 use Tools\TestSuite\TestCase;
-use Tools\View\Helper\TimelineHelper;
+use TestApp\View\Helper\TimelineHelper;
 
 /**
  * Timeline Helper Test Case
@@ -13,19 +13,17 @@ use Tools\View\Helper\TimelineHelper;
 class TimelineHelperTest extends TestCase {
 
 	/**
-	 * @var \Tools\View\Helper\TimelineHelper
+	 * @var \Tools\View\Helper\TimelineHelper|\TestApp\View\Helper\TimelineHelper
 	 */
 	public $Timeline;
 
 	/**
-	 * TimelineHelperTest::setUp()
-	 *
 	 * @return void
 	 */
 	public function setUp() {
 		parent::setUp();
 
-		$this->Timeline = new TimelineTestHelper(new View(null));
+		$this->Timeline = new TimelineHelper(new View(null));
 	}
 
 	/**
@@ -71,28 +69,38 @@ class TimelineHelperTest extends TestCase {
 		];
 		$this->Timeline->addItem($data);
 
-		$result = $this->Timeline->finalize(true);
+		$this->Timeline->finalize();
+		$result = $this->Timeline->getView()->fetch('script');
 		$this->assertContains('\'start\': new Date(', $result);
 	}
 
 	/**
 	 * @return void
 	 */
-	public function tearDown() {
-		parent::tearDown();
+	public function testFinalizeReturnScript() {
+		$this->testAddItem();
+		$data = [
+			'start' => new DateTime(),
+			'content' => '',
+		];
+		$this->Timeline->addItem($data);
+		$data = [
+			'start' => new DateTime(date(FORMAT_DB_DATE)),
+			'content' => '',
+		];
+		$this->Timeline->addItem($data);
 
-		unset($this->Timeline);
+		$result = $this->Timeline->finalize(true);
+		$this->assertContains('\'start\': new Date(', $result);
 	}
 
-}
-
-class TimelineTestHelper extends TimelineHelper {
-
 	/**
-	 * @return array
+	 * @return void
 	 */
-	public function items() {
-		return $this->_items;
+	public function tearDown() {
+		parent::tearDown();
+
+		unset($this->Timeline);
 	}
 
 }