2009-03-14 00:50:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* JqueryEngineTestCase
|
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-03-14 00:50:31 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2011-10-10 21:18:48 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2009-03-14 00:50:31 +00:00
|
|
|
*
|
2013-05-30 22:11:14 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2009-03-14 00:50:31 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
|
|
|
|
App::uses('HtmlHelper', 'View/Helper');
|
|
|
|
App::uses('JsHelper', 'View/Helper');
|
|
|
|
App::uses('JqueryEngineHelper', 'View/Helper');
|
|
|
|
App::uses('View', 'View');
|
2009-03-14 00:50:31 +00:00
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* JqueryEngineHelperTest
|
2013-05-30 22:11:14 +00:00
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.View.Helper
|
|
|
|
*/
|
2010-06-13 14:01:37 +00:00
|
|
|
class JqueryEngineHelperTest extends CakeTestCase {
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp
|
2009-03-14 00:50:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2010-07-03 16:16:40 +00:00
|
|
|
$controller = null;
|
2011-01-09 05:09:01 +00:00
|
|
|
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
|
|
|
|
$this->Jquery = new JqueryEngineHelper($this->View);
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* tearDown
|
2009-03-14 00:50:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::tearDown();
|
2009-03-14 00:50:31 +00:00
|
|
|
unset($this->Jquery);
|
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
/**
|
|
|
|
* test selector method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelector() {
|
2009-03-14 00:50:31 +00:00
|
|
|
$result = $this->Jquery->get('#content');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($this->Jquery, $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Jquery->selection, '$("#content")');
|
2009-07-25 02:46:33 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
$result = $this->Jquery->get('document');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($this->Jquery, $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Jquery->selection, '$(document)');
|
2009-07-25 02:46:33 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
$result = $this->Jquery->get('window');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($this->Jquery, $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Jquery->selection, '$(window)');
|
2009-07-25 02:46:33 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
$result = $this->Jquery->get('ul');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($this->Jquery, $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Jquery->selection, '$("ul")');
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
/**
|
|
|
|
* test event binding
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testEvent() {
|
2009-04-07 01:24:14 +00:00
|
|
|
$this->Jquery->get('#myLink');
|
|
|
|
$result = $this->Jquery->event('click', 'doClick', array('wrap' => false));
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#myLink").bind("click", doClick);';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-15 16:26:12 +00:00
|
|
|
|
2009-04-07 01:24:14 +00:00
|
|
|
$result = $this->Jquery->event('click', '$(this).show();', array('stop' => false));
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#myLink").bind("click", function (event) {$(this).show();});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-15 16:26:12 +00:00
|
|
|
|
2009-04-07 01:24:14 +00:00
|
|
|
$result = $this->Jquery->event('click', '$(this).hide();');
|
2012-03-19 03:25:19 +00:00
|
|
|
$expected = '$("#myLink").bind("click", function (event) {$(this).hide();' . "\n" . 'return false;});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
/**
|
|
|
|
* test dom ready event creation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDomReady() {
|
2009-03-14 00:50:31 +00:00
|
|
|
$result = $this->Jquery->domReady('foo.name = "bar";');
|
2010-01-29 15:06:47 +00:00
|
|
|
$expected = '$(document).ready(function () {foo.name = "bar";});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 00:50:31 +00:00
|
|
|
/**
|
|
|
|
* test Each method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testEach() {
|
2009-04-07 01:24:14 +00:00
|
|
|
$this->Jquery->get('#foo');
|
|
|
|
$result = $this->Jquery->each('$(this).hide();');
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#foo").each(function () {$(this).hide();});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 05:57:24 +00:00
|
|
|
/**
|
|
|
|
* test Effect generation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testEffect() {
|
2009-04-07 01:24:14 +00:00
|
|
|
$this->Jquery->get('#foo');
|
|
|
|
$result = $this->Jquery->effect('show');
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#foo").show();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 05:57:24 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('hide');
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#foo").hide();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 04:10:43 +00:00
|
|
|
|
2009-03-14 05:57:24 +00:00
|
|
|
$result = $this->Jquery->effect('hide', array('speed' => 'fast'));
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#foo").hide("fast");';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 05:57:24 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('fadeIn');
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#foo").fadeIn();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 05:57:24 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('fadeOut');
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#foo").fadeOut();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 05:57:24 +00:00
|
|
|
|
2009-03-15 23:59:16 +00:00
|
|
|
$result = $this->Jquery->effect('slideIn');
|
2009-03-30 01:52:44 +00:00
|
|
|
$expected = '$("#foo").slideDown();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-15 23:59:16 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('slideOut');
|
2009-03-30 01:52:44 +00:00
|
|
|
$expected = '$("#foo").slideUp();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:37:41 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('slideDown');
|
|
|
|
$expected = '$("#foo").slideDown();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:37:41 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('slideUp');
|
|
|
|
$expected = '$("#foo").slideUp();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 05:57:24 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-14 21:01:49 +00:00
|
|
|
/**
|
|
|
|
* Test Request Generation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequest() {
|
2009-03-14 21:01:49 +00:00
|
|
|
$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1));
|
2010-03-09 03:30:28 +00:00
|
|
|
$expected = '$.ajax({url:"\\/posts\\/view\\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 21:01:49 +00:00
|
|
|
|
2009-08-12 13:27:01 +00:00
|
|
|
$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array(
|
|
|
|
'update' => '#content'
|
|
|
|
));
|
2010-03-09 03:30:28 +00:00
|
|
|
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-08-12 13:24:23 +00:00
|
|
|
|
2009-03-14 21:01:49 +00:00
|
|
|
$result = $this->Jquery->request('/people/edit/1', array(
|
|
|
|
'method' => 'post',
|
2009-07-25 02:46:33 +00:00
|
|
|
'before' => 'doBefore',
|
2009-04-06 03:49:09 +00:00
|
|
|
'complete' => 'doComplete',
|
|
|
|
'success' => 'doSuccess',
|
2009-03-14 21:01:49 +00:00
|
|
|
'error' => 'handleError',
|
|
|
|
'type' => 'json',
|
2009-07-30 02:19:02 +00:00
|
|
|
'data' => array('name' => 'jim', 'height' => '185cm'),
|
|
|
|
'wrapCallbacks' => false
|
2009-03-14 21:01:49 +00:00
|
|
|
));
|
2010-03-09 03:30:28 +00:00
|
|
|
$expected = '$.ajax({beforeSend:doBefore, complete:doComplete, data:"name=jim&height=185cm", dataType:"json", error:handleError, success:doSuccess, type:"post", url:"\\/people\\/edit\\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-25 02:46:33 +00:00
|
|
|
|
2009-03-30 03:00:39 +00:00
|
|
|
$result = $this->Jquery->request('/people/edit/1', array(
|
|
|
|
'update' => '#updated',
|
|
|
|
'success' => 'doFoo',
|
2009-07-30 02:19:02 +00:00
|
|
|
'method' => 'post',
|
|
|
|
'wrapCallbacks' => false
|
2009-03-30 03:00:39 +00:00
|
|
|
));
|
2010-10-02 02:43:46 +00:00
|
|
|
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:19:02 +00:00
|
|
|
|
2009-07-25 05:35:36 +00:00
|
|
|
$result = $this->Jquery->request('/people/edit/1', array(
|
|
|
|
'update' => '#updated',
|
|
|
|
'success' => 'doFoo',
|
|
|
|
'method' => 'post',
|
|
|
|
'dataExpression' => true,
|
2009-07-30 02:19:02 +00:00
|
|
|
'data' => '$("#someId").serialize()',
|
|
|
|
'wrapCallbacks' => false
|
2009-07-25 05:35:36 +00:00
|
|
|
));
|
2010-10-02 02:43:46 +00:00
|
|
|
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:19:02 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->request('/people/edit/1', array(
|
|
|
|
'success' => 'doFoo',
|
|
|
|
'before' => 'doBefore',
|
|
|
|
'method' => 'post',
|
|
|
|
'dataExpression' => true,
|
|
|
|
'data' => '$("#someId").serialize()',
|
|
|
|
));
|
2010-03-09 03:30:28 +00:00
|
|
|
$expected = '$.ajax({beforeSend:function (XMLHttpRequest) {doBefore}, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\\/people\\/edit\\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-10-18 15:00:15 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->request('/people/edit/1', array(
|
|
|
|
'success' => 'doFoo',
|
|
|
|
'xhr' => 'return jQuery.ajaxSettings.xhr();',
|
|
|
|
'async' => true,
|
|
|
|
'method' => 'post',
|
|
|
|
'dataExpression' => true,
|
|
|
|
'data' => '$("#someId").serialize()',
|
|
|
|
));
|
2013-10-18 15:41:38 +00:00
|
|
|
$expected = '$.ajax({async:true, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\/people\/edit\/1", xhr:function () {return jQuery.ajaxSettings.xhr();}});';
|
2013-10-18 15:00:15 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-05-17 22:25:50 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 04:09:37 +00:00
|
|
|
/**
|
|
|
|
* Test that querystring arguments are not double escaped.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequestWithQueryStringArguments() {
|
|
|
|
$url = '/users/search/sort:User.name/direction:desc?nome=&cpm=&audience=public';
|
|
|
|
$result = $this->Jquery->request($url);
|
|
|
|
$expected = '$.ajax({url:"\\/users\\/search\\/sort:User.name\\/direction:desc?nome=&cpm=&audience=public"});';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2010-05-17 22:25:50 +00:00
|
|
|
/**
|
|
|
|
* test that alternate jQuery object values work for request()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRequestWithAlternateJqueryObject() {
|
2010-05-17 22:25:50 +00:00
|
|
|
$this->Jquery->jQueryObject = '$j';
|
|
|
|
|
|
|
|
$result = $this->Jquery->request('/people/edit/1', array(
|
|
|
|
'update' => '#updated',
|
|
|
|
'success' => 'doFoo',
|
|
|
|
'method' => 'post',
|
|
|
|
'dataExpression' => true,
|
|
|
|
'data' => '$j("#someId").serialize()',
|
|
|
|
'wrapCallbacks' => false
|
|
|
|
));
|
2010-10-02 02:43:46 +00:00
|
|
|
$expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-14 21:01:49 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-28 03:44:57 +00:00
|
|
|
/**
|
|
|
|
* test sortable list generation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSortable() {
|
2009-04-07 01:24:14 +00:00
|
|
|
$this->Jquery->get('#myList');
|
|
|
|
$result = $this->Jquery->sortable(array(
|
2009-03-28 03:44:57 +00:00
|
|
|
'distance' => 5,
|
|
|
|
'containment' => 'parent',
|
|
|
|
'start' => 'onStart',
|
|
|
|
'complete' => 'onStop',
|
|
|
|
'sort' => 'onSort',
|
2009-07-30 02:19:02 +00:00
|
|
|
'wrapCallbacks' => false
|
2009-03-28 03:44:57 +00:00
|
|
|
));
|
2009-03-30 01:52:44 +00:00
|
|
|
$expected = '$("#myList").sortable({containment:"parent", distance:5, sort:onSort, start:onStart, stop:onStop});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:19:02 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->sortable(array(
|
|
|
|
'distance' => 5,
|
|
|
|
'containment' => 'parent',
|
|
|
|
'start' => 'onStart',
|
|
|
|
'complete' => 'onStop',
|
|
|
|
'sort' => 'onSort',
|
|
|
|
));
|
|
|
|
$expected = '$("#myList").sortable({containment:"parent", distance:5, sort:function (event, ui) {onSort}, start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-28 03:44:57 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-30 03:00:39 +00:00
|
|
|
/**
|
|
|
|
* test drag() method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDrag() {
|
2009-04-09 03:31:17 +00:00
|
|
|
$this->Jquery->get('#element');
|
|
|
|
$result = $this->Jquery->drag(array(
|
|
|
|
'container' => '#content',
|
|
|
|
'start' => 'onStart',
|
2009-07-25 02:46:33 +00:00
|
|
|
'drag' => 'onDrag',
|
2009-04-09 03:31:17 +00:00
|
|
|
'stop' => 'onStop',
|
|
|
|
'snapGrid' => array(10, 10),
|
2009-07-30 02:19:02 +00:00
|
|
|
'wrapCallbacks' => false
|
2009-04-09 03:31:17 +00:00
|
|
|
));
|
2009-04-09 03:57:32 +00:00
|
|
|
$expected = '$("#element").draggable({containment:"#content", drag:onDrag, grid:[10,10], start:onStart, stop:onStop});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:19:02 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->drag(array(
|
|
|
|
'container' => '#content',
|
|
|
|
'start' => 'onStart',
|
|
|
|
'drag' => 'onDrag',
|
|
|
|
'stop' => 'onStop',
|
|
|
|
'snapGrid' => array(10, 10),
|
|
|
|
));
|
|
|
|
$expected = '$("#element").draggable({containment:"#content", drag:function (event, ui) {onDrag}, grid:[10,10], start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-30 03:00:39 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-03-30 03:00:39 +00:00
|
|
|
/**
|
|
|
|
* test drop() method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDrop() {
|
2009-04-09 03:57:32 +00:00
|
|
|
$this->Jquery->get('#element');
|
|
|
|
$result = $this->Jquery->drop(array(
|
|
|
|
'accept' => '.items',
|
2009-07-25 02:46:33 +00:00
|
|
|
'hover' => 'onHover',
|
2009-04-09 03:57:32 +00:00
|
|
|
'leave' => 'onExit',
|
2009-07-30 02:19:02 +00:00
|
|
|
'drop' => 'onDrop',
|
|
|
|
'wrapCallbacks' => false
|
2009-04-09 03:57:32 +00:00
|
|
|
));
|
|
|
|
$expected = '$("#element").droppable({accept:".items", drop:onDrop, out:onExit, over:onHover});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:19:02 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->drop(array(
|
|
|
|
'accept' => '.items',
|
|
|
|
'hover' => 'onHover',
|
|
|
|
'leave' => 'onExit',
|
|
|
|
'drop' => 'onDrop',
|
|
|
|
));
|
|
|
|
$expected = '$("#element").droppable({accept:".items", drop:function (event, ui) {onDrop}, out:function (event, ui) {onExit}, over:function (event, ui) {onHover}});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-03-30 03:00:39 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-04-24 17:44:52 +00:00
|
|
|
/**
|
|
|
|
* test slider generation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSlider() {
|
2009-04-24 17:44:52 +00:00
|
|
|
$this->Jquery->get('#element');
|
|
|
|
$result = $this->Jquery->slider(array(
|
|
|
|
'complete' => 'onComplete',
|
|
|
|
'change' => 'onChange',
|
|
|
|
'min' => 0,
|
|
|
|
'max' => 10,
|
|
|
|
'value' => 2,
|
2009-07-30 02:19:02 +00:00
|
|
|
'direction' => 'vertical',
|
|
|
|
'wrapCallbacks' => false
|
2009-04-24 17:44:52 +00:00
|
|
|
));
|
|
|
|
$expected = '$("#element").slider({change:onChange, max:10, min:0, orientation:"vertical", stop:onComplete, value:2});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-30 02:19:02 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->slider(array(
|
|
|
|
'complete' => 'onComplete',
|
|
|
|
'change' => 'onChange',
|
|
|
|
'min' => 0,
|
|
|
|
'max' => 10,
|
|
|
|
'value' => 2,
|
|
|
|
'direction' => 'vertical',
|
|
|
|
));
|
|
|
|
$expected = '$("#element").slider({change:function (event, ui) {onChange}, max:10, min:0, orientation:"vertical", stop:function (event, ui) {onComplete}, value:2});';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-04-24 17:44:52 +00:00
|
|
|
}
|
2009-07-30 02:37:41 +00:00
|
|
|
|
2009-07-25 02:46:33 +00:00
|
|
|
/**
|
|
|
|
* test the serializeForm method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSerializeForm() {
|
2009-07-25 02:46:33 +00:00
|
|
|
$this->Jquery->get('#element');
|
2009-07-25 03:29:44 +00:00
|
|
|
$result = $this->Jquery->serializeForm(array('isForm' => false));
|
2009-07-25 02:46:33 +00:00
|
|
|
$expected = '$("#element").closest("form").serialize();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-25 02:46:33 +00:00
|
|
|
|
2009-07-25 03:29:44 +00:00
|
|
|
$result = $this->Jquery->serializeForm(array('isForm' => true));
|
2009-07-25 02:46:33 +00:00
|
|
|
$expected = '$("#element").serialize();';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-25 02:46:33 +00:00
|
|
|
|
2009-07-25 03:29:44 +00:00
|
|
|
$result = $this->Jquery->serializeForm(array('isForm' => false, 'inline' => true));
|
|
|
|
$expected = '$("#element").closest("form").serialize()';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-25 02:46:33 +00:00
|
|
|
}
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|