mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating prototype engine and test case for request()
This commit is contained in:
parent
5f7abae48c
commit
00f3c6f25d
2 changed files with 31 additions and 13 deletions
|
@ -38,7 +38,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
'async' => 'asyncrhronous',
|
||||
'data' => 'parameters',
|
||||
'before' => 'onCreate',
|
||||
'complete' => 'onSuccess',
|
||||
'success' => 'onSuccess',
|
||||
'complete' => 'onComplete',
|
||||
'error' => 'onFailure'
|
||||
)
|
||||
);
|
||||
|
@ -161,7 +162,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
function request($url, $options = array()) {
|
||||
$url = '"'. $this->url($url) . '"';
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
$type = $data = null;
|
||||
$type = '.Request';
|
||||
$data = null;
|
||||
/*if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
$type = '.JSON';
|
||||
if (!empty($options['data'])) {
|
||||
|
@ -171,15 +173,11 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
unset($options['type']);
|
||||
}*/
|
||||
if (isset($options['update'])) {
|
||||
$options['update'] = str_replace('#', '', $options['update']);
|
||||
$url = '"' . str_replace('#', '', $options['update']) . '", ' . $url;
|
||||
$type = '.Updater';
|
||||
if (!empty($options['data'])) {
|
||||
$data = $this->_toQuerystring($options['data']);
|
||||
unset($options['data']);
|
||||
unset($options['update'], $options['type']);
|
||||
}
|
||||
unset($options['type']);
|
||||
}
|
||||
$callbacks = array('onComplete', 'onFailure', 'onRequest');
|
||||
$callbacks = array('onCreate', 'onComplete', 'onFailure', 'onRequest', 'onSuccess');
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
|
|
|
@ -114,7 +114,8 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
|||
* @return void
|
||||
**/
|
||||
function testEffect() {
|
||||
$result = $this->Proto->get('#foo')->effect('show');
|
||||
$this->Proto->get('#foo');
|
||||
$result = $this->Proto->effect('show');
|
||||
$expected = '$("foo").show();';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
@ -169,11 +170,30 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
|||
**/
|
||||
function testRequest() {
|
||||
$result = $this->Proto->request(array('controller' => 'posts', 'action' => 'view', 1));
|
||||
$expected = 'var jsRequest = new Ajax("/posts/view/1");';
|
||||
$expected = 'var jsRequest = new Ajax.Request("/posts/view/1");';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->request('/posts/view/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doComplete',
|
||||
'before' => 'doBefore',
|
||||
'success' => 'doSuccess',
|
||||
'error' => 'doError',
|
||||
'data' => array('name' => 'jim', 'height' => '185cm')
|
||||
));
|
||||
$expected = 'var jsRequest = new Ajax.Request("/posts/view/1", {method:"post", onComplete:doComplete, onCreate:doBefore, onFailure:doError, onSuccess:doSuccess, parameters:{"name":"jim","height":"185cm"}});';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->request('/posts/view/1', array('update' => 'content'));
|
||||
$expected = 'var jsRequest = new Ajax.Updater("/posts/view/1", {update:"content"});';
|
||||
$expected = 'var jsRequest = new Ajax.Updater("content", "/posts/view/1");';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->request('/people/edit/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doSuccess',
|
||||
'update' => '#update-zone'
|
||||
));
|
||||
$expected = 'var jsRequest = new Ajax.Updater("update-zone", "/people/edit/1", {method:"post", onComplete:doSuccess});';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
/* $result = $this->Proto->request('/people/edit/1', array(
|
||||
|
|
Loading…
Reference in a new issue