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