Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023

This commit is contained in:
Pantheon Automation 2015-09-04 13:20:09 -07:00 committed by Greg Anderson
parent 2720a9ec4b
commit f3791f1da3
1898 changed files with 54300 additions and 11481 deletions

View file

@ -0,0 +1,90 @@
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Migrate\ProfileFieldTest.
*/
namespace Drupal\Tests\user\Unit\Migrate;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests profile_field source plugin.
*
* @group user
*/
class ProfileFieldTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\user\Plugin\migrate\source\ProfileField';
protected $migrationConfiguration = [
'id' => 'test_profile_fields',
'source' => [
'plugin' => 'd6_profile_field',
],
];
// We need to set up the database contents; it's easier to do that below.
// These are sample result queries.
// @todo Add multiple cases.
protected $expectedResults = [
[
'fid' => 1,
'title' => 'First name',
'name' => 'profile_first_name',
'explanation' => 'First name user',
'category' => 'profile',
'page' => '',
'type' => 'textfield',
'weight' => 0,
'required' => 1,
'register' => 0,
'visibility' => 2,
'autocomplete' => 0,
'options' => [],
],
[
'fid' => 2,
'title' => 'Last name',
'name' => 'profile_last_name',
'explanation' => 'Last name user',
'category' => 'profile',
'page' => '',
'type' => 'textfield',
'weight' => 0,
'required' => 0,
'register' => 0,
'visibility' => 2,
'autocomplete' => 0,
'options' => [],
],
[
'fid' => 3,
'title' => 'Policy',
'name' => 'profile_policy',
'explanation' => 'A checkbox that say if you accept policy of website',
'category' => 'profile',
'page' => '',
'type' => 'checkbox',
'weight' => 0,
'required' => 1,
'register' => 1,
'visibility' => 2,
'autocomplete' => 0,
'options' => [],
],
];
/**
* Prepopulate contents with results.
*/
protected function setUp() {
$this->databaseContents['profile_fields'] = $this->expectedResults;
foreach ($this->databaseContents['profile_fields'] as &$row) {
$row['options'] = serialize([]);
}
parent::setUp();
}
}

View file

@ -0,0 +1,86 @@
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Migrate\d6\RoleTest.
*/
namespace Drupal\Tests\user\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 role source plugin.
*
* @group user
*/
class RoleTest extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\user\Plugin\migrate\source\d6\Role';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'test',
// This needs to be the identifier of the actual key: cid for comment, nid
// for node and so on.
'source' => array(
'plugin' => 'd6_user_role',
),
);
protected $expectedResults = array(
array(
'rid' => 1,
'name' => 'anonymous user',
'permissions' => array(
'access content',
),
),
array(
'rid' => 2,
'name' => 'authenticated user',
'permissions' => array(
'access comments',
'access content',
'post comments',
'post comments without approval',
),
),
array(
'rid' => 3,
'name' => 'administrator',
'permissions' => array(
'access comments',
'administer comments',
'post comments',
'post comments without approval',
'access content',
'administer content types',
'administer nodes',
),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $row) {
$this->databaseContents['permission'][] = array(
'perm' => implode(', ', $row['permissions']),
'rid' => $row['rid'],
);
unset($row['permissions']);
$this->databaseContents['role'][] = $row;
}
$this->databaseContents['filter_formats'][] = array(
'format' => 1,
'roles' => '',
);
parent::setUp();
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Migrate\d6\UserPictureTest.
*/
namespace Drupal\Tests\user\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 user picture source plugin.
*
* @group user
*/
class UserPictureTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\user\Plugin\migrate\source\d6\UserPicture';
protected $migrationConfiguration = array(
'id' => 'test_user_picture',
'source' => array(
'plugin' => 'd6_user_picture',
),
);
protected $expectedResults = array(
array(
'uid' => 1,
'access' => 1382835435,
'picture' => 'sites/default/files/pictures/picture-1.jpg',
),
array(
'uid' => 2,
'access' => 1382835436,
'picture' => 'sites/default/files/pictures/picture-2.jpg',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['users'] = $this->expectedResults;
parent::setUp();
}
}

View file

@ -0,0 +1,88 @@
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Migrate\d6\UserTest.
*/
namespace Drupal\Tests\user\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D6 user source plugin.
*
* @group user
*/
class UserTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\user\Plugin\migrate\source\d6\User';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_user',
),
);
protected $expectedResults = array(
array(
'uid' => 2,
'name' => 'admin',
// @todo d6 hash?
'pass' => '1234',
'mail' => 'admin@example.com',
'theme' => '',
'signature' => '',
'signature_format' => 0,
'created' => 1279402616,
'access' => 1322981278,
'login' => 1322699994,
'status' => 0,
'timezone' => 'America/Lima',
'language' => 'en',
// @todo Add the file when needed.
'picture' => 'sites/default/files/pictures/picture-1.jpg',
'init' => 'admin@example.com',
'data' => NULL,
),
array(
'uid' => 4,
'name' => 'alice',
// @todo d6 hash?
'pass' => '1234',
'mail' => 'alice@example.com',
'theme' => '',
'signature' => '',
'signature_format' => 0,
'created' => 1322981368,
'access' => 1322982419,
'login' => 132298140,
'status' => 0,
'timezone' => 'America/Lima',
'language' => 'en',
'picture' => '',
'init' => 'alice@example.com',
'data' => NULL,
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $k => $row) {
$this->databaseContents['users'][$k] = $row;
}
// getDatabase() will not create empty tables, so we need to insert data
// even if it's irrelevant to the test.
$this->databaseContents['users_roles'] = array(
array(
'uid' => 99,
'rid' => 99,
),
);
parent::setUp();
}
}

