2009-03-15 21:32:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-15 21:48:27 +00:00
|
|
|
* MooEngineTestCase
|
2009-03-15 21:32:04 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* 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', 'MootoolsEngine'));
|
|
|
|
|
2009-03-15 21:48:27 +00:00
|
|
|
class MooEngineHelperTestCase extends CakeTestCase {
|
2009-03-15 21:32:04 +00:00
|
|
|
/**
|
|
|
|
* startTest
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function startTest() {
|
|
|
|
$this->Moo =& new MootoolsEngineHelper();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* end test
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function endTest() {
|
|
|
|
unset($this->Moo);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test selector method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testSelector() {
|
2009-03-15 21:48:27 +00:00
|
|
|
$result = $this->Moo->get('#content');
|
|
|
|
$this->assertEqual($result, $this->Moo);
|
2009-03-15 23:59:16 +00:00
|
|
|
$this->assertEqual($this->Moo->selection, '$("content")');
|
2009-03-15 21:48:27 +00:00
|
|
|
|
|
|
|
$result = $this->Moo->get('a .remove');
|
|
|
|
$this->assertEqual($result, $this->Moo);
|
2009-03-15 23:59:16 +00:00
|
|
|
$this->assertEqual($this->Moo->selection, '$$("a .remove")');
|
2009-03-15 21:48:27 +00:00
|
|
|
|
|
|
|
$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);
|
2009-03-15 23:59:16 +00:00
|
|
|
$this->assertEqual($this->Moo->selection, '$$("ul")');
|
2009-03-15 21:48:27 +00:00
|
|
|
|
|
|
|
$result = $this->Moo->get('#some_long-id.class');
|
|
|
|
$this->assertEqual($result, $this->Moo);
|
2009-03-15 23:59:16 +00:00
|
|
|
$this->assertEqual($this->Moo->selection, '$$("#some_long-id.class")');
|
2009-03-15 21:32:04 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test event binding
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testEvent() {
|
2009-03-15 22:48:34 +00:00
|
|
|
$result = $this->Moo->get('#myLink')->event('click', 'doClick', array('wrap' => false));
|
2009-03-15 23:59:16 +00:00
|
|
|
$expected = '$("myLink").addEvent("click", doClick);';
|
2009-03-15 22:48:34 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
|
2009-03-15 22:48:34 +00:00
|
|
|
$result = $this->Moo->get('#myLink')->event('click', 'this.setStyle("display", "");', array('stop' => false));
|
2009-03-15 23:59:16 +00:00
|
|
|
$expected = '$("myLink").addEvent("click", function (event) {this.setStyle("display", "");});';
|
2009-03-15 22:48:34 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->get('#myLink')->event('click', 'this.setStyle("display", "none");');
|
2009-03-16 01:51:00 +00:00
|
|
|
$expected = "\$(\"myLink\").addEvent(\"click\", function (event) {event.stop();\nthis.setStyle(\"display\", \"none\");});";
|
2009-03-15 22:48:34 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test dom ready event creation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testDomReady() {
|
2009-03-15 23:59:16 +00:00
|
|
|
$result = $this->Moo->domReady('foo.name = "bar";');
|
|
|
|
$expected = 'window.addEvent("domready", function (event) {foo.name = "bar";});';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test Each method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testEach() {
|
2009-03-15 23:59:16 +00:00
|
|
|
$result = $this->Moo->get('#foo')->each('item.setStyle("display", "none");');
|
|
|
|
$expected = '$("foo").each(function (item, index) {item.setStyle("display", "none");});';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test Effect generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testEffect() {
|
2009-03-15 23:59:16 +00:00
|
|
|
$result = $this->Moo->get('#foo')->effect('show');
|
|
|
|
$expected = '$("foo").setStyle("display", "");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('hide');
|
|
|
|
$expected = '$("foo").setStyle("display", "none");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('fadeIn');
|
|
|
|
$expected = '$("foo").fade("in");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('fadeOut');
|
|
|
|
$expected = '$("foo").fade("out");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('slideIn');
|
|
|
|
$expected = '$("foo").slide("in");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('slideOut');
|
|
|
|
$expected = '$("foo").slide("out");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('slideOut', array('speed' => 'fast'));
|
|
|
|
$expected = '$("foo").set("slide", {duration:"short"}).slide("out");';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->effect('slideOut', array('speed' => 'slow'));
|
|
|
|
$expected = '$("foo").set("slide", {duration:"long"}).slide("out");';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Test Request Generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testRequest() {
|
2009-03-16 02:15:22 +00:00
|
|
|
$result = $this->Moo->request(array('controller' => 'posts', 'action' => 'view', 1));
|
|
|
|
$expected = 'var jsRequest = new Request({url:"/posts/view/1"}).send();';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Moo->request('/posts/view/1', array('update' => 'content'));
|
|
|
|
$expected = 'var jsRequest = new Request.HTML({update:"content", url:"/posts/view/1"}).send();';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
|
2009-03-16 02:15:22 +00:00
|
|
|
$result = $this->Moo->request('/people/edit/1', array(
|
|
|
|
'method' => 'post',
|
|
|
|
'complete' => 'doSuccess',
|
|
|
|
'error' => 'handleError',
|
|
|
|
'type' => 'json',
|
|
|
|
'data' => array('name' => 'jim', 'height' => '185cm')
|
|
|
|
));
|
|
|
|
$expected = 'var jsRequest = new Request.JSON({method:"post", onComplete:doSuccess, onFailure:handleError, url:"/people/edit/1"}).send({"name":"jim","height":"185cm"});';
|
|
|
|
$this->assertEqual($result, $expected);
|
2009-03-15 21:32:04 +00:00
|
|
|
}
|
2009-03-28 04:15:05 +00:00
|
|
|
/**
|
|
|
|
* test sortable list generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testSortable() {
|
|
|
|
$result = $this->Moo->get('#myList')->sortable(array(
|
|
|
|
'distance' => 5,
|
|
|
|
'containment' => 'parent',
|
|
|
|
'start' => 'onStart',
|
|
|
|
'complete' => 'onStop',
|
|
|
|
'sort' => 'onSort',
|
|
|
|
));
|
2009-03-28 04:31:51 +00:00
|
|
|
$expected = 'var mooSortable = new Sortables($("myList"), {constrain:"parent", onComplete:onStop, onSort:onSort, onStart:onStart, snap:5});';
|
2009-03-28 04:15:05 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-03-15 21:32:04 +00:00
|
|
|
}
|
|
|
|
?>
|