From e74f80a3040f233771b23a24c186a0243778ccc6 Mon Sep 17 00:00:00 2001 From: amontero Date: Wed, 11 Jun 2014 12:21:07 +0200 Subject: [PATCH] #1694574 - tests only --- modules/user/tests/user_ajax_test.info | 6 ++ modules/user/tests/user_ajax_test.module | 42 +++++++++++++ modules/user/user.test | 102 +++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 modules/user/tests/user_ajax_test.info create mode 100644 modules/user/tests/user_ajax_test.module diff --git a/modules/user/tests/user_ajax_test.info b/modules/user/tests/user_ajax_test.info new file mode 100644 index 0000000..4798ea3 --- /dev/null +++ b/modules/user/tests/user_ajax_test.info @@ -0,0 +1,6 @@ +name = "User module ajax tests" +description = "Support module for user ajax testing." +package = Testing +version = VERSION +core = 7.x +hidden = TRUE diff --git a/modules/user/tests/user_ajax_test.module b/modules/user/tests/user_ajax_test.module new file mode 100644 index 0000000..87eb37c --- /dev/null +++ b/modules/user/tests/user_ajax_test.module @@ -0,0 +1,42 @@ + $form['#id'], + 'callback' => 'user_ajax_test_form_user_login_ajax', + 'progress' => array( + 'type' => 'throbber', + 'message' => t('Logging in'), + ), + 'event' => 'click', + ); + } +} + +/** + * AJAX Callback for user_login_form(). + * + * @see ajax_login_test_form_user_login_alter(). + */ +function user_ajax_test_form_user_login_ajax($form, $form_state) { + global $user; + if ($user->uid) { + return t('Successfully logged in.'); + } + else { + return $form; + } +} diff --git a/modules/user/user.test b/modules/user/user.test index e2086d4..a2b619c 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -2366,3 +2366,105 @@ class UserValidateCurrentPassCustomForm extends DrupalWebTestCase { $this->assertText(t('The password has been validated and the form submitted successfully.')); } } + +/** + * Tests the user login forms work with caching and AJAX submits. + */ +class UserLoginAjaxCacheTestCase extends AJAXTestCase { + + /** + * Provide information about the test. + */ + public static function getInfo() { + return array( + 'name' => 'User cached AJAX login', + 'description' => 'Ensure that AJAX login forms continue to work with anonymous caching enabled.', + 'group' => 'User', + ); + } + + /** + * Overrides DrupalWebTestCase::setUp(). + */ + public function setUp() { + parent::setUp('user_ajax_test'); + variable_set('cache', 1); + } + + /** + * Test that the user_login form cache works with AJAX submission. + */ + public function testUserLoginForm() { + // Create a user. + $user = $this->drupalCreateUser(); + $edit = array(); + $edit['name'] = $user->name; + $edit['pass'] = $user->pass_raw; + + // Log in using the page. + $commands = $this->drupalPostAJAX('user', $edit, array('submit' => t('Log in'))); + if (empty($commands)) { + $this->fail(t('No valid response for first log in with user_login form.')); + } + else { + $expected = array( + 'command' => 'insert', + 'data' => t('Successfully logged in.'), + ); + $this->assertCommand($commands, $expected, t('Successful first log in with user_login form.')); + } + + // Now, log out and repeat. + $this->drupalLogout(); + $commands = $this->drupalPostAJAX('user', $edit, array('submit' => t('Log in'))); + if (empty($commands)) { + $this->fail(t('No valid response for second log in with user_login form.')); + } + else { + $expected = array( + 'command' => 'insert', + 'data' => t('Successfully logged in.'), + ); + $this->assertCommand($commands, $expected, t('Successful second log in with user_login form.')); + } + } + + /** + * Test that the user_login_block form cache works with AJAX submission. + */ + public function testUserLoginBlockForm() { + // Create a user. + $user = $this->drupalCreateUser(); + $edit = array(); + $edit['name'] = $user->name; + $edit['pass'] = $user->pass_raw; + + // Log in using the page. + $commands = $this->drupalPostAJAX('', $edit, array('submit' => t('Log in'))); + if (empty($commands)) { + $this->fail(t('No valid response for first log in with user_login_block form.')); + } + else { + $expected = array( + 'command' => 'insert', + 'data' => t('Successfully logged in.'), + ); + $this->assertCommand($commands, $expected, t('Successful first log in with user_login_block form.')); + } + + // Now, log out and repeat. + $this->drupalLogout(); + $commands = $this->drupalPostAJAX('', $edit, array('submit' => t('Log in'))); + if (empty($commands)) { + $this->fail(t('No valid response for second log in with user_login_block form.')); + } + else { + $expected = array( + 'command' => 'insert', + 'data' => t('Successfully logged in.'), + ); + $this->assertCommand($commands, $expected, t('Successful second log in with user_login_block form.')); + } + } + +} -- 1.9.2