View file

@ -11,6 +11,8 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Access\PermissionAccessCheck;
use Symfony\Component\Routing\Route;
use Drupal\Core\Cache\Context\CacheContextsManager;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\user\Access\PermissionAccessCheck
@ -26,12 +28,24 @@ class PermissionAccessCheckTest extends UnitTestCase {
*/
public $accessCheck;
/**
* The dependency injection container.
*
* @var \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected $container;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->container = new ContainerBuilder();
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
$this->container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($this->container);
$this->accessCheck = new PermissionAccessCheck();
}
@ -41,15 +55,13 @@ class PermissionAccessCheckTest extends UnitTestCase {
* @return array
*/
public function providerTestAccess() {
$allowed = AccessResult::allowedIf(TRUE)->addCacheContexts(['user.permissions']);
$neutral = AccessResult::allowedIf(FALSE)->addCacheContexts(['user.permissions']);
return [
[[], AccessResult::allowedIf(FALSE)],
[['_permission' => 'allowed'], $allowed],
[['_permission' => 'denied'], $neutral],
[['_permission' => 'allowed+denied'], $allowed],
[['_permission' => 'allowed+denied+other'], $allowed],
[['_permission' => 'allowed,denied'], $neutral],
[[], FALSE],
[['_permission' => 'allowed'], TRUE, ['user.permissions']],
[['_permission' => 'denied'], FALSE, ['user.permissions']],
[['_permission' => 'allowed+denied'], TRUE, ['user.permissions']],
[['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']],
[['_permission' => 'allowed,denied'], FALSE, ['user.permissions']],
];
}
@ -59,7 +71,8 @@ class PermissionAccessCheckTest extends UnitTestCase {
* @dataProvider providerTestAccess
* @covers ::access
*/
public function testAccess($requirements, $access) {
public function testAccess($requirements, $access, array $contexts = []) {
$access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts);
$user = $this->getMock('Drupal\Core\Session\AccountInterface');
$user->expects($this->any())
->method('hasPermission')
@ -71,7 +84,7 @@ class PermissionAccessCheckTest extends UnitTestCase {
));
$route = new Route('', [], $requirements);
$this->assertEquals($access, $this->accessCheck->access($route, $user));
$this->assertEquals($access_result, $this->accessCheck->access($route, $user));
}
}

View file

@ -0,0 +1,78 @@
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Plugin\migrate\source\d7\RoleTest.
*/
namespace Drupal\Tests\user\Unit\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 role source plugin.
*
* @group user
*/
class RoleTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\user\Plugin\migrate\source\d7\Role';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd7_user_role',
),
);
protected $expectedResults = array(
array(
'rid' => 1,
'name' => 'anonymous user',
'permissions' => array(
'access content',
),
),
array(
'rid' => 2,
'name' => 'authenticated user',
'permissions' => array(
'access comments',
'access content',
'post comments',
'post comments without approval',
),
),
array(
'rid' => 3,
'name' => 'administrator',
'permissions' => array(
'access comments',
'administer comments',
'post comments',
'post comments without approval',
'access content',
'administer content types',
'administer nodes',
),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $row) {
foreach ($row['permissions'] as $permission) {
$this->databaseContents['role_permission'][] = array(
'permission' => $permission,
'rid' => $row['rid'],
);
}
unset($row['permissions']);
$this->databaseContents['role'][] = $row;
}
parent::setUp();
}
}

View file

@ -0,0 +1,117 @@
<?php
/**
* @file
* Contains \Drupal\Tests\user\Unit\Plugin\migrate\source\d7\UserTest.
*/
namespace Drupal\Tests\user\Unit\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 user source plugin.
*
* @group user
*/
class UserTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\user\Plugin\migrate\source\d7\User';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_user',
],
];
protected $expectedResults = [
[
'uid' => '2',
'name' => 'Odo',
'pass' => '$S$DVpvPItXvnsmF3giVEe7Jy2lG.SCoEs8uKwpHsyPvdeNAaNZYxZ8',
'mail' => 'odo@local.host',
'signature' => '',
'signature_format' => 'filtered_html',
'created' => '1432750741',
'access' => '0',
'login' => '0',
'status' => '1',
'timezone' => 'America/Chicago',
'language' => '',
'picture' => '0',
'init' => 'odo@local.host',
'roles' => [2],
'data' => [
'contact' => 1,
],
'field_file' => [
[
'fid' => 99,
'display' => 1,
'description' => 'None',
],
],
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['users'][] = [
'uid' => '2',
'name' => 'Odo',
'pass' => '$S$DVpvPItXvnsmF3giVEe7Jy2lG.SCoEs8uKwpHsyPvdeNAaNZYxZ8',
'mail' => 'odo@local.host',
'theme' => '',
'signature' => '',
'signature_format' => 'filtered_html',
'created' => '1432750741',
'access' => '0',
'login' => '0',
'status' => '1',
'timezone' => 'America/Chicago',
'language' => '',
'picture' => '0',
'init' => 'odo@local.host',
'data' => 'a:1:{s:7:"contact";i:1;}',
];
$this->databaseContents['users_roles'][] = [
'uid' => 2,
'rid' => 2,
];
$this->databaseContents['role'][] = [
'rid' => 2,
'name' => 'authenticated user',
'weight' => 0,
];
$this->databaseContents['field_config_instance'] = [
[
'id' => '33',
'field_id' => '11',
'field_name' => 'field_file',
'entity_type' => 'user',
'bundle' => 'user',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$this->databaseContents['field_data_field_file'] = [
[
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => 0,
'entity_id' => 2,
'revision_id' => NULL,
'language' => 'und',
'delta' => 0,
'field_file_fid' => 99,
'field_file_display' => 1,
'field_file_description' => 'None',
],
];
parent::setUp();
}
}

View file

@ -7,8 +7,9 @@
namespace Drupal\Tests\user\Unit;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Context\CacheContextsManager;
use Drupal\Core\DependencyInjection\Container;
use Drupal\Tests\UnitTestCase;
use Drupal\user\UserAccessControlHandler;
@ -62,6 +63,12 @@ class UserAccessControlHandlerTest extends UnitTestCase {
*/
public function setUp() {
parent::setUp();
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
$container = new Container();
$container->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
$this->viewer = $this->getMock('\Drupal\Core\Session\AccountInterface');
$this->viewer
->expects($this->any())
@ -125,13 +132,8 @@ class UserAccessControlHandlerTest extends UnitTestCase {
->will($this->returnValue($this->{$target}));
foreach (array('view' => $view, 'edit' => $edit) as $operation => $result) {
$message = SafeMarkup::format("User @field field access returns @result with operation '@op' for @account accessing @target", array(
'@field' => $field,
'@result' => !isset($result) ? 'null' : ($result ? 'true' : 'false'),
'@op' => $operation,
'@account' => $viewer,
'@target' => $target,
));
$result_text = !isset($result) ? 'null' : ($result ? 'true' : 'false');
$message = "User '$field' field access returns '$result_text' with operation '$operation' for '$viewer' accessing '$target'";
$this->assertSame($result, $this->accessControlHandler->fieldAccess($operation, $field_definition, $this->{$viewer}, $this->items), $message);
}
}

View file

@ -7,7 +7,6 @@
namespace Drupal\Tests\user\Unit\Views\Argument;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Entity\Role;
@ -20,9 +19,9 @@ use Drupal\user\Plugin\views\argument\RolesRid;
class RolesRidTest extends UnitTestCase {
/**
* Tests the title_query method.
* Tests the titleQuery method.
*
* @see \Drupal\user\Plugin\views\argument\RolesRid::title_query()
* @covers ::titleQuery
*/
public function testTitleQuery() {
$role1 = new Role(array(
@ -72,16 +71,16 @@ class RolesRidTest extends UnitTestCase {
$roles_rid_argument = new RolesRid(array(), 'user__roles_rid', array(), $entity_manager);
$roles_rid_argument->value = array();
$titles = $roles_rid_argument->title_query();
$titles = $roles_rid_argument->titleQuery();
$this->assertEquals(array(), $titles);
$roles_rid_argument->value = array('test_rid_1');
$titles = $roles_rid_argument->title_query();
$titles = $roles_rid_argument->titleQuery();
$this->assertEquals(array('test rid 1'), $titles);
$roles_rid_argument->value = array('test_rid_1', 'test_rid_2');
$titles = $roles_rid_argument->title_query();
$this->assertEquals(array('test rid 1', SafeMarkup::checkPlain('test <strong>rid 2</strong>')), $titles);
$titles = $roles_rid_argument->titleQuery();
$this->assertEquals(array('test rid 1', 'test <strong>rid 2</strong>'), $titles);
}
}