Commit 61f97d31 authored by catch's avatar catch

Issue #3041837 by claudiu.cristea, naveenvalecha, Krzysztof Domański, Lendude:...

Issue #3041837 by claudiu.cristea, naveenvalecha, Krzysztof Domański, Lendude: Convert UserDataTest into a kernel test
parent c8ef0bb6
<?php
namespace Drupal\Tests\user\Functional\Views;
namespace Drupal\Tests\user\Kernel\Views;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\user\Entity\User;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the user data service field handler.
*
* @group user
*
* @see \Drupal\user\Plugin\views\field\UserData
*/
class UserDataTest extends UserTestBase {
class UserDataTest extends ViewsKernelTestBase {
/**
* Provides the user data service object.
*
* @var \Drupal\user\UserDataInterface
* {@inheritdoc}
*/
protected $userData;
public static $testViews = ['test_user_data'];
/**
* Views used by this test.
*
* @var array
* {@inheritdoc}
*/
public static $testViews = ['test_user_data'];
public static $modules = ['user_test_views'];
/**
* Tests field handler.
*/
public function testDataField() {
// But some random values into the user data service.
$this->userData = $this->container->get('user.data');
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
$this->installEntitySchema('user');
$this->installSchema('user', ['users_data']);
$user = User::create([
// Set 'uid' because the 'test_user_data' view filters the user with an ID
// equal to 2.
'uid' => 2,
'name' => $this->randomMachineName(),
]);
$user->save();
// Add some random value as user data.
$user_data = $this->container->get('user.data');
$random_value = $this->randomMachineName();
$this->userData->set('views_test_config', $this->users[0]->id(), 'test_value_name', $random_value);
$user_data->set('views_test_config', $user->id(), 'test_value_name', $random_value);
$view = Views::getView('test_user_data');
$this->executeView($view);
$output = $view->field['data']->render($view->result[0]);
$this->assertEqual($output, $random_value, 'A valid user data got rendered.');
// Assert that using a valid user data key renders the value.
$this->assertEquals($random_value, $output);
$view->field['data']->options['data_name'] = $this->randomMachineName();
$output = $view->field['data']->render($view->result[0]);
$this->assertFalse($output, 'An invalid configuration does not return anything');
$output = $view->field['data']->render($view->result[0]);
// An invalid configuration does not return anything.
$this->assertNull($output);
}
}
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