Skip to content

Commit

Permalink
Fixed test fails by installing the users table and setting the curren…
Browse files Browse the repository at this point in the history
…t user.
  • Loading branch information
klausi committed Mar 26, 2014
1 parent 2e26f53 commit 91a6934
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
Expand Up @@ -41,6 +41,8 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();

$this->installSchema('user', array('users'));

$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
}
Expand Down
Expand Up @@ -57,6 +57,8 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();

$this->installSchema('user', array('users'));

$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->accessChecker = new MockEditEntityFieldAccessCheck();
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
Expand Down
Expand Up @@ -70,6 +70,7 @@ public function setUp() {

// Install the Filter module.
$this->installSchema('system', 'url_alias');
$this->installSchema('user', array('users'));
$this->enableModules(array('user', 'filter'));

// Enable the Text Editor and Text Editor Test module.
Expand Down
Expand Up @@ -48,9 +48,11 @@ function assertEntityAccess($ops, AccessibleInterface $object, AccountInterface
* Ensures entity access is properly working.
*/
function testEntityAccess() {
$originial_user = \Drupal::currentUser();
// Set up a non-admin user that is allowed to view test entities.
global $user;
$user = $this->createUser(array('uid' => 2), array('view test entity'));
\Drupal::getContainer()->set('current_user', $user);
$entity = entity_create('entity_test', array(
'name' => 'test',
));
Expand All @@ -63,6 +65,9 @@ function testEntityAccess() {
'view' => TRUE,
), $entity);

// Restore the original user.
\Drupal::getContainer()->set('current_user', $originial_user);

// The custom user is not allowed to perform any operation on test entities.
$custom_user = $this->createUser();
$this->assertEntityAccess(array(
Expand Down Expand Up @@ -99,7 +104,7 @@ function testEntityAccessDefaultController() {
* Ensures entity access for entity translations is properly working.
*/
function testEntityTranslationAccess() {

$originial_user = \Drupal::currentUser();
// Set up a non-admin user that is allowed to view test entity translations.
global $user;
$user = $this->createUser(array('uid' => 2), array('view test entity translations'));
Expand All @@ -123,6 +128,9 @@ function testEntityTranslationAccess() {
$this->assertEntityAccess(array(
'view' => TRUE,
), $translation);

// Restore the original user.
\Drupal::getContainer()->set('current_user', $originial_user);
}

/**
Expand Down
Expand Up @@ -92,7 +92,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['user_id'] = OwnerFieldDefinition::create()
->setLabel(t('User ID'))
->setDescription(t('The ID of the associated user.'))
->setSettings(array('target_type' => 'user'))
->setTranslatable(TRUE);

return $fields;
Expand Down
Expand Up @@ -50,6 +50,7 @@ protected function setUp() {
parent::setUp();

$this->installSchema('entity_test', array('entity_test'));
$this->installSchema('user', array('users'));

$this->storageController = $this->container->get('entity.manager')->getStorageController('entity_test');
}
Expand Down

0 comments on commit 91a6934

Please sign in to comment.