Commit d736cc1a authored by catch's avatar catch
Browse files

Issue #1748176 by dawehner, fastangel, amateescu, damiankloip: Add test...

Issue #1748176 by dawehner, fastangel, amateescu, damiankloip: Add test coverage for Views user integration.
parent be7209c9
......@@ -279,7 +279,14 @@ function views_ajax_form_wrapper($form_id, &$form_state) {
}
/**
* Page callback for views user autocomplete
* Page callback for views user autocomplete.
*
* @param string $string
* (optional) A comma-separated list of user names entered in the
* autocomplete form element. Only the last user is used for autocompletion.
* Defaults to '' (an empty string).
*
* @return Symfony\Component\HttpFoundation\JsonResponse
*/
function views_ajax_autocomplete_user($string = '') {
// The user enters a comma-separated list of user name. We only autocomplete the last name.
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Tests\User;
/**
* Tests views user argument argument handler.
* Tests views user argument validator plugin.
*/
class ArgumentValidateTest extends UserTestBase {
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\User\HandlerArgumentUserUidTest.
*/
namespace Drupal\views\Tests\User;
/**
* Tests views user uid argument handler.
*/
class HandlerArgumentUserUidTest extends UserTestBase {
public static function getInfo() {
return array(
'name' => 'User: Uid Argument',
'description' => 'Tests the handler of the user: uid Argument.',
'group' => 'Views Modules',
);
}
/**
* Tests the generated title of an user: uid argument.
*/
public function testArgumentTitle() {
$view = views_get_view('test_user_uid_argument');
// Tests an invalid user uid.
$this->executeView($view, array(rand(1000, 10000)));
$this->assertFalse($view->getTitle());
$view->destroy();
// Tests a valid user.
$account = $this->drupalCreateUser();
$this->executeView($view, array($account->uid));
$this->assertEqual($view->getTitle(), $account->label());
$view->destroy();
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\User\HandlerFilterUserNameTest.
*/
namespace Drupal\views\Tests\User;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests the handler of the user: name filter.
*
* @see Views\user\Plugin\views\filter\Name
*/
class HandlerFilterUserNameTest extends ViewTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views_ui');
/**
* Accounts used by this test.
*
* @var array
*/
protected $accounts = array();
/**
* Usernames of $accounts.
*
* @var array
*/
protected $names = array();
/**
* Stores the column map for this testCase.
*
* @var array
*/
public $columnMap = array(
'uid' => 'uid',
);
public static function getInfo() {
return array(
'name' => 'User: Name Filter',
'description' => 'Tests the handler of the user: name filter',
'group' => 'Views Modules',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->accounts = array();
$this->names = array();
for ($i = 0; $i < 3; $i++) {
$this->accounts[] = $account = $this->drupalCreateUser();
$this->names[] = $account->label();
}
}
/**
* Tests just using the filter.
*/
public function testUserNameApi() {
$view = views_get_view('test_user_name');
// Test all of the accounts with a single entry.
foreach ($this->accounts as $account) {
$view->storage->display['default']['display_options']['filters']['uid']['value'] = $account->id();
}
$this->executeView($view);
$this->assertIdenticalResultset($view, array(array('uid' => $account->id())), $this->columnMap);
}
/**
* Tests using the user interface.
*/
public function testAdminUserInterface() {
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
$this->drupalLogin($admin_user);
$path = 'admin/structure/views/nojs/config-item/test_user_name/default/filter/uid';
$this->drupalGet($path);
// Pass in an invalid username, the validation should catch it.
$users = array($this->randomName());
$users = array_map('strtolower', $users);
$edit = array(
'options[value]' => implode(', ', $users)
);
$this->drupalPost($path, $edit, t('Apply'));
$message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', $users)));
$this->assertText($message);
// Pass in an invalid username and a valid username.
$random_name = $this->randomName();
$users = array($random_name, $this->names[0]);
$users = array_map('strtolower', $users);
$edit = array(
'options[value]' => implode(', ', $users)
);
$users = array($users[0]);
$this->drupalPost($path, $edit, t('Apply'));
$message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', $users)));
$this->assertRaw($message);
// Pass in just valid usernames.
$users = $this->names;
$users = array_map('strtolower', $users);
$edit = array(
'options[value]' => implode(', ', $users)
);
$this->drupalPost($path, $edit, t('Apply'));
$message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', $users)));
$this->assertNoRaw($message);
}
/**
* Tests exposed filters.
*/
public function testExposedFilter() {
$path = 'test_user_name';
$options = array();
// Pass in an invalid username, the validation should catch it.
$users = array($this->randomName());
$users = array_map('strtolower', $users);
$options['query']['uid'] = implode(', ', $users);
$this->drupalGet($path, $options);
$message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', $users)));
$this->assertRaw($message);
// Pass in an invalid username and a valid username.
$users = array($this->randomName(), $this->names[0]);
$options['query']['uid'] = implode(', ', $users);
$users = array_map('strtolower', $users);
$users = array($users[0]);
$this->drupalGet($path, $options);
$message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', $users)));
$this->assertRaw($message);
// Pass in just valid usernames.
$users = $this->names;
$options['query']['uid'] = implode(', ', $users);
$users = array_map('strtolower', $users);
$this->drupalGet($path, $options);
$this->assertNoRaw('Unable to find user');
// The actual result should contain all of the user ids.
foreach ($this->accounts as $account) {
$this->assertRaw($account->uid);
}
}
/**
* Tests the autocomplete function.
*
* @see views_ajax_autocomplete_user
*/
public function testUserAutocomplete() {
module_load_include('inc', 'views', 'includes/ajax');
// Nothing should return no user.
$result = (array) json_decode(views_ajax_autocomplete_user(''));
$this->assertFalse($result);
// A random user should also not be findable.
$result = (array) json_decode(views_ajax_autocomplete_user($this->randomName())->getContent());
$this->assertFalse($result);
// A valid user should be found.
$result = (array) json_decode(views_ajax_autocomplete_user($this->names[0])->getContent());
$expected_result = array($this->names[0] => $this->names[0]);
$this->assertIdentical($result, $expected_result);
}
}
api_version: '3.0'
base_table: users
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
fields:
uid:
id: uid
table: users
field: uid
arguments:
uid:
id: uid
table: users
field: uid
title_enable: true
title: %1
display_plugin: default
display_title: Master
id: default
position: '0'
human_name:
name: test_user_uid_argument
api_version: '3.0'
base_table: users
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: none
cache:
type: none
exposed_form:
type: basic
pager:
type: full
row:
type: fields
style:
type: default
fields:
name:
id: uid
table: users
field: uid
filters:
uid:
id: uid
table: users
field: uid
exposed: true
expose:
operator_id: uid_op
label: Name
operator: uid_op
identifier: uid
remember_roles:
authenticated: authenticated
anonymous: 0
display_plugin: default
display_title: Master
id: default
position: '0'
page_1:
display_options:
path: test_user_name
display_plugin: page
display_title: Page
id: page_1
position: '0'
human_name: ''
name: test_user_name
tag: ''
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment