/**
  * Performs setup tasks before each individual test method is run.
  */
 public function setUp()
 {
     parent::setUp('content_access');
     // The parent method already installs most needed node and comment schemas,
     // but here we also need the comment statistics.
     $this->installSchema('comment', array('comment_entity_statistics'));
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database, as the user table is inner
     // joined by \Drupal\comment\CommentStorage.
     User::create(array('uid' => 0, 'name' => ''))->save();
     // Create a node with attached comment.
     $this->nodes[0] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'test title'));
     $this->nodes[0]->save();
     $comment_type = CommentType::create(array('id' => 'comment', 'target_entity_type_id' => 'node'));
     $comment_type->save();
     $this->installConfig(array('comment'));
     $this->addDefaultCommentField('node', 'page');
     $comment = Comment::create(array('entity_type' => 'node', 'entity_id' => $this->nodes[0]->id(), 'field_name' => 'comment', 'body' => 'test body', 'comment_type' => $comment_type->id()));
     $comment->save();
     $this->comments[] = $comment;
     $this->nodes[1] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'some title'));
     $this->nodes[1]->save();
     $this->nodes[2] = Node::create(array('status' => NODE_NOT_PUBLISHED, 'type' => 'page', 'title' => 'other title'));
     $this->nodes[2]->save();
     // Also index users, to verify that they are unaffected by the processor.
     $this->index->set('datasources', array('entity:comment', 'entity:node', 'entity:user'));
     $this->index->save();
     $this->index = entity_load('search_api_index', $this->index->id(), TRUE);
 }
 /**
  * Tests the getEntity method.
  */
 public function testGetEntity()
 {
     // The view is a view of comments, their nodes and their authors, so there
     // are three layers of entities.
     $account = User::create(['name' => $this->randomMachineName(), 'bundle' => 'user']);
     $account->save();
     $node = Node::create(['uid' => $account->id(), 'type' => 'page', 'title' => $this->randomString()]);
     $node->save();
     $comment = Comment::create(array('uid' => $account->id(), 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment'));
     $comment->save();
     $user = $this->drupalCreateUser(['access comments']);
     $this->drupalLogin($user);
     $view = Views::getView('test_field_get_entity');
     $this->executeView($view);
     $row = $view->result[0];
     // Tests entities on the base level.
     $entity = $view->field['cid']->getEntity($row);
     $this->assertEqual($entity->id(), $comment->id(), 'Make sure the right comment entity got loaded.');
     // Tests entities as relationship on first level.
     $entity = $view->field['nid']->getEntity($row);
     $this->assertEqual($entity->id(), $node->id(), 'Make sure the right node entity got loaded.');
     // Tests entities as relationships on second level.
     $entity = $view->field['uid']->getEntity($row);
     $this->assertEqual($entity->id(), $account->id(), 'Make sure the right user entity got loaded.');
 }
示例#3
0
 /**
  * Tests some of the methods.
  *
  * @see \Drupal\user\Entity\User::getRoles()
  * @see \Drupal\user\Entity\User::addRole()
  * @see \Drupal\user\Entity\User::removeRole()
  */
 public function testUserMethods()
 {
     $role_storage = $this->container->get('entity.manager')->getStorage('user_role');
     $role_storage->create(array('id' => 'test_role_one'))->save();
     $role_storage->create(array('id' => 'test_role_two'))->save();
     $role_storage->create(array('id' => 'test_role_three'))->save();
     $values = array('uid' => 1, 'roles' => array('test_role_one'));
     $user = User::create($values);
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertFalse($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one'), $user->getRoles());
     $user->addRole('test_role_one');
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertFalse($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one'), $user->getRoles());
     $user->addRole('test_role_two');
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one', 'test_role_two'), $user->getRoles());
     $user->removeRole('test_role_three');
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one', 'test_role_two'), $user->getRoles());
     $user->removeRole('test_role_one');
     $this->assertFalse($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_two'), $user->getRoles());
 }
 /**
  * Tests the normalization of node translations.
  */
 public function testNodeTranslation()
 {
     $node_type = NodeType::create(['type' => 'example_type']);
     $node_type->save();
     $this->container->get('content_translation.manager')->setEnabled('node', 'example_type', TRUE);
     $user = User::create(['name' => $this->randomMachineName()]);
     $user->save();
     $node = Node::create(['title' => $this->randomMachineName(), 'uid' => $user->id(), 'type' => $node_type->id(), 'status' => NODE_PUBLISHED, 'langcode' => 'en', 'promote' => 1, 'sticky' => 0, 'body' => ['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()], 'revision_log' => $this->randomString()]);
     $node->addTranslation('de', ['title' => 'German title', 'body' => ['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()]]);
     $node->save();
     $original_values = $node->toArray();
     $translation = $node->getTranslation('de');
     $original_translation_values = $node->getTranslation('en')->toArray();
     $normalized = $this->serializer->normalize($node, $this->format);
     $this->assertContains(['lang' => 'en', 'value' => $node->getTitle()], $normalized['title'], 'Original language title has been normalized.');
     $this->assertContains(['lang' => 'de', 'value' => $translation->getTitle()], $normalized['title'], 'Translation language title has been normalized.');
     /** @var \Drupal\node\NodeInterface $denormalized_node */
     $denormalized_node = $this->serializer->denormalize($normalized, 'Drupal\\node\\Entity\\Node', $this->format);
     $this->assertSame($denormalized_node->language()->getId(), $denormalized_node->getUntranslated()->language()->getId(), 'Untranslated object is returned from serializer.');
     $this->assertSame('en', $denormalized_node->language()->getId());
     $this->assertTrue($denormalized_node->hasTranslation('de'));
     $this->assertSame($node->getTitle(), $denormalized_node->getTitle());
     $this->assertSame($translation->getTitle(), $denormalized_node->getTranslation('de')->getTitle());
     $this->assertEquals($original_values, $denormalized_node->toArray(), 'Node values are restored after normalizing and denormalizing.');
     $this->assertEquals($original_translation_values, $denormalized_node->getTranslation('en')->toArray(), 'Node values are restored after normalizing and denormalizing.');
 }
示例#5
0
 /**
  * Tests the normalization of comments.
  */
 public function testComment()
 {
     $node_type = NodeType::create(['type' => 'example_type']);
     $node_type->save();
     $account = User::create(['name' => $this->randomMachineName()]);
     $account->save();
     // Add comment type.
     $this->container->get('entity.manager')->getStorage('comment_type')->create(array('id' => 'comment', 'label' => 'comment', 'target_entity_type_id' => 'node'))->save();
     $this->addDefaultCommentField('node', 'example_type');
     $node = Node::create(['title' => $this->randomMachineName(), 'uid' => $account->id(), 'type' => $node_type->id(), 'status' => NODE_PUBLISHED, 'promote' => 1, 'sticky' => 0, 'body' => [['value' => $this->randomMachineName(), 'format' => $this->randomMachineName()]]]);
     $node->save();
     $parent_comment = Comment::create(array('uid' => $account->id(), 'subject' => $this->randomMachineName(), 'comment_body' => ['value' => $this->randomMachineName(), 'format' => NULL], 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment'));
     $parent_comment->save();
     $comment = Comment::create(array('uid' => $account->id(), 'subject' => $this->randomMachineName(), 'comment_body' => ['value' => $this->randomMachineName(), 'format' => NULL], 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => $parent_comment->id(), 'mail' => '*****@*****.**', 'homepage' => 'http://buytaert.net'));
     $comment->save();
     $original_values = $comment->toArray();
     // Hostname will always be denied view access.
     // No value will exist for name as this is only for anonymous users.
     unset($original_values['hostname'], $original_values['name']);
     $normalized = $this->serializer->normalize($comment, $this->format, ['account' => $account]);
     // Assert that the hostname field does not appear at all in the normalized
     // data.
     $this->assertFalse(array_key_exists('hostname', $normalized), 'Hostname was not found in normalized comment data.');
     /** @var \Drupal\comment\CommentInterface $denormalized_comment */
     $denormalized_comment = $this->serializer->denormalize($normalized, 'Drupal\\comment\\Entity\\Comment', $this->format, ['account' => $account]);
     // Before comparing, unset values that are expected to differ.
     $denormalized_comment_values = $denormalized_comment->toArray();
     unset($denormalized_comment_values['hostname'], $denormalized_comment_values['name']);
     $this->assertEqual($original_values, $denormalized_comment_values, 'The expected comment values are restored after normalizing and denormalizing.');
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', 'sequences');
     $this->installEntitySchema('user');
     $this->manager = $this->container->get('plugin.manager.condition');
     // Set up the authenticated and anonymous roles.
     Role::create(array('id' => RoleInterface::ANONYMOUS_ID, 'label' => 'Anonymous user'))->save();
     Role::create(array('id' => RoleInterface::AUTHENTICATED_ID, 'label' => 'Authenticated user'))->save();
     // Create new role.
     $rid = strtolower($this->randomMachineName(8));
     $label = $this->randomString(8);
     $role = Role::create(array('id' => $rid, 'label' => $label));
     $role->save();
     $this->role = $role;
     // Setup an anonymous user for our tests.
     $this->anonymous = User::create(array('name' => '', 'uid' => 0));
     $this->anonymous->save();
     // Loading the anonymous user adds the correct role.
     $this->anonymous = User::load($this->anonymous->id());
     // Setup an authenticated user for our tests.
     $this->authenticated = User::create(array('name' => $this->randomMachineName()));
     $this->authenticated->save();
     // Add the custom role.
     $this->authenticated->addRole($this->role->id());
 }
示例#7
0
 /**
  * Tests removal of role references on role entity delete.
  *
  * @see user_user_role_delete()
  */
 public function testRoleDeleteUserRoleReferenceDelete()
 {
     // Create two test roles.
     $role_storage = $this->container->get('entity.manager')->getStorage('user_role');
     $role_storage->create(array('id' => 'test_role_one'))->save();
     $role_storage->create(array('id' => 'test_role_two'))->save();
     // Create user and assign both test roles.
     $values = array('uid' => 1, 'name' => $this->randomString(), 'roles' => array('test_role_one', 'test_role_two'));
     $user = User::create($values);
     $user->save();
     // Check that user has both roles.
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     // Delete test role one.
     $test_role_one = $role_storage->load('test_role_one');
     $test_role_one->delete();
     // Load user again from the database.
     $user = User::load($user->id());
     // Check that user does not have role one anymore, still has role two.
     $this->assertFalse($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     // Create new role with same name.
     $role_storage->create(array('id' => 'test_role_one'))->save();
     // Load user again from the database.
     $user = User::load($user->id());
     // Check that user does not have role one.
     $this->assertFalse($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
 }
示例#8
0
 /**
  * Create a user with a given set of permissions.
  *
  * @param array $permissions
  *   Array of permission names to assign to user. Note that the user always
  *   has the default permissions derived from the "authenticated users" role.
  * @param string $name
  *   The user name.
  * @param bool $admin
  *   (optional) Whether the user should be an administrator
  *   with all the available permissions.
  *
  * @return \Drupal\user\Entity\User|false
  *   A fully loaded user object with pass_raw property, or FALSE if account
  *   creation fails.
  */
 protected function createUser(array $permissions = array(), $name = NULL, $admin = FALSE)
 {
     // Create a role with the given permission set, if any.
     $rid = FALSE;
     if ($permissions) {
         $rid = $this->createRole($permissions);
         if (!$rid) {
             return FALSE;
         }
     }
     // Create a user assigned to that role.
     $edit = array();
     $edit['name'] = !empty($name) ? $name : $this->randomMachineName();
     $edit['mail'] = $edit['name'] . '@example.com';
     $edit['pass'] = user_password();
     $edit['status'] = 1;
     if ($rid) {
         $edit['roles'] = array($rid);
     }
     if ($admin) {
         $edit['roles'][] = $this->createAdminRole();
     }
     $account = User::create($edit);
     $account->save();
     $this->assertTrue($account->id(), SafeMarkup::format('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), 'User login');
     if (!$account->id()) {
         return FALSE;
     }
     // Add the raw password so that we can log in as this user.
     $account->pass_raw = $edit['pass'];
     return $account;
 }
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Llama" user.
     $user = User::create(['name' => 'Llama', 'status' => TRUE]);
     $user->save();
     return $user;
 }
 /**
  * Tests exportContentWithReferences().
  */
 public function testExportWithReferences()
 {
     \Drupal::service('module_installer')->install(['node', 'default_content']);
     \Drupal::service('router.builder')->rebuild();
     $this->defaultContentManager = \Drupal::service('default_content.manager');
     $user = User::create(['name' => 'my username']);
     $user->save();
     // Reload the user to get the proper casted values from the DB.
     $user = User::load($user->id());
     $node_type = NodeType::create(['type' => 'test']);
     $node_type->save();
     $node = Node::create(['type' => $node_type->id(), 'title' => 'test node', 'uid' => $user->id()]);
     $node->save();
     // Reload the node to get the proper casted values from the DB.
     $node = Node::load($node->id());
     /** @var \Symfony\Component\Serializer\Serializer $serializer */
     $serializer = \Drupal::service('serializer');
     \Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
     $expected_node = $serializer->serialize($node, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $expected_user = $serializer->serialize($user, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $exported_by_entity_type = $this->defaultContentManager->exportContentWithReferences('node', $node->id());
     // Ensure that the node type is not tryed to be exported.
     $this->assertEqual(array_keys($exported_by_entity_type), ['node', 'user']);
     // Ensure the right UUIDs are exported.
     $this->assertEqual([$node->uuid()], array_keys($exported_by_entity_type['node']));
     $this->assertEqual([$user->uuid()], array_keys($exported_by_entity_type['user']));
     // Compare the actual serialized data.
     $this->assertEqual(reset($exported_by_entity_type['node']), $expected_node);
     $this->assertEqual(reset($exported_by_entity_type['user']), $expected_user);
 }
示例#11
0
 /**
  * {@inheritdoc}
  */
 protected function setUp($import_test_views = TRUE)
 {
     parent::setUp($import_test_views);
     $this->installEntitySchema('user');
     $this->installEntitySchema('comment');
     // Create the anonymous role.
     $this->installConfig(['user']);
     // Create an anonymous user.
     $storage = \Drupal::entityManager()->getStorage('user');
     // Insert a row for the anonymous user.
     $storage->create(array('uid' => 0, 'name' => '', 'status' => 0))->save();
     $admin_role = Role::create(['id' => 'admin', 'permissions' => ['administer comments', 'access user profiles']]);
     $admin_role->save();
     /* @var \Drupal\user\RoleInterface $anonymous_role */
     $anonymous_role = Role::load(Role::ANONYMOUS_ID);
     $anonymous_role->grantPermission('access comments');
     $anonymous_role->save();
     $this->adminUser = User::create(['name' => $this->randomMachineName(), 'roles' => [$admin_role->id()]]);
     $this->adminUser->save();
     // Create some comments.
     $comment = Comment::create(['subject' => 'My comment title', 'uid' => $this->adminUser->id(), 'name' => $this->adminUser->label(), 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'status' => 1]);
     $comment->save();
     $comment_anonymous = Comment::create(['subject' => 'Anonymous comment title', 'uid' => 0, 'name' => 'barry', 'mail' => '*****@*****.**', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'created' => 123456, 'status' => 1]);
     $comment_anonymous->save();
 }
示例#12
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $config = $this->config('system.theme');
     $config->set('default', 'bartik');
     $config->set('admin', 'seven');
     $config->save();
     foreach (static::$modules as $module) {
         $function = $module . '_schema';
         module_load_install($module);
         if (function_exists($function)) {
             $schema = $function();
             $this->installSchema($module, array_keys($schema));
         }
     }
     $this->installEntitySchema('aggregator_feed');
     $this->installEntitySchema('aggregator_item');
     $this->installEntitySchema('block_content');
     $this->installEntitySchema('comment');
     $this->installEntitySchema('file');
     $this->installEntitySchema('node');
     $this->installEntitySchema('menu_link_content');
     $this->installEntitySchema('taxonomy_term');
     $this->installEntitySchema('user');
     $this->installConfig(['block_content', 'comment', 'file', 'node', 'simpletest']);
     // Install one of D8's test themes.
     \Drupal::service('theme_handler')->install(array('test_theme'));
     // Create a new user which needs to have UID 1, because that is expected by
     // the assertions from
     // \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
     User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
     $this->installMigrations('Drupal 6');
 }
 public function testRevisionView()
 {
     $entity = EnhancedEntity::create(['name' => 'rev 1', 'type' => 'default']);
     $entity->save();
     $revision = clone $entity;
     $revision->name->value = 'rev 2';
     $revision->setNewRevision(TRUE);
     $revision->isDefaultRevision(FALSE);
     $revision->save();
     /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
     $http_kernel = \Drupal::service('http_kernel');
     $request = Request::create($revision->url('revision'));
     $response = $http_kernel->handle($request);
     $this->assertEquals(403, $response->getStatusCode());
     $role = Role::create(['id' => 'test_role']);
     $role->grantPermission('view all entity_test_enhanced revisions');
     $role->grantPermission('administer entity_test_enhanced');
     $role->save();
     $user = User::create(['name' => 'Test user']);
     $user->addRole($role->id());
     \Drupal::service('account_switcher')->switchTo($user);
     $request = Request::create($revision->url('revision'));
     $response = $http_kernel->handle($request);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertNotContains('rev 1', $response->getContent());
     $this->assertContains('rev 2', $response->getContent());
 }
 /**
  * Tests tabs in profile UI.
  */
 public function testProfileTabs()
 {
     $types_data = ['profile_type_0' => ['label' => $this->randomMachineName()], 'profile_type_1' => ['label' => $this->randomMachineName()]];
     /** @var ProfileType[] $types */
     $types = [];
     foreach ($types_data as $id => $values) {
         $types[$id] = ProfileType::create(['id' => $id] + $values);
         $types[$id]->save();
     }
     $this->container->get('router.builder')->rebuild();
     $this->user1 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
     $this->user1->save();
     $this->user2 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
     $this->user2->save();
     // Create new profiles.
     $profile1 = Profile::create($expected = ['type' => $types['profile_type_0']->id(), 'uid' => $this->user1->id()]);
     $profile1->save();
     $profile2 = Profile::create($expected = ['type' => $types['profile_type_1']->id(), 'uid' => $this->user2->id()]);
     $profile2->save();
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('admin/config');
     $this->clickLink('User profiles');
     $this->assertResponse(200);
     $this->assertUrl('admin/config/people/profiles');
     $this->assertLink($profile1->label());
     $this->assertLinkByHref($profile2->toUrl('canonical')->toString());
     $tasks = [['entity.profile.collection', []], ['entity.profile_type.collection', []]];
     $this->assertLocalTasks($tasks, 0);
 }
示例#15
0
 public function testUserHooks()
 {
     FieldStorageConfig::create(array('field_name' => 'field_text', 'type' => 'string', 'entity_type' => 'user'))->save();
     FieldConfig::create(array('field_name' => 'field_text', 'type' => 'string', 'entity_type' => 'user', 'bundle' => 'user'))->save();
     $this->assertIdentical('', \Drupal::config('name.settings')->get('user_preferred'));
     FieldStorageConfig::create(array('field_name' => 'field_name_test', 'type' => 'name', 'entity_type' => 'user'))->save();
     FieldStorageConfig::create(array('field_name' => 'field_name_test2', 'type' => 'name', 'entity_type' => 'user'))->save();
     $field = FieldConfig::create(array('field_name' => 'field_name_test', 'type' => 'name', 'entity_type' => 'user', 'bundle' => 'user'));
     $field->save();
     $field2 = FieldConfig::create(array('field_name' => 'field_name_test2', 'type' => 'name', 'entity_type' => 'user', 'bundle' => 'user'));
     $field2->save();
     $this->assertEqual($field->getName(), \Drupal::config('name.settings')->get('user_preferred'));
     \Drupal::configFactory()->getEditable('name.settings')->set('user_preferred', $field2->getName())->save();
     $field2->delete();
     $this->assertEqual('', \Drupal::config('name.settings')->get('user_preferred'));
     \Drupal::configFactory()->getEditable('name.settings')->set('user_preferred', $field->getName())->save();
     $account = User::create(array('name' => 'test'));
     $account->field_name_test[0] = array('given' => 'Max', 'family' => 'Mustermann');
     $account->save();
     $account = User::load($account->id());
     $this->assertEqual('Max Mustermann', $account->realname);
     $this->assertEqual('Max Mustermann', user_format_name($account));
     $this->assertEqual('test', $account->getUsername());
     $this->assertEqual('Max Mustermann', $account->getDisplayName());
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installConfig(['node']);
     $this->installSchema('node', ['node_access']);
     $this->installSchema('system', ['sequences']);
     // Create a new user which needs to have UID 1, because that is expected by
     // the assertions from
     // \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
     User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
     $node_type = entity_create('node_type', array('type' => 'test_planet'));
     $node_type->save();
     node_add_body_field($node_type);
     $node_type = entity_create('node_type', array('type' => 'story'));
     $node_type->save();
     node_add_body_field($node_type);
     $id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))), 'd6_user' => array(array(array(1), array(1)), array(array(2), array(2))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))));
     $this->prepareMigrations($id_mappings);
     $migration = entity_load('migration', 'd6_node_settings');
     $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
     // Create a test node.
     $node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
     $node = entity_create('node', array('type' => 'test_planet', 'nid' => 3, 'vid' => 4, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
 }
 /**
  * Create a test user based on a role.
  *
  * @param string $role
  *
  * @return $this
  */
 public function createTestUser($role = 'administrator')
 {
     if ($role != 'anonymous' && !$this->userExists($role)) {
         $this->output->writeln("creating test{$role}User...");
         User::create(['name' => "test{$role}User", 'mail' => "test{$role}User@example.com", 'roles' => [$role], 'pass' => $this->config['test_user_pass'], 'status' => 1])->save();
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', 'sequences');
     $this->installEntitySchema('user');
     $this->anonymous = User::create(['uid' => 0]);
     $this->authenticated = User::create(['uid' => 1]);
 }
示例#19
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', ['key_value_expire', 'sequences']);
     $this->installEntitySchema('user');
     $test_user = User::create(['name' => 'foobar', 'mail' => '*****@*****.**']);
     $test_user->save();
     \Drupal::service('current_user')->setAccount($test_user);
 }
示例#20
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->adminUser = $this->drupalCreateUser(['access user profiles', 'administer profiles', 'administer profile types', 'bypass profile access', 'access administration pages']);
     $this->user1 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
     $this->user1->save();
     $this->user2 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
     $this->user2->save();
 }
 /**
  * Tests account's available fields.
  */
 function testUserFields()
 {
     // Create the user to test the user fields.
     $user = User::create(['name' => 'foobar', 'mail' => '*****@*****.**']);
     $build = user_view($user);
     $output = \Drupal::service('renderer')->renderRoot($build);
     $this->setRawContent($output);
     $userEmail = $user->getEmail();
     $this->assertText($userEmail, "User's mail field is found in the twig template");
 }
示例#22
0
 /**
  * Ensures that an existing password is unset after the user was saved.
  */
 function testExistingPasswordRemoval()
 {
     /** @var \Drupal\user\Entity\User $user */
     $user = User::create(['name' => $this->randomMachineName()]);
     $user->save();
     $user->setExistingPassword('existing password');
     $this->assertNotNull($user->pass->existing);
     $user->save();
     $this->assertNull($user->pass->existing);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', ['key_value_expire', 'sequences']);
     $this->installEntitySchema('user');
     $this->queue = \Drupal::service('queue.database')->get('aggregator_refresh');
     $test_user = User::create(array('name' => 'foobar', 'mail' => '*****@*****.**'));
     $test_user->save();
     \Drupal::service('current_user')->setAccount($test_user);
 }
示例#24
0
 /**
  * Tests the formatter output.
  */
 public function testFormatter()
 {
     $user = User::create(['name' => 'test name']);
     $user->save();
     $result = $user->{$this->fieldName}->view(['type' => 'user_name']);
     $this->assertEqual('username', $result[0]['#theme']);
     $this->assertEqual(spl_object_hash($user), spl_object_hash($result[0]['#account']));
     $result = $user->{$this->fieldName}->view(['type' => 'user_name', 'settings' => ['link_to_entity' => FALSE]]);
     $this->assertEqual($user->getUsername(), $result[0]['#markup']);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installSchema('system', 'sequences');
     $devel_role = Role::create(['id' => 'admin', 'permissions' => ['access devel information']]);
     $devel_role->save();
     $this->develUser = User::create(['name' => $this->randomMachineName(), 'roles' => [$devel_role->id()]]);
     $this->develUser->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUpFixtures()
 {
     $this->installEntitySchema('user');
     $this->installConfig(array('user'));
     parent::setUpFixtures();
     // Create a record for uid 1.
     $this->rootUser = User::create(['name' => $this->randomMachineName()]);
     $this->rootUser->save();
     Views::viewsData()->clear();
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('file');
     $this->installSchema('file', 'file_usage');
     $this->installSchema('system', 'sequences');
     $this->user = User::create(['name' => 'username', 'status' => 1]);
     $this->user->save();
 }
示例#28
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Create a field on the user entity so that we can test nested property
     // overwrites.
     // @see static::testOverwriteSelectedNestedProperty()
     FieldStorageConfig::create(['field_name' => 'signature', 'entity_type' => 'user', 'type' => 'text_long'])->save();
     FieldConfig::create(['field_name' => 'signature', 'entity_type' => 'user', 'bundle' => 'user'])->save();
     User::create(['uid' => 2, 'name' => 'Ford Prefect', 'mail' => 'ford.prefect@localhost', 'signature' => array(array('value' => 'Bring a towel.', 'format' => 'filtered_html')), 'init' => '*****@*****.**'])->save();
     $this->executeMigrations(['d6_filter_format', 'd6_user_role']);
 }
示例#29
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     $this->installEntitySchema('entity_test_enhanced');
     $this->installSchema('system', ['key_value_expire', 'sequences']);
     $bundle = EnhancedEntityBundle::create(['id' => 'default', 'label' => 'Default']);
     $bundle->save();
     $this->user = User::create(['name' => 'username', 'status' => 1]);
     $this->user->save();
     \Drupal::service('current_user')->setAccount($this->user);
 }
 /**
  * @return \Drupal\user\UserInterface
  */
 protected function drupalCreateUser(array $permissions = [])
 {
     $role = Role::create(['id' => 'test_role__' . $this->randomMachineName()]);
     foreach ($permissions as $permission) {
         $role->grantPermission($permission);
     }
     $role->save();
     $user = User::create(['name' => 'test name  ' . $this->randomMachineName()]);
     $user->addRole($role->id());
     $user->save();
     return $user;
 }