Skip to content

Commit

Permalink
Removing multiple param for JsBaseEngine::get() it is not needed.
Browse files Browse the repository at this point in the history
Adding get() to Mootools engine
  • Loading branch information
markstory committed Mar 15, 2009
1 parent 6b00583 commit a9da171
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
3 changes: 1 addition & 2 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -43,10 +43,9 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
* Create javascript selector for a CSS rule
*
* @param string $selector The selector that is targeted
* @param boolean $multiple Whether or not the selector could target more than one element.
* @return object instance of $this. Allows chained methods.
**/
function get($selector, $multiple = false) {
function get($selector) {
if ($selector == 'window' || $selector == 'document') {
$this->selection = "$(" . $selector .")";
} else {
Expand Down
3 changes: 1 addition & 2 deletions cake/libs/view/helpers/js.php
Expand Up @@ -487,10 +487,9 @@ function getCache($clear = true) {
* Create javascript selector for a CSS rule
*
* @param string $selector The selector that is targeted
* @param boolean $multiple Whether or not the selector could target more than one element.
* @return object instance of $this. Allows chained methods.
**/
function get($selector, $multiple = false) {
function get($selector) {
trigger_error(sprintf(__('%s does not have get() implemented', true), get_class($this)), E_USER_WARNING);
return $this;
}
Expand Down
14 changes: 11 additions & 3 deletions cake/libs/view/helpers/mootools_engine.php
Expand Up @@ -47,11 +47,19 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
* Create javascript selector for a CSS rule
*
* @param string $selector The selector that is targeted
* @param boolean $multiple Whether or not the selector could target more than one element.
* @return object instance of $this. Allows chained methods.
**/
function get($selector, $multiple = false) {

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.
Expand Down
28 changes: 25 additions & 3 deletions cake/tests/cases/libs/view/helpers/mootools_engine.test.php
@@ -1,6 +1,6 @@
<?php
/**
* JqueryEngineTestCase
* MooEngineTestCase
*
*
*
Expand All @@ -23,7 +23,7 @@
*/
App::import('Helper', array('Html', 'Js', 'MootoolsEngine'));

class JqueryEngineHelperTestCase extends CakeTestCase {
class MooEngineHelperTestCase extends CakeTestCase {
/**
* startTest
*
Expand All @@ -46,7 +46,29 @@ function endTest() {
* @return void
**/
function testSelector() {

$result = $this->Moo->get('#content');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$('content')");

$result = $this->Moo->get('a .remove');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$$('a .remove')");

$result = $this->Moo->get('document');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$(document)");

$result = $this->Moo->get('window');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$(window)");

$result = $this->Moo->get('ul');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$$('ul')");

$result = $this->Moo->get('#some_long-id.class');
$this->assertEqual($result, $this->Moo);
$this->assertEqual($this->Moo->selection, "$$('#some_long-id.class')");
}
/**
* test event binding
Expand Down

0 comments on commit a9da171

Please sign in to comment.