2009-03-14 00:50:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* JqueryEngineTestCase
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-03-14 00:50:31 +00:00
|
|
|
*
|
2009-11-06 06:08:23 +00:00
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2010-10-24 20:58:22 +00:00
|
|
|
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-03-14 00:50:31 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2010-10-24 20:58:22 +00:00
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2009-03-14 00:50:31 +00:00
|
|
|
* @package cake.tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.views.helpers
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
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
|
|
|
|
2010-06-13 14:01:37 +00:00
|
|
|
class JqueryEngineHelperTest extends CakeTestCase {
|
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');
|
|
|
|
$this->assertEqual($result, $this->Jquery);
|
2009-03-16 01:44:40 +00:00
|
|
|
$this->assertEqual($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');
|
|
|
|
$this->assertEqual($result, $this->Jquery);
|
2009-03-16 01:44:40 +00:00
|
|
|
$this->assertEqual($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');
|
|
|
|
$this->assertEqual($result, $this->Jquery);
|
2009-03-16 01:44:40 +00:00
|
|
|
$this->assertEqual($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');
|
|
|
|
$this->assertEqual($result, $this->Jquery);
|
2009-03-16 01:44:40 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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();');
|
2009-03-16 01:44:40 +00:00
|
|
|
$expected = '$("#myLink").bind("click", function (event) {$(this).hide();'."\n".'return false;});';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-30 02:37:41 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('slideDown');
|
|
|
|
$expected = '$("#foo").slideDown();';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-30 02:37:41 +00:00
|
|
|
|
|
|
|
$result = $this->Jquery->effect('slideUp');
|
|
|
|
$expected = '$("#foo").slideUp();';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-25 02:46:33 +00:00
|
|
|
}
|
2009-03-14 00:50:31 +00:00
|
|
|
}
|