From da2361de146d0043d3efecd5a96f5e8d05fbee27 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 28 Mar 2009 11:50:57 -0400 Subject: [PATCH] Adding get() + tests to prototype --- cake/libs/view/helpers/prototype_engine.php | 125 ++++++++++++++++++ .../view/helpers/prototype_engine.test.php | 122 +++++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 cake/libs/view/helpers/prototype_engine.php create mode 100644 cake/tests/cases/libs/view/helpers/prototype_engine.test.php diff --git a/cake/libs/view/helpers/prototype_engine.php b/cake/libs/view/helpers/prototype_engine.php new file mode 100644 index 00000000000..5d595a4c47f --- /dev/null +++ b/cake/libs/view/helpers/prototype_engine.php @@ -0,0 +1,125 @@ + + * Copyright 2006-2008, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake. + * @version + * @modifiedby + * @lastmodified + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +App::import('Helper', 'Js'); + +class PrototypeEngineHelper extends JsBaseEngineHelper { +/** + * Option mappings for Prototype + * + * @var array + **/ + var $_optionMap = array( + + ); +/** + * Create javascript selector for a CSS rule + * + * @param string $selector The selector that is targeted + * @return object instance of $this. Allows chained methods. + **/ + function get($selector) { + if ($selector == 'window' || $selector == 'document') { + $this->selection = "$(" . $selector .")"; + return $this; + } + if (preg_match('/^#[^\s.]+$/', $selector)) { + $this->selection = '$("' . substr($selector, 1) . '")'; + return $this; + } + $this->selection = '$$("' . $selector . '")'; + return $this; + } +/** + * Add an event to the script cache. Operates on the currently selected elements. + * + * ### Options + * + * - 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults true) + * - 'stop' - Whether you want the event to stopped. (defaults true) + * + * @param string $type Type of event to bind to the current dom id + * @param string $callback The Javascript function you wish to trigger or the function literal + * @param array $options Options for the event. + * @return string completed event handler + **/ + function event($type, $callback, $options = array()) { + + } +/** + * Create a domReady event. This is a special event in many libraries + * + * @param string $functionBody The code to run on domReady + * @return string completed domReady method + **/ + function domReady($functionBody) { + + } +/** + * Create an iteration over the current selection result. + * + * @param string $method The method you want to apply to the selection + * @param string $callback The function body you wish to apply during the iteration. + * @return string completed iteration + **/ + function each($callback) { + + } +/** + * Trigger an Effect. + * + * @param string $name The name of the effect to trigger. + * @param array $options Array of options for the effect. + * @return string completed string with effect. + * @see JsBaseEngineHelper::effect() + **/ + function effect($name, $options = array()) { + + } +/** + * Create an Ajax or Ajax.Updater call. + * + * @param mixed $url + * @param array $options + * @return string The completed ajax call. + **/ + function request($url, $options = array()) { + + } +/** + * Create a sortable element. + * + * Requires both Ui.Core and Ui.Sortables to be loaded. + * + * @param array $options Array of options for the sortable. + * @return string Completed sortable script. + * @see JsHelper::sortable() for options list. + **/ + function sortable($options = array()) { + + } +} +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php new file mode 100644 index 00000000000..c80a96013dd --- /dev/null +++ b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php @@ -0,0 +1,122 @@ + + * Copyright 2006-2008, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake.tests + * @subpackage cake.tests.cases.views.helpers + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +App::import('Helper', array('Html', 'Js', 'PrototypeEngine')); + +class PrototypeEngineHelperTestCase extends CakeTestCase { +/** + * startTest + * + * @return void + **/ + function startTest() { + $this->Proto =& new PrototypeEngineHelper(); + } +/** + * end test + * + * @return void + **/ + function endTest() { + unset($this->Proto); + } +/** + * test selector method + * + * @return void + **/ + function testSelector() { + $result = $this->Proto->get('#content'); + $this->assertEqual($result, $this->Proto); + $this->assertEqual($this->Proto->selection, '$("content")'); + + $result = $this->Proto->get('a .remove'); + $this->assertEqual($result, $this->Proto); + $this->assertEqual($this->Proto->selection, '$$("a .remove")'); + + $result = $this->Proto->get('document'); + $this->assertEqual($result, $this->Proto); + $this->assertEqual($this->Proto->selection, "$(document)"); + + $result = $this->Proto->get('window'); + $this->assertEqual($result, $this->Proto); + $this->assertEqual($this->Proto->selection, "$(window)"); + + $result = $this->Proto->get('ul'); + $this->assertEqual($result, $this->Proto); + $this->assertEqual($this->Proto->selection, '$$("ul")'); + + $result = $this->Proto->get('#some_long-id.class'); + $this->assertEqual($result, $this->Proto); + $this->assertEqual($this->Proto->selection, '$$("#some_long-id.class")'); + } +/** + * test event binding + * + * @return void + **/ + function testEvent() { + + } +/** + * test dom ready event creation + * + * @return void + **/ + function testDomReady() { + + } +/** + * test Each method + * + * @return void + **/ + function testEach() { + + } +/** + * test Effect generation + * + * @return void + **/ + function testEffect() { + + } +/** + * Test Request Generation + * + * @return void + **/ + function testRequest() { + + } +/** + * test sortable list generation + * + * @return void + **/ + function testSortable() { + + } +} +?> \ No newline at end of file