Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
229
Merge Requests
229
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
ee8fbcf2
Commit
ee8fbcf2
authored
Jun 03, 2012
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Patch
#1598548
by Rob Loach, Niklas Fiekas: Convert ajax.test to
PSR-0
.
parent
f5b2ed1a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
582 additions
and
1 deletion
+582
-1
core/modules/system/lib/Drupal/system/Tests/Ajax/AjaxTestBase.php
...ules/system/lib/Drupal/system/Tests/Ajax/AjaxTestBase.php
+67
-0
core/modules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php
...ules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php
+161
-0
core/modules/system/lib/Drupal/system/Tests/Ajax/ElementValidationTest.php
...em/lib/Drupal/system/Tests/Ajax/ElementValidationTest.php
+40
-0
core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php
...es/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php
+59
-0
core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php
...les/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php
+170
-0
core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
...les/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
+85
-0
core/modules/system/system.info
core/modules/system/system.info
+0
-1
No files found.
core/modules/system/lib/Drupal/system/Tests/Ajax/AjaxTestBase.php
0 → 100644
View file @
ee8fbcf2
<?php
/**
* @file
* Definition of Drupal\system\Tests\Ajax\AjaxTestBase.
*/
namespace
Drupal\system\Tests\Ajax
;
use
Drupal\simpletest\WebTestBase
;
/**
* Base test system for AJAX tests.
*/
class
AjaxTestBase
extends
WebTestBase
{
function
setUp
()
{
$modules
=
func_get_args
();
if
(
isset
(
$modules
[
0
])
&&
is_array
(
$modules
[
0
]))
{
$modules
=
$modules
[
0
];
}
parent
::
setUp
(
array_unique
(
array_merge
(
array
(
'ajax_test'
,
'ajax_forms_test'
),
$modules
)));
}
/**
* Assert that a command with the required properties exists within the array of Ajax commands returned by the server.
*
* The Ajax framework, via the ajax_deliver() and ajax_render() functions,
* returns an array of commands. This array sometimes includes commands
* automatically provided by the framework in addition to commands returned by
* a particular page callback. During testing, we're usually interested that a
* particular command is present, and don't care whether other commands
* precede or follow the one we're interested in. Additionally, the command
* we're interested in may include additional data that we're not interested
* in. Therefore, this function simply asserts that one of the commands in
* $haystack contains all of the keys and values in $needle. Furthermore, if
* $needle contains a 'settings' key with an array value, we simply assert
* that all keys and values within that array are present in the command we're
* checking, and do not consider it a failure if the actual command contains
* additional settings that aren't part of $needle.
*
* @param $haystack
* An array of Ajax commands returned by the server.
* @param $needle
* Array of info we're expecting in one of those commands.
* @param $message
* An assertion message.
*/
protected
function
assertCommand
(
$haystack
,
$needle
,
$message
)
{
$found
=
FALSE
;
foreach
(
$haystack
as
$command
)
{
// If the command has additional settings that we're not testing for, do
// not consider that a failure.
if
(
isset
(
$command
[
'settings'
])
&&
is_array
(
$command
[
'settings'
])
&&
isset
(
$needle
[
'settings'
])
&&
is_array
(
$needle
[
'settings'
]))
{
$command
[
'settings'
]
=
array_intersect_key
(
$command
[
'settings'
],
$needle
[
'settings'
]);
}
// If the command has additional data that we're not testing for, do not
// consider that a failure. Also, == instead of ===, because we don't
// require the key/value pairs to be in any particular order
// (http://www.php.net/manual/language.operators.array.php).
if
(
array_intersect_key
(
$command
,
$needle
)
==
$needle
)
{
$found
=
TRUE
;
break
;
}
}
$this
->
assertTrue
(
$found
,
$message
);
}
}
core/modules/system/lib/Drupal/system/Tests/Ajax/CommandsTest.php
0 → 100644
View file @
ee8fbcf2
<?php
/**
* @file
* Definition of Drupal\system\Tests\Ajax\CommandsTest.
*/
namespace
Drupal\system\Tests\Ajax
;
/**
* Tests Ajax framework commands.
*/
class
CommandsTest
extends
AjaxTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'AJAX commands'
,
'description'
=>
'Performs tests on AJAX framework commands.'
,
'group'
=>
'AJAX'
,
);
}
/**
* Test the various Ajax Commands.
*/
function
testAjaxCommands
()
{
$form_path
=
'ajax_forms_test_ajax_commands_form'
;
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
));
$this
->
drupalLogin
(
$web_user
);
$edit
=
array
();
// Tests the 'after' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'After': Click to put something after the div"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'after'
,
'data'
=>
'This will be placed after'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'after' AJAX command issued with correct data"
);
// Tests the 'alert' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'Alert': Click to alert"
)));
$expected
=
array
(
'command'
=>
'alert'
,
'text'
=>
'Alert'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'alert' AJAX Command issued with correct text"
);
// Tests the 'append' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'Append': Click to append something"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'append'
,
'data'
=>
'Appended text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'append' AJAX command issued with correct data"
);
// Tests the 'before' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'before': Click to put something before the div"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'before'
,
'data'
=>
'Before text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'before' AJAX command issued with correct data"
);
// Tests the 'changed' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX changed: Click to mark div changed."
)));
$expected
=
array
(
'command'
=>
'changed'
,
'selector'
=>
'#changed_div'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'changed' AJAX command issued with correct selector"
);
// Tests the 'changed' command using the second argument.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX changed: Click to mark div changed with asterisk."
)));
$expected
=
array
(
'command'
=>
'changed'
,
'selector'
=>
'#changed_div'
,
'asterisk'
=>
'#changed_div_mark_this'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'changed' AJAX command (with asterisk) issued with correct selector"
);
// Tests the 'css' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"Set the the '#box' div to be blue."
)));
$expected
=
array
(
'command'
=>
'css'
,
'selector'
=>
'#css_div'
,
'argument'
=>
array
(
'background-color'
=>
'blue'
),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'css' AJAX command issued with correct selector"
);
// Tests the 'data' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX data command: Issue command."
)));
$expected
=
array
(
'command'
=>
'data'
,
'name'
=>
'testkey'
,
'value'
=>
'testvalue'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'data' AJAX command issued with correct key and value"
);
// Tests the 'invoke' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX invoke command: Invoke addClass() method."
)));
$expected
=
array
(
'command'
=>
'invoke'
,
'method'
=>
'addClass'
,
'arguments'
=>
array
(
'error'
),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'invoke' AJAX command issued with correct method and argument"
);
// Tests the 'html' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX html: Replace the HTML in a selector."
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'html'
,
'data'
=>
'replacement text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'html' AJAX command issued with correct data"
);
// Tests the 'insert' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX insert: Let client insert based on #ajax['method']."
)));
$expected
=
array
(
'command'
=>
'insert'
,
'data'
=>
'insert replacement text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'insert' AJAX command issued with correct data"
);
// Tests the 'prepend' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'prepend': Click to prepend something"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'prepend'
,
'data'
=>
'prepended text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'prepend' AJAX command issued with correct data"
);
// Tests the 'remove' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'remove': Click to remove text"
)));
$expected
=
array
(
'command'
=>
'remove'
,
'selector'
=>
'#remove_text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'remove' AJAX command issued with correct command and selector"
);
// Tests the 'restripe' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'restripe' command"
)));
$expected
=
array
(
'command'
=>
'restripe'
,
'selector'
=>
'#restripe_table'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'restripe' AJAX command issued with correct selector"
);
// Tests the 'settings' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'settings' command"
)));
$expected
=
array
(
'command'
=>
'settings'
,
'settings'
=>
array
(
'ajax_forms_test'
=>
array
(
'foo'
=>
42
)),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'settings' AJAX command issued with correct data"
);
}
}
core/modules/system/lib/Drupal/system/Tests/Ajax/ElementValidationTest.php
0 → 100644
View file @
ee8fbcf2
<?php
/**
* @file
* Definition of Drupal\system\Tests\Ajax\ElementValidationTest.
*/
namespace
Drupal\system\Tests\Ajax
;
/**
* Miscellaneous Ajax tests using ajax_test module.
*/
class
ElementValidationTest
extends
AjaxTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Miscellaneous AJAX tests'
,
'description'
=>
'Various tests of AJAX behavior'
,
'group'
=>
'AJAX'
,
);
}
/**
* Try to post an Ajax change to a form that has a validated element.
*
* The drivertext field is Ajax-enabled. An additional field is not, but
* is set to be a required field. In this test the required field is not
* filled in, and we want to see if the activation of the "drivertext"
* Ajax-enabled field fails due to the required field being empty.
*/
function
testAjaxElementValidation
()
{
$web_user
=
$this
->
drupalCreateUser
();
$edit
=
array
(
'drivertext'
=>
t
(
'some dumb text'
));
// Post with 'drivertext' as the triggering element.
$post_result
=
$this
->
drupalPostAJAX
(
'ajax_validation_test'
,
$edit
,
'drivertext'
);
// Look for a validation failure in the resultant JSON.
$this
->
assertNoText
(
t
(
'Error message'
),
t
(
"No error message in resultant JSON"
));
$this
->
assertText
(
'ajax_forms_test_validation_form_callback invoked'
,
t
(
'The correct callback was invoked'
));
}
}
core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php
0 → 100644
View file @
ee8fbcf2
<?php
/**
* @file
* Definition of Drupal\system\Tests\Ajax\FormValuesTest.
*/
namespace
Drupal\system\Tests\Ajax
;
/**
* Test that $form_state['values'] is properly delivered to $ajax['callback'].
*/
class
FormValuesTest
extends
AjaxTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'AJAX command form values'
,
'description'
=>
'Tests that form values are properly delivered to AJAX callbacks.'
,
'group'
=>
'AJAX'
,
);
}
function
setUp
()
{
parent
::
setUp
();
$this
->
web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
));
$this
->
drupalLogin
(
$this
->
web_user
);
}
/**
* Create a simple form, then POST to system/ajax to change to it.
*/
function
testSimpleAjaxFormValue
()
{
// Verify form values of a select element.
foreach
(
array
(
'red'
,
'green'
,
'blue'
)
as
$item
)
{
$edit
=
array
(
'select'
=>
$item
,
);
$commands
=
$this
->
drupalPostAJAX
(
'ajax_forms_test_get_form'
,
$edit
,
'select'
);
$expected
=
array
(
'command'
=>
'data'
,
'value'
=>
$item
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"verification of AJAX form values from a selectbox issued with a correct value"
);
}
// Verify form values of a checkbox element.
foreach
(
array
(
FALSE
,
TRUE
)
as
$item
)
{
$edit
=
array
(
'checkbox'
=>
$item
,
);
$commands
=
$this
->
drupalPostAJAX
(
'ajax_forms_test_get_form'
,
$edit
,
'checkbox'
);
$expected
=
array
(
'command'
=>
'data'
,
'value'
=>
(
int
)
$item
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"verification of AJAX form values from a checkbox issued with a correct value"
);
}
}
}
core/modules/system/
tests/ajax.test
→
core/modules/system/
lib/Drupal/system/Tests/Ajax/FrameworkTest.php
View file @
ee8fbcf2
<?php
<?php
/**
use
Drupal\simpletest\WebTestBase
;
* @file
* Definition of Drupal\system\Tests\Ajax\FrameworkTest.
class
AJAXTestCase
extends
WebTestBase
{
function
setUp
()
{
$modules
=
func_get_args
();
if
(
isset
(
$modules
[
0
])
&&
is_array
(
$modules
[
0
]))
{
$modules
=
$modules
[
0
];
}
parent
::
setUp
(
array_unique
(
array_merge
(
array
(
'ajax_test'
,
'ajax_forms_test'
),
$modules
)));
}
/**
* Assert that a command with the required properties exists within the array of Ajax commands returned by the server.
*
* The Ajax framework, via the ajax_deliver() and ajax_render() functions,
* returns an array of commands. This array sometimes includes commands
* automatically provided by the framework in addition to commands returned by
* a particular page callback. During testing, we're usually interested that a
* particular command is present, and don't care whether other commands
* precede or follow the one we're interested in. Additionally, the command
* we're interested in may include additional data that we're not interested
* in. Therefore, this function simply asserts that one of the commands in
* $haystack contains all of the keys and values in $needle. Furthermore, if
* $needle contains a 'settings' key with an array value, we simply assert
* that all keys and values within that array are present in the command we're
* checking, and do not consider it a failure if the actual command contains
* additional settings that aren't part of $needle.
*
* @param $haystack
* An array of Ajax commands returned by the server.
* @param $needle
* Array of info we're expecting in one of those commands.
* @param $message
* An assertion message.
*/
*/
protected
function
assertCommand
(
$haystack
,
$needle
,
$message
)
{
$found
=
FALSE
;
namespace
Drupal\system\Tests\Ajax
;
foreach
(
$haystack
as
$command
)
{
// If the command has additional settings that we're not testing for, do
// not consider that a failure.
if
(
isset
(
$command
[
'settings'
])
&&
is_array
(
$command
[
'settings'
])
&&
isset
(
$needle
[
'settings'
])
&&
is_array
(
$needle
[
'settings'
]))
{
$command
[
'settings'
]
=
array_intersect_key
(
$command
[
'settings'
],
$needle
[
'settings'
]);
}
// If the command has additional data that we're not testing for, do not
// consider that a failure. Also, == instead of ===, because we don't
// require the key/value pairs to be in any particular order
// (http://www.php.net/manual/language.operators.array.php).
if
(
array_intersect_key
(
$command
,
$needle
)
==
$needle
)
{
$found
=
TRUE
;
break
;
}
}
$this
->
assertTrue
(
$found
,
$message
);
}
}
/**
/**
* Tests primary Ajax framework functions.
* Tests primary Ajax framework functions.
*/
*/
class
AJAXFrameworkTestCase
extends
AJAXTestC
ase
{
class
FrameworkTest
extends
AjaxTestB
ase
{
public
static
function
getInfo
()
{
public
static
function
getInfo
()
{
return
array
(
return
array
(
'name'
=>
'AJAX framework'
,
'name'
=>
'AJAX framework'
,
...
@@ -218,316 +168,3 @@ function testLazyLoadOverriddenCSS() {
...
@@ -218,316 +168,3 @@ function testLazyLoadOverriddenCSS() {
$this
->
assertNoText
(
'system.base.css?'
,
'Ajax lazy loading does not add overridden CSS files.'
);
$this
->
assertNoText
(
'system.base.css?'
,
'Ajax lazy loading does not add overridden CSS files.'
);
}
}
}
}
/**
* Tests Ajax framework commands.
*/
class
AJAXCommandsTestCase
extends
AJAXTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'AJAX commands'
,
'description'
=>
'Performs tests on AJAX framework commands.'
,
'group'
=>
'AJAX'
,
);
}
/**
* Test the various Ajax Commands.
*/
function
testAJAXCommands
()
{
$form_path
=
'ajax_forms_test_ajax_commands_form'
;
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
));
$this
->
drupalLogin
(
$web_user
);
$edit
=
array
();
// Tests the 'after' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'After': Click to put something after the div"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'after'
,
'data'
=>
'This will be placed after'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'after' AJAX command issued with correct data"
);
// Tests the 'alert' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'Alert': Click to alert"
)));
$expected
=
array
(
'command'
=>
'alert'
,
'text'
=>
'Alert'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'alert' AJAX Command issued with correct text"
);
// Tests the 'append' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'Append': Click to append something"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'append'
,
'data'
=>
'Appended text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'append' AJAX command issued with correct data"
);
// Tests the 'before' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'before': Click to put something before the div"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'before'
,
'data'
=>
'Before text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'before' AJAX command issued with correct data"
);
// Tests the 'changed' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX changed: Click to mark div changed."
)));
$expected
=
array
(
'command'
=>
'changed'
,
'selector'
=>
'#changed_div'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'changed' AJAX command issued with correct selector"
);
// Tests the 'changed' command using the second argument.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX changed: Click to mark div changed with asterisk."
)));
$expected
=
array
(
'command'
=>
'changed'
,
'selector'
=>
'#changed_div'
,
'asterisk'
=>
'#changed_div_mark_this'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'changed' AJAX command (with asterisk) issued with correct selector"
);
// Tests the 'css' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"Set the the '#box' div to be blue."
)));
$expected
=
array
(
'command'
=>
'css'
,
'selector'
=>
'#css_div'
,
'argument'
=>
array
(
'background-color'
=>
'blue'
),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'css' AJAX command issued with correct selector"
);
// Tests the 'data' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX data command: Issue command."
)));
$expected
=
array
(
'command'
=>
'data'
,
'name'
=>
'testkey'
,
'value'
=>
'testvalue'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'data' AJAX command issued with correct key and value"
);
// Tests the 'invoke' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX invoke command: Invoke addClass() method."
)));
$expected
=
array
(
'command'
=>
'invoke'
,
'method'
=>
'addClass'
,
'arguments'
=>
array
(
'error'
),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'invoke' AJAX command issued with correct method and argument"
);
// Tests the 'html' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX html: Replace the HTML in a selector."
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'html'
,
'data'
=>
'replacement text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'html' AJAX command issued with correct data"
);
// Tests the 'insert' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX insert: Let client insert based on #ajax['method']."
)));
$expected
=
array
(
'command'
=>
'insert'
,
'data'
=>
'insert replacement text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'insert' AJAX command issued with correct data"
);
// Tests the 'prepend' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'prepend': Click to prepend something"
)));
$expected
=
array
(
'command'
=>
'insert'
,
'method'
=>
'prepend'
,
'data'
=>
'prepended text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'prepend' AJAX command issued with correct data"
);
// Tests the 'remove' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'remove': Click to remove text"
)));
$expected
=
array
(
'command'
=>
'remove'
,
'selector'
=>
'#remove_text'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'remove' AJAX command issued with correct command and selector"
);
// Tests the 'restripe' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'restripe' command"
)));
$expected
=
array
(
'command'
=>
'restripe'
,
'selector'
=>
'#restripe_table'
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'restripe' AJAX command issued with correct selector"
);
// Tests the 'settings' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX 'settings' command"
)));
$expected
=
array
(
'command'
=>
'settings'
,
'settings'
=>
array
(
'ajax_forms_test'
=>
array
(
'foo'
=>
42
)),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'settings' AJAX command issued with correct data"
);
}
}
/**
* Test that $form_state['values'] is properly delivered to $ajax['callback'].
*/
class
AJAXFormValuesTestCase
extends
AJAXTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'AJAX command form values'
,
'description'
=>
'Tests that form values are properly delivered to AJAX callbacks.'
,
'group'
=>
'AJAX'
,
);
}
function
setUp
()
{
parent
::
setUp
();
$this
->
web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
));
$this
->
drupalLogin
(
$this
->
web_user
);
}
/**
* Create a simple form, then POST to system/ajax to change to it.
*/
function
testSimpleAJAXFormValue
()
{
// Verify form values of a select element.
foreach
(
array
(
'red'
,
'green'
,
'blue'
)
as
$item
)
{
$edit
=
array
(
'select'
=>
$item
,
);
$commands
=
$this
->
drupalPostAJAX
(
'ajax_forms_test_get_form'
,
$edit
,
'select'
);
$expected
=
array
(
'command'
=>
'data'
,
'value'
=>
$item
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"verification of AJAX form values from a selectbox issued with a correct value"
);
}
// Verify form values of a checkbox element.
foreach
(
array
(
FALSE
,
TRUE
)
as
$item
)
{
$edit
=
array
(
'checkbox'
=>
$item
,
);
$commands
=
$this
->
drupalPostAJAX
(
'ajax_forms_test_get_form'
,
$edit
,
'checkbox'
);
$expected
=
array
(
'command'
=>
'data'
,
'value'
=>
(
int
)
$item
,
);
$this
->
assertCommand
(
$commands
,
$expected
,
"verification of AJAX form values from a checkbox issued with a correct value"
);
}
}