cakephp2-php8/lib/Cake/Test/Case/View/Helper/MootoolsEngineHelperTest.php

383 lines
12 KiB
PHP
Raw Normal View History

2009-03-15 21:32:04 +00:00
<?php
/**
* MooEngineTestCase
2009-03-15 21:32:04 +00:00
*
2017-06-10 21:33:55 +00:00
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
2009-03-15 21:32:04 +00:00
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
2009-03-15 21:32:04 +00:00
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
2017-06-10 21:33:55 +00:00
* @link https://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license https://opensource.org/licenses/mit-license.php MIT License
2009-03-15 21:32:04 +00:00
*/
2011-02-14 04:49:06 +00:00
App::uses('View', 'View');
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('MootoolsEngineHelper', 'View/Helper');
2009-03-15 21:32:04 +00:00
/**
* MootoolsEngineHelperTest
*
* @package Cake.Test.Case.View.Helper
*/
class MootoolsEngineHelperTest extends CakeTestCase {
2009-03-15 21:32:04 +00:00
/**
* setUp
2009-03-15 21:32:04 +00:00
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = $this->getMock('View', array('addScript'), array(&$controller));
$this->Moo = new MootoolsEngineHelper($this->View);
2009-03-15 21:32:04 +00:00
}
2009-03-15 21:32:04 +00:00
/**
* tearDown
2009-03-15 21:32:04 +00:00
*
* @return void
*/
public function tearDown() {
parent::tearDown();
2009-03-15 21:32:04 +00:00
unset($this->Moo);
}
2009-03-15 21:32:04 +00:00
/**
* test selector method
*
* @return void
*/
public function testSelector() {
$result = $this->Moo->get('#content');
$this->assertEquals($this->Moo, $result);
$this->assertEquals($this->Moo->selection, '$("content")');
$result = $this->Moo->get('a .remove');
$this->assertEquals($this->Moo, $result);
$this->assertEquals($this->Moo->selection, '$$("a .remove")');
$result = $this->Moo->get('document');
$this->assertEquals($this->Moo, $result);
$this->assertEquals($this->Moo->selection, "$(document)");
$result = $this->Moo->get('window');
$this->assertEquals($this->Moo, $result);
$this->assertEquals($this->Moo->selection, "$(window)");
$result = $this->Moo->get('ul');
$this->assertEquals($this->Moo, $result);
$this->assertEquals($this->Moo->selection, '$$("ul")');
$result = $this->Moo->get('#some_long-id.class');
$this->assertEquals($this->Moo, $result);
$this->assertEquals($this->Moo->selection, '$$("#some_long-id.class")');
2009-03-15 21:32:04 +00:00
}
2011-12-06 20:52:48 +00:00
2009-03-15 21:32:04 +00:00
/**
* test event binding
*
* @return void
*/
public function testEvent() {
2009-04-07 01:24:14 +00:00
$this->Moo->get('#myLink');
$result = $this->Moo->event('click', 'doClick', array('wrap' => false));
$expected = '$("myLink").addEvent("click", doClick);';
$this->assertEquals($expected, $result);
2009-03-15 21:32:04 +00:00
2009-04-07 01:24:14 +00:00
$result = $this->Moo->event('click', 'this.setStyle("display", "");', array('stop' => false));
$expected = '$("myLink").addEvent("click", function (event) {this.setStyle("display", "");});';
$this->assertEquals($expected, $result);
2009-04-07 01:24:14 +00:00
$result = $this->Moo->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\");});";
$this->assertEquals($expected, $result);
2009-03-15 21:32:04 +00:00
}
2011-12-06 20:52:48 +00:00
2009-03-15 21:32:04 +00:00
/**
* test dom ready event creation
*
* @return void
*/
public function testDomReady() {
$result = $this->Moo->domReady('foo.name = "bar";');
$expected = 'window.addEvent("domready", function (event) {foo.name = "bar";});';
$this->assertEquals($expected, $result);
2009-03-15 21:32:04 +00:00
}
2011-12-06 20:52:48 +00:00
2009-03-15 21:32:04 +00:00
/**
* test Each method
*
* @return void
*/
public function testEach() {
2009-04-07 01:24:14 +00:00
$this->Moo->get('#foo');
$result = $this->Moo->each('item.setStyle("display", "none");');
$expected = '$("foo").each(function (item, index) {item.setStyle("display", "none");});';
$this->assertEquals($expected, $result);
2009-03-15 21:32:04 +00:00
}
2011-12-06 20:52:48 +00:00
2009-03-15 21:32:04 +00:00
/**
* test Effect generation
*
* @return void
*/
public function testEffect() {
2009-04-07 01:24:14 +00:00
$this->Moo->get('#foo');
$result = $this->Moo->effect('show');
$expected = '$("foo").setStyle("display", "");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('hide');
$expected = '$("foo").setStyle("display", "none");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('fadeIn');
$expected = '$("foo").fade("in");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('fadeOut');
$expected = '$("foo").fade("out");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('slideIn');
$expected = '$("foo").slide("in");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('slideOut');
$expected = '$("foo").slide("out");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('slideOut', array('speed' => 'fast'));
$expected = '$("foo").set("slide", {duration:"short"}).slide("out");';
$this->assertEquals($expected, $result);
$result = $this->Moo->effect('slideOut', array('speed' => 'slow'));
$expected = '$("foo").set("slide", {duration:"long"}).slide("out");';
$this->assertEquals($expected, $result);
2009-03-15 21:32:04 +00:00
}
2011-12-06 20:52:48 +00:00
2009-03-15 21:32:04 +00:00
/**
* Test Request Generation
*
* @return void
*/
public 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->assertEquals($expected, $result);
2009-03-16 02:15:22 +00:00
$result = $this->Moo->request('/posts/view/1', array('update' => 'content'));
$expected = 'var jsRequest = new Request.HTML({update:"content", url:"\\/posts\\/view\\/1"}).send();';
$this->assertEquals($expected, $result);
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'),
'wrapCallbacks' => false
2009-03-16 02:15:22 +00:00
));
$expected = 'var jsRequest = new Request.JSON({method:"post", onComplete:doSuccess, onFailure:handleError, url:"\\/people\\/edit\\/1"}).send({"name":"jim","height":"185cm"});';
$this->assertEquals($expected, $result);
2009-03-30 02:08:49 +00:00
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doSuccess',
'update' => '#update-zone',
'wrapCallbacks' => false
2009-03-30 02:08:49 +00:00
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doSuccess, update:"update-zone", url:"\\/people\\/edit\\/1"}).send();';
$this->assertEquals($expected, $result);
2009-03-30 02:08:49 +00:00
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doComplete',
'success' => 'doSuccess',
'error' => 'doFailure',
'before' => 'doBefore',
'update' => 'update-zone',
'wrapCallbacks' => false
2009-03-30 02:08:49 +00:00
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doComplete, onFailure:doFailure, onRequest:doBefore, onSuccess:doSuccess, update:"update-zone", url:"\\/people\\/edit\\/1"}).send();';
$this->assertEquals($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'complete' => 'doComplete',
'success' => 'doSuccess',
'error' => 'doFailure',
'before' => 'doBefore',
'update' => 'update-zone',
'dataExpression' => true,
'data' => '$("foo").toQueryString()',
'wrapCallbacks' => false
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doComplete, onFailure:doFailure, onRequest:doBefore, onSuccess:doSuccess, update:"update-zone", url:"\\/people\\/edit\\/1"}).send($("foo").toQueryString());';
$this->assertEquals($expected, $result);
$result = $this->Moo->request('/people/edit/1', array(
'method' => 'post',
'before' => 'doBefore',
'success' => 'doSuccess',
'complete' => 'doComplete',
'update' => '#update-zone',
));
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:function () {doComplete}, onRequest:function () {doBefore}, onSuccess:function (responseText, responseXML) {doSuccess}, update:"update-zone", url:"\\/people\\/edit\\/1"}).send();';
$this->assertEquals($expected, $result);
2009-03-15 21:32:04 +00:00
}
2011-12-06 20:52:48 +00:00
2009-03-28 04:15:05 +00:00
/**
* test sortable list generation
*
* @return void
*/
public function testSortable() {
2009-04-07 01:24:14 +00:00
$this->Moo->get('#myList');
$result = $this->Moo->sortable(array(
2009-03-28 04:15:05 +00:00
'distance' => 5,
'containment' => 'parent',
'start' => 'onStart',
'complete' => 'onStop',
'sort' => 'onSort',
'wrapCallbacks' => false
2009-03-28 04:15:05 +00:00
));
$expected = 'var jsSortable = new Sortables($("myList"), {constrain:"parent", onComplete:onStop, onSort:onSort, onStart:onStart, snap:5});';
$this->assertEquals($expected, $result);
2009-03-28 04:15:05 +00:00
}
2011-12-06 20:52:48 +00:00
/**
* test drag() method
*
* @return void
*/
public function testDrag() {
2009-04-12 03:09:58 +00:00
$this->Moo->get('#drag-me');
$result = $this->Moo->drag(array(
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10, 10),
'wrapCallbacks' => false
2009-04-12 03:09:58 +00:00
));
$expected = '$("drag-me").makeDraggable({onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});';
$this->assertEquals($expected, $result);
}
/**
* test drop() method with the required drag option missing
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testDropWithMissingOption() {
2009-04-12 03:37:24 +00:00
$this->Moo->get('#drop-me');
$this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
));
}
2011-12-06 20:52:48 +00:00
/**
* test drop() method
*
* @return void
*/
public function testDrop() {
$this->Moo->get('#drop-me');
2009-04-12 03:37:24 +00:00
$result = $this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
'drag' => '#my-drag',
'wrapCallbacks' => false
2009-04-12 03:37:24 +00:00
));
$expected = '$("my-drag").makeDraggable({droppables:$("drop-me"), onDrop:onDrop, onEnter:onHover, onLeave:onLeave});';
$this->assertEquals($expected, $result);
$this->assertEquals($this->Moo->selection, '$("drop-me")');
$result = $this->Moo->drop(array(
'drop' => 'onDrop',
'leave' => 'onLeave',
'hover' => 'onHover',
'drag' => '#my-drag',
));
$expected = '$("my-drag").makeDraggable({droppables:$("drop-me"), onDrop:function (element, droppable, event) {onDrop}, onEnter:function (element, droppable) {onHover}, onLeave:function (element, droppable) {onLeave}});';
$this->assertEquals($expected, $result);
}
2011-12-06 20:52:48 +00:00
2009-04-24 17:44:52 +00:00
/**
* test slider generation
*
* @return void
*/
public function testSlider() {
2009-04-24 17:44:52 +00:00
$this->Moo->get('#slider');
$result = $this->Moo->slider(array(
'handle' => '#my-handle',
'complete' => 'onComplete',
'change' => 'onChange',
'direction' => 'horizontal',
'wrapCallbacks' => false
2009-04-24 17:44:52 +00:00
));
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete});';
$this->assertEquals($expected, $result);
$this->assertEquals($this->Moo->selection, '$("slider")');
2009-04-24 17:44:52 +00:00
$this->Moo->get('#slider');
$result = $this->Moo->slider(array(
'handle' => '#my-handle',
'complete' => 'onComplete',
'change' => 'onChange',
'direction' => 'horizontal',
'min' => 10,
'max' => 40,
'wrapCallbacks' => false
2009-04-24 17:44:52 +00:00
));
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:onChange, onComplete:onComplete, range:[10,40]});';
$this->assertEquals($expected, $result);
$this->Moo->get('#slider');
$result = $this->Moo->slider(array(
'handle' => '#my-handle',
'complete' => 'complete;',
'change' => 'change;',
'direction' => 'horizontal',
));
$expected = 'var jsSlider = new Slider($("slider"), $("my-handle"), {mode:"horizontal", onChange:function (step) {change;}, onComplete:function (event) {complete;}});';
$this->assertEquals($expected, $result);
2009-04-24 17:44:52 +00:00
}
2011-12-06 20:52:48 +00:00
/**
* test the serializeForm implementation.
*
* @return void
*/
public function testSerializeForm() {
$this->Moo->get('#element');
$result = $this->Moo->serializeForm(array('isForm' => true));
$expected = '$("element").toQueryString();';
$this->assertEquals($expected, $result);
$result = $this->Moo->serializeForm(array('isForm' => true, 'inline' => true));
$expected = '$("element").toQueryString()';
$this->assertEquals($expected, $result);
$result = $this->Moo->serializeForm(array('isForm' => false));
$expected = '$($("element").form).toQueryString();';
$this->assertEquals($expected, $result);
$result = $this->Moo->serializeForm(array('isForm' => false, 'inline' => true));
$expected = '$($("element").form).toQueryString()';
$this->assertEquals($expected, $result);
}
2009-03-15 21:32:04 +00:00
}