protected function setUp() { parent::setUp(); // Enable anonymous and authenticated user comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access comments', 'post comments', 'skip comment approval')); user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access comments', 'post comments', 'skip comment approval')); }
/** * Test user registration integration. */ public function testUserRegisterForm() { $id = $this->type->id(); $field_name = $this->field->getName(); $this->field->setRequired(TRUE); $this->field->save(); // Allow registration without administrative approval and log in user // directly after registering. \Drupal::configFactory()->getEditable('user.settings')->set('register', USER_REGISTER_VISITORS)->set('verify_mail', 0)->save(); user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['view own test profile']); // Verify that the additional profile field is attached and required. $name = $this->randomMachineName(); $pass_raw = $this->randomMachineName(); $edit = ['name' => $name, 'mail' => $this->randomMachineName() . '@example.com', 'pass[pass1]' => $pass_raw, 'pass[pass2]' => $pass_raw]; $this->drupalPostForm('user/register', $edit, t('Create new account')); $this->assertRaw(new FormattableMarkup('@name field is required.', ['@name' => $this->field->getLabel()])); // Verify that we can register. $edit["entity_" . $id . "[{$field_name}][0][value]"] = $this->randomMachineName(); $this->drupalPostForm(NULL, $edit, t('Create new account')); $this->assertText(new FormattableMarkup('Registration successful. You are now logged in.', [])); $new_user = user_load_by_name($name); $this->assertTrue($new_user->isActive(), 'New account is active after registration.'); // Verify that a new profile was created for the new user ID. $profile = \Drupal::entityTypeManager()->getStorage('profile')->loadByUser($new_user, $this->type->id()); $this->assertEqual($profile->get($field_name)->value, $edit["entity_" . $id . "[{$field_name}][0][value]"], 'Field value found in loaded profile.'); // Verify that the profile field value appears on the user account page. $this->drupalGet('user'); $this->assertText($edit["entity_" . $id . "[{$field_name}][0][value]"], 'Field value found on user account page.'); }
/** * Test comment field name. */ public function testCommentFieldName() { /** @var \Drupal\Core\Render\RendererInterface $renderer */ $renderer = \Drupal::service('renderer'); $view = Views::getView('test_comment_field_name'); $this->executeView($view); $expected_result = [['cid' => $this->comment->id(), 'field_name' => $this->comment->getFieldName()], ['cid' => $this->customComment->id(), 'field_name' => $this->customComment->getFieldName()]]; $column_map = ['cid' => 'cid', 'comment_field_data_field_name' => 'field_name']; $this->assertIdenticalResultset($view, $expected_result, $column_map); // Test that no data can be rendered. $this->assertIdentical(FALSE, isset($view->field['field_name'])); // Grant permission to properly check view access on render. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); $this->container->get('account_switcher')->switchTo(new AnonymousUserSession()); $view = Views::getView('test_comment_field_name'); $this->executeView($view); // Test that data rendered. $output = $renderer->executeInRenderContext(new RenderContext(), function () use($view) { return $view->field['field_name']->advancedRender($view->result[0]); }); $this->assertIdentical($this->comment->getFieldName(), $output); $output = $renderer->executeInRenderContext(new RenderContext(), function () use($view) { return $view->field['field_name']->advancedRender($view->result[1]); }); $this->assertIdentical($this->customComment->getFieldName(), $output); }
function setUp() { parent::setUp(); // Enable anonymous and authenticated user comments. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments', 'post comments', 'skip comment approval')); user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access comments', 'post comments', 'skip comment approval')); }
/** * Tests that configuration changes also clear the page cache. */ public function testConfigChangePageCache() { $this->enableService('entity:entity_test', 'GET'); // Allow anonymous users to issue GET requests. $permissions = $this->entityPermissions('entity_test', 'view'); $permissions[] = 'restful get entity:entity_test'; user_role_grant_permissions('anonymous', $permissions); // Create an entity programmatically. $entity = $this->entityCreate('entity_test'); $entity->set('field_test_text', 'custom cache tag value'); $entity->save(); // Read it over the REST API. $this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET', NULL, $this->defaultMimeType); $this->assertResponse(200, 'HTTP response code is correct.'); $this->assertHeader('x-drupal-cache', 'MISS'); $this->assertCacheTag('config:rest.settings'); $this->assertCacheTag('entity_test:1'); $this->assertCacheTag('entity_test_access:field_test_text'); // Read it again, should be page-cached now. $this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET', NULL, $this->defaultMimeType); $this->assertResponse(200, 'HTTP response code is correct.'); $this->assertHeader('x-drupal-cache', 'HIT'); $this->assertCacheTag('config:rest.settings'); $this->assertCacheTag('entity_test:1'); $this->assertCacheTag('entity_test_access:field_test_text'); // Trigger a config save which should clear the page cache, so we should get // a cache miss now for the same request. $this->config('rest.settings')->save(); $this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET', NULL, $this->defaultMimeType); $this->assertResponse(200, 'HTTP response code is correct.'); $this->assertHeader('x-drupal-cache', 'MISS'); $this->assertCacheTag('config:rest.settings'); $this->assertCacheTag('entity_test:1'); $this->assertCacheTag('entity_test_access:field_test_text'); }
/** * Set some test data for permission related tests. */ protected function setupPermissionTestData() { // Setup a role without any permission. $this->roleStorage->create(array('id' => 'authenticated'))->save(); $this->roleStorage->create(array('id' => 'no_permission'))->save(); // Setup a role with just one permission. $this->roleStorage->create(array('id' => 'one_permission'))->save(); user_role_grant_permissions('one_permission', array('administer permissions')); // Setup a role with multiple permissions. $this->roleStorage->create(array('id' => 'multiple_permissions'))->save(); user_role_grant_permissions('multiple_permissions', array('administer permissions', 'administer users', 'access user profiles')); // Setup a user without an extra role. $this->users[] = $account = $this->userStorage->create(['name' => $this->randomString()]); $account->save(); // Setup a user with just the first role (so no permission beside the // ones from the authenticated role). $this->users[] = $account = $this->userStorage->create(array('name' => 'first_role')); $account->addRole('no_permission'); $account->save(); // Setup a user with just the second role (so one additional permission). $this->users[] = $account = $this->userStorage->create(array('name' => 'second_role')); $account->addRole('one_permission'); $account->save(); // Setup a user with both the second and the third role. $this->users[] = $account = $this->userStorage->create(array('name' => 'second_third_role')); $account->addRole('one_permission'); $account->addRole('multiple_permissions'); $account->save(); }
protected function setUp() { parent::setUp(); // Enable user signatures. \Drupal::config('user.settings')->set('signatures', 1)->save(); // Create Basic page node type. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); // Add a comment field with commenting enabled by default. $this->container->get('comment.manager')->addDefaultField('node', 'page'); // Prefetch and create text formats. $this->filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html_format', 'name' => 'Filtered HTML', 'weight' => -1, 'filters' => array('filter_html' => array('module' => 'filter', 'status' => TRUE, 'settings' => array('allowed_html' => '<a> <em> <strong>'))))); $this->filtered_html_format->save(); $this->full_html_format = entity_create('filter_format', array('format' => 'full_html', 'name' => 'Full HTML')); $this->full_html_format->save(); user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filtered_html_format->getPermissionName())); // Create regular and administrative users. $this->web_user = $this->drupalCreateUser(array('post comments')); $admin_permissions = array('post comments', 'administer comments', 'administer user form display', 'administer account settings'); foreach (filter_formats() as $format) { if ($permission = $format->getPermissionName()) { $admin_permissions[] = $permission; } } $this->admin_user = $this->drupalCreateUser($admin_permissions); }
public function testInactiveDomain() { // Create three new domains programmatically. $this->domainCreateTestDomains(3); $domains = \Drupal::service('domain.loader')->loadMultiple(); // Grab the last domain for testing. $domain = end($domains); $this->drupalGet($domain->getPath()); $this->assertTrue($domain->status(), 'Tested domain is set to active.'); $this->assertTrue($domain->getPath() == $this->getUrl(), 'Loaded the active domain.'); // Disable the domain and test for redirect. $domain->disable(); $default = \Drupal::service('domain.loader')->loadDefaultDomain(); // Must flush cache. drupal_flush_all_caches(); $this->drupalGet($domain->getPath()); $this->assertFalse($domain->status(), 'Tested domain is set to inactive.'); $this->assertTrue($default->getPath() == $this->getUrl(), 'Redirected an inactive domain to the default domain.'); // Try to access with the proper permission. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access inactive domains')); $this->assertFalse($domain->status(), 'Tested domain is set to inactive.'); // Must flush cache. drupal_flush_all_caches(); $this->drupalGet($domain->getPath()); $this->assertTrue($domain->getPath() == $this->getUrl(), 'Loaded the inactive domain with permission.'); }
/** * Tests configuration options and the site-wide contact form. */ public function testContactStorage() { // Create and login administrative user. $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields')); $this->drupalLogin($admin_user); // Create first valid contact form. $mail = '*****@*****.**'; $this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($mail)), '', TRUE, ['send_a_pony' => 1]); $this->assertRaw(t('Contact form %label has been added.', array('%label' => $label))); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); $this->assertNoText(t('Form')); $this->submitContact($name = $this->randomMachineName(16), $mail, $subject = $this->randomMachineName(16), $id, $message = $this->randomMachineName(64)); $this->assertText(t('Your message has been sent.')); $messages = Message::loadMultiple(); /** @var \Drupal\contact\Entity\Message $message */ $message = reset($messages); $this->assertEqual($message->getContactForm()->id(), $id); $this->assertTrue($message->getContactForm()->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE)); $this->assertEqual($message->getSenderName(), $name); $this->assertEqual($message->getSubject(), $subject); $this->assertEqual($message->getSenderMail(), $mail); $config = $this->config("contact.form.{$id}"); $this->assertEqual($config->get('id'), $id); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('local_tasks_block'); $this->drupalPlaceBlock('local_actions_block'); $this->drupalPlaceBlock('page_title_block'); $this->type = $this->createProfileType('test', 'Test profile', TRUE); $id = $this->type->id(); $field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']); $field_storage->save(); $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']); $this->field->save(); // Configure the default display. $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default"); if (!$this->display) { $this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]); $this->display->save(); } $this->display->setComponent($this->field->getName(), ['type' => 'string'])->save(); // Configure rhe default form. $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default"); if (!$this->form) { $this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]); $this->form->save(); } $this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save(); $this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]); user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']); $this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]); }
/** * Tests configuration options and the site-wide contact form. */ public function testContactStorage() { // Create and login administrative user. $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields')); $this->drupalLogin($admin_user); // Create first valid category. $mail = '*****@*****.**'; $this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($mail)), '', TRUE); $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); $this->assertNoText(t('Category')); $this->submitContact($name = $this->randomName(16), $mail, $subject = $this->randomName(16), $id, $message = $this->randomName(64)); $this->assertText(t('Your message has been sent.')); $messages = Message::loadMultiple(); /** @var \Drupal\contact\Entity\Message $message */ $message = reset($messages); $this->assertEqual($message->getCategory()->id(), $id); $this->assertEqual($message->getSenderName(), $name); $this->assertEqual($message->getSubject(), $subject); $this->assertEqual($message->getSenderMail(), $mail); }
function setUp() { parent::setUp(); // Create an administrative user. $this->admin_user = $this->drupalCreateUser(array('administer site configuration')); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access user profiles')); user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access user profiles')); }
protected function setUp() { parent::setUp(); // Create an administrative user. $this->adminUser = $this->drupalCreateUser(array('administer site configuration', 'link to any page')); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access user profiles')); user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access user profiles')); }
protected function setUp() { parent::setUp(); $filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html', 'name' => 'Filtered HTML')); $filtered_html_format->save(); $filtered_html_permission = $filtered_html_format->getPermissionName(); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array($filtered_html_permission)); }
protected function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); $this->user = $this->drupalCreateUser($permissions); $this->otherUser = $this->drupalCreateUser($permissions); $this->addDefaultCommentField('node', 'page'); user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('access content', 'access user profiles')); }
protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('page_title_block'); // Create an administrative user. $this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer site configuration', 'link to any page', 'administer blocks']); $this->adminUser->roles[] = 'administrator'; $this->adminUser->save(); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access user profiles')); user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access user profiles')); }
protected function setUp() { parent::setUp(); // Create Basic page node type. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); /** @var \Drupal\filter\Entity\FilterFormat $filtered_html_format */ $filtered_html_format = entity_load('filter_format', 'filtered_html'); $filtered_html_permission = $filtered_html_format->getPermissionName(); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array($filtered_html_permission)); $this->adminUser = $this->drupalCreateUser(array('administer modules', 'administer filters', 'administer site configuration')); $this->drupalLogin($this->adminUser); }
/** * Creates a user. * * @param array $values * (optional) The values used to create the entity. * @param array $permissions * (optional) Array of permission names to assign to user. The * users_roles tables must be installed before this can be used. * * @return \Drupal\user\Entity\User * The created user entity. */ protected function createUser($values = array(), $permissions = array()) { if ($permissions) { // Create a new role and apply permissions to it. $role = entity_create('user_role', array('id' => strtolower($this->randomName(8)), 'label' => $this->randomName(8))); $role->save(); user_role_grant_permissions($role->id(), $permissions); $values['roles'][] = $role->id(); } $account = entity_create('user', $values + array('name' => $this->randomName(), 'status' => 1)); $account->enforceIsNew(); $account->save(); return $account; }
/** * Tests contact messages submitted through contact form. */ public function testContactStorage() { // Create and login administrative user. $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields')); $this->drupalLogin($admin_user); // Create first valid contact form. $mail = '*****@*****.**'; $this->addContactForm('test_id', 'test_label', $mail, '', TRUE); $this->assertText(t('Contact form test_label has been added.')); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); $this->assertNoText(t('Form')); $this->submitContact('Test_name', $mail, 'Test_subject', 'test_id', 'Test_message'); $this->assertText(t('Your message has been sent.')); // Login as admin,check the message list overview. $this->drupalLogin($admin_user); $this->drupalGet('admin/structure/contact/messages'); $rows = $this->xpath('//tbody/tr'); // Make sure only 1 message is available. $this->assertEqual(count($rows), 1); // Some fields should be present. $this->assertText('Test_subject'); $this->assertText('Test_name'); $this->assertText('test_label'); // Make sure the stored message is correct. $this->clickLink(t('Edit')); $this->assertFieldById('edit-name', 'Test_name'); $this->assertFieldById('edit-mail', $mail); $this->assertFieldById('edit-subject-0-value', 'Test_subject'); $this->assertFieldById('edit-message-0-value', 'Test_message'); // Submit should redirect back to listing. $this->drupalPostForm(NULL, array(), t('Save')); $this->assertUrl('admin/structure/contact/messages'); // Delete the message. $this->clickLink(t('Delete')); $this->drupalPostForm(NULL, NULL, t('Delete')); $this->assertText('Deleted contact message Test_subject.'); // Make sure no messages are available. $this->assertText('There is no Contact message yet.'); // Fill the redirect field and assert the page is successfully redirected. $edit = ['contact_storage_uri' => 'entity:user/' . $admin_user->id()]; $this->drupalPostForm('admin/structure/contact/manage/test_id', $edit, t('Save')); $edit = ['subject[0][value]' => 'Test subject', 'message[0][value]' => 'Test message']; $this->drupalPostForm('contact', $edit, t('Send message')); $this->assertText('Your message has been sent.'); $this->assertEqual($this->url, $admin_user->urlInfo()->setAbsolute()->toString()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); // Set up the filter formats used by this test. $basic_html_format = entity_create('filter_format', array('format' => 'basic_html', 'name' => 'Basic HTML', 'filters' => array('filter_html' => array('status' => 1, 'settings' => array('allowed_html' => '<p> <br> <strong> <a> <em>'))))); $basic_html_format->save(); $restricted_html_format = entity_create('filter_format', array('format' => 'restricted_html', 'name' => 'Restricted HTML', 'filters' => array('filter_html' => array('status' => TRUE, 'weight' => -10, 'settings' => array('allowed_html' => '<p> <br> <strong> <a> <em> <h4>')), 'filter_autop' => array('status' => TRUE, 'weight' => 0), 'filter_url' => array('status' => TRUE, 'weight' => 0), 'filter_htmlcorrector' => array('status' => TRUE, 'weight' => 10)))); $restricted_html_format->save(); $full_html_format = entity_create('filter_format', array('format' => 'full_html', 'name' => 'Full HTML', 'weight' => 1, 'filters' => array())); $full_html_format->save(); $this->adminUser = $this->drupalCreateUser(array('administer filters', $basic_html_format->getPermissionName(), $restricted_html_format->getPermissionName(), $full_html_format->getPermissionName())); $this->webUser = $this->drupalCreateUser(array('create page content', 'edit own page content')); user_role_grant_permissions('authenticated', array($basic_html_format->getPermissionName())); user_role_grant_permissions('anonymous', array($restricted_html_format->getPermissionName())); $this->drupalLogin($this->adminUser); }
/** * Tests the recent comments block. */ function testRecentCommentBlock() { $this->drupalLogin($this->adminUser); $block = $this->drupalPlaceBlock('views_block:comments_recent-block_1'); // Add some test comments, with and without subjects. Because the 10 newest // comments should be shown by the block, we create 11 to test that behavior // below. $timestamp = REQUEST_TIME; for ($i = 0; $i < 11; ++$i) { $subject = $i % 2 ? $this->randomMachineName() : ''; $comments[$i] = $this->postComment($this->node, $this->randomMachineName(), $subject); $comments[$i]->created->value = $timestamp--; $comments[$i]->save(); } // Test that a user without the 'access comments' permission cannot see the // block. $this->drupalLogout(); user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access comments')); $this->drupalGet(''); $this->assertNoText(t('Recent comments')); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access comments')); // Test that a user with the 'access comments' permission can see the // block. $this->drupalLogin($this->webUser); $this->drupalGet(''); $this->assertText(t('Recent comments')); // Test the only the 10 latest comments are shown and in the proper order. $this->assertNoText($comments[10]->getSubject(), 'Comment 11 not found in block.'); for ($i = 0; $i < 10; $i++) { $this->assertText($comments[$i]->getSubject(), SafeMarkup::format('Comment @number found in block.', array('@number' => 10 - $i))); if ($i > 1) { $previous_position = $position; $position = strpos($this->getRawContent(), $comments[$i]->getSubject()); $this->assertTrue($position > $previous_position, SafeMarkup::format('Comment @a appears after comment @b', array('@a' => 10 - $i, '@b' => 11 - $i))); } $position = strpos($this->getRawContent(), $comments[$i]->getSubject()); } // Test that links to comments work when comments are across pages. $this->setCommentsPerPage(1); for ($i = 0; $i < 10; $i++) { $this->clickLink($comments[$i]->getSubject()); $this->assertText($comments[$i]->getSubject(), 'Comment link goes to correct page.'); $this->assertRaw('<link rel="canonical"', 'Canonical URL was found in the HTML head'); } }
/** * Test user registration integration. */ function testUserRegisterForm() { $id = $this->type->id(); $field_name = $this->field->field_name; // Allow registration without administrative approval and log in user // directly after registering. \Drupal::config('user.settings') ->set('register', USER_REGISTER_VISITORS) ->set('verify_mail', 0) ->save(); user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, ['view own test profile']); // Verify that the additional profile field is attached and required. $name = $this->randomMachineName(); $pass_raw = $this->randomMachineName(); $edit = [ 'name' => $name, 'mail' => $this->randomMachineName() . '@example.com', 'pass[pass1]' => $pass_raw, 'pass[pass2]' => $pass_raw, ]; $this->drupalPostForm('user/register', $edit, t('Create new account')); $this->assertRaw(new FormattableMarkup('@name field is required.', ['@name' => $this->instance->label])); // Verify that we can register. $edit["entity_" . $id . "[$field_name][0][value]"] = $this->randomMachineName(); $this->drupalPostForm(NULL, $edit, t('Create new account')); $this->assertText(new FormattableMarkup('Registration successful. You are now logged in.')); $new_user = user_load_by_name($name); $this->assertTrue($new_user->isActive(), 'New account is active after registration.'); // Verify that a new profile was created for the new user ID. $profiles = entity_load_multiple_by_properties('profile', [ 'uid' => $new_user->id(), 'type' => $this->type->id(), ]); $profile = reset($profiles); $this->assertEqual($profile->get($field_name)->value, $edit["entity_" . $id . "[$field_name][0][value]"], 'Field value found in loaded profile.'); // Verify that the profile field value appears on the user account page. $this->drupalGet('user'); $this->assertText($edit["entity_" . $id . "[$field_name][0][value]"], 'Field value found on user account page.'); }
/** * Configure permissions. * * @todo this is here because I cannot add it inside module due to SQL error: * SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot * be null. * * {@inheritdoc} */ function osha_configure_permissions() { if ($role = user_role_load_by_name('administrator')) { $vocabularies = array('activity', 'article_types', 'esener', 'nace_codes', 'section', 'thesaurus', 'wiki_categories', 'workflow_status', 'publication_types', 'newsletter_sections'); $permissions = array(); foreach ($vocabularies as $voc_name) { if ($voc = taxonomy_vocabulary_machine_name_load($voc_name)) { $permissions[] = 'add terms in ' . $voc_name; $permissions[] = 'edit terms in ' . $voc->vid; $permissions[] = 'delete terms in ' . $voc->vid; } } $permissions[] = 'access workbench access by role'; $permissions[] = 'translate taxonomy_term entities'; $permissions[] = 'edit any content in rejected'; $permissions[] = 'edit any content in approved'; $permissions[] = 'edit any content in final_draft'; $permissions[] = 'edit any content in to_be_approved'; // Workbench access permissions. $moderated_types = workbench_moderation_moderate_node_types(); $transitions = workbench_moderation_transitions(); foreach ($transitions as $transition) { $permissions[] = "moderate content from {$transition->from_name} to {$transition->to_name}"; foreach ($moderated_types as $node_type) { //@todo: $permissions[] = "moderate $node_type state from {$transition->from_name} to {$transition->to_name}"; } } $permissions[] = 'create moderators_group entity collections'; $permissions[] = 'edit moderators_group entity collections'; $permissions[] = 'view moderators_group entity collections'; $permissions[] = 'delete moderators_group entity collections'; $permissions[] = 'add content to moderators_group entity collections'; $permissions[] = 'manage content in moderators_group entity collections'; user_role_grant_permissions($role->rid, $permissions); user_role_revoke_permissions($role->rid, array('use workbench_moderation needs review tab')); } $roles = array(OSHA_WORKFLOW_ROLE_TRANSLATION_MANAGER, OSHA_WORKFLOW_ROLE_TRANSLATION_LIAISON, OSHA_WORKFLOW_ROLE_LAYOUT_VALIDATOR, OSHA_WORKFLOW_ROLE_CONTENT_VALIDATOR); foreach ($roles as $role_name) { if ($role = user_role_load_by_name($role_name)) { user_role_grant_permissions($role->rid, array('access workbench')); } } }
/** * Tests HEAD support when a REST resource supports GET. */ public function testHeadSupport() { user_role_grant_permissions('anonymous', ['view test entity', 'restful get entity:entity_test']); // Create an entity programatically. $this->entityCreate('entity_test')->save(); $url = Url::fromUri('internal:/entity_test/1?_format=' . $this->defaultFormat); $this->enableService('entity:entity_test', 'GET'); $this->httpRequest($url, 'HEAD', NULL, $this->defaultMimeType); $this->assertResponse(200, 'HTTP response code is correct.'); $this->assertHeader('X-Drupal-Cache', 'MISS'); $this->assertResponseBody(''); $response = $this->httpRequest($url, 'GET', NULL, $this->defaultMimeType); $this->assertResponse(200, 'HTTP response code is correct.'); $this->assertHeader('X-Drupal-Cache', 'HIT'); $this->assertCacheTag('config:rest.settings'); $this->assertCacheTag('entity_test:1'); $data = Json::decode($response); $this->assertEqual($data['type'][0]['value'], 'entity_test'); }
/** * Tests the handling of aliased requests. */ function testDomainAliasNegotiator() { // No domains should exist. $this->domainTableIsEmpty(); // Create two new domains programmatically. $this->domainCreateTestDomains(2); // Since we cannot read the service request, we place a block // which shows the current domain information. $this->drupalPlaceBlock('domain_server_block'); // To get around block access, let the anon user view the block. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('administer domains')); // Test the response of the default home page. foreach (\Drupal::service('domain.loader')->loadMultiple() as $domain) { if (!isset($alias_domain)) { $alias_domain = $domain; } $this->drupalGet($domain->getPath()); $this->assertRaw($domain->label(), 'Loaded the proper domain.'); $this->assertRaw('Exact match', 'Direct domain match.'); } // Now, test an alias. $this->domainAliasCreateTestAlias($alias_domain); $pattern = '*.' . $alias_domain->getHostname(); $alias = \Drupal::service('domain_alias.loader')->loadByPattern($pattern); $alias_domain->set('hostname', 'two.' . $alias_domain->getHostname()); $alias_domain->setPath(); $url = $alias_domain->getPath(); $this->drupalGet($url); $this->assertRaw($alias_domain->label(), 'Loaded the proper domain.'); $this->assertRaw('ALIAS:', 'No direct domain match.'); $this->assertRaw($alias->getPattern(), 'Alias match.'); // Test redirections. // @TODO: This could be much more elegant: the redirects break assertRaw() $alias->set('redirect', 301); $alias->save(); $this->drupalGet($url); $alias->set('redirect', 302); $alias->save(); $this->drupalGet($url); // Revoke the permission change user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('administer domains')); }
/** * Tests the handling of an inbound request. */ function testDomainNegotiator() { // No domains should exist. $this->domainTableIsEmpty(); // Create four new domains programmatically. $this->domainCreateTestDomains(4); // Since we cannot read the service request, we place a block // which shows the current domain information. $this->drupalPlaceBlock('domain_server_block'); // To get around block access, let the anon user view the block. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('view domain information')); // Test the response of the default home page. foreach (\Drupal::service('domain.loader')->loadMultiple() as $domain) { $this->drupalGet($domain->getPath()); $this->assertRaw($domain->label(), 'Loaded the proper domain.'); } // Revoke the permission change user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('view domain information')); // @TODO: Any other testing needed here? }
/** * Tests cancelling own user account. */ function testCancelOwnAccount() { // Allow users to cancel their own accounts. user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['cancel account']); $account = $this->registerUser(); $this->assertMollomData('user', $account->id()); // Verify that no feedback options appear on the account cancellation form. $this->drupalGet('user/' . $account->id() . '/cancel'); $this->assertNoText(t('Report as…')); // Cancel own account. $this->drupalPostForm(NULL, [], t('Cancel account')); $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.')); $this->assertNoText(t('The content was successfully reported as inappropriate.')); // Confirm account cancellation request. // Turn off error assertion because the link returns a 404 due to the batch // user process... but it really does work to cancel the account. hmmmm. $this->assertWatchdogErrors = FALSE; $this->drupalGet($this->getCancelUrl()); // Verify that Mollom session data has been deleted. $this->assertNoMollomData('user', $account->id()); }
function setUp() { parent::setUp(); // Create a bundle for entity_test. entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test'); entity_create('comment_type', array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'entity_test'))->save(); // Create comment field on entity_test bundle. $this->container->get('comment.manager')->addDefaultField('entity_test', 'entity_test'); // Verify that bundles are defined correctly. $bundles = \Drupal::entityManager()->getBundleInfo('comment'); $this->assertEqual($bundles['comment']['label'], 'Comment settings'); // Create test user. $this->admin_user = $this->drupalCreateUser(array('administer comments', 'skip comment approval', 'post comments', 'access comments', 'view test entity', 'administer entity_test content')); // Enable anonymous and authenticated user comments. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments', 'post comments', 'skip comment approval')); user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access comments', 'post comments', 'skip comment approval')); // Create a test entity. $random_label = $this->randomName(); $data = array('type' => 'entity_test', 'name' => $random_label); $this->entity = entity_create('entity_test', $data); $this->entity->save(); }
/** * Tests that domain-specific homepage loading works. * * @TODO: Requires https://www.drupal.org/node/2662196 */ function testDomainConfigHomepage() { // Let anon users see content. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content')); // Configure 'node' as front page. $this->config('system.site')->set('page.front', '/node')->save(); // No domains should exist. $this->domainTableIsEmpty(); // Create four new domains programmatically. $this->domainCreateTestDomains(5); // Get the domain list. $domains = \Drupal::service('domain.loader')->loadMultiple(); $node1 = $this->drupalCreateNode(array('type' => 'article', 'title' => 'Node 1', 'promoted' => TRUE)); $node2 = $this->drupalCreateNode(array('type' => 'article', 'title' => 'Node 2', 'promoted' => TRUE)); $homepages = $this->getHomepages(); foreach ($domains as $domain) { $home = $this->drupalGet($domain->getPath()); $expected = $domain->getPath() . $homepages[$domain->id()]; $expected_home = $this->drupalGet($expected); $this->assertTrue($home == $expected_home, 'Proper home page loaded.'); } }
/** * {@inheritdoc} */ protected function setUp() { parent::Setup(); // Create and login administrative user. $admin_user = $this->drupalCreateUser(array( 'administer contact forms', )); $this->drupalLogin($admin_user); // Create first valid contact form. $mail = '*****@*****.**'; $this->addContactForm('test_id', 'test_label', $mail, '', TRUE); $this->assertText(t('Contact form test_label has been added.')); $this->drupalLogout(); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalGet('contact'); $this->assertText(t('Your email address')); // Submit contact form few times. for ($i = 1; $i <= 5; $i++) { $this->submitContact($this->randomMachineName(), $mail, $this->randomMachineName(), 'test_id', $this->randomMachineName()); $this->assertText(t('Your message has been sent.')); } }