/** * Tests contact link. */ public function testContactLink() { $accounts = array(); $accounts['root'] = User::load(1); // Create an account with access to all contact pages. $admin_account = $this->drupalCreateUser(array('administer users')); $accounts['admin'] = $admin_account; // Create an account with no access to contact pages. $no_contact_account = $this->drupalCreateUser(); $accounts['no_contact'] = $no_contact_account; // Create an account with access to contact pages. $contact_account = $this->drupalCreateUser(array('access user contact forms')); $accounts['contact'] = $contact_account; $this->drupalLogin($admin_account); $this->drupalGet('test-contact-link'); // The admin user has access to all contact links beside his own. $this->assertContactLinks($accounts, array('root', 'no_contact', 'contact')); $this->drupalLogin($no_contact_account); $this->drupalGet('test-contact-link'); // Ensure that the user without the permission doesn't see any link. $this->assertContactLinks($accounts, array()); $this->drupalLogin($contact_account); $this->drupalGet('test-contact-link'); $this->assertContactLinks($accounts, array('root', 'admin', 'no_contact')); // Disable contact link for no_contact. $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE); // @todo Remove cache invalidation in https://www.drupal.org/node/2477903. Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate()); $this->drupalGet('test-contact-link'); $this->assertContactLinks($accounts, array('root', 'admin')); }
/** * Tests contact link. */ public function testContactLink() { $accounts = array(); $accounts['root'] = user_load(1); // Create an account with access to all contact pages. $admin_account = $this->drupalCreateUser(array('administer users')); $accounts['admin'] = $admin_account; // Create an account with no access to contact pages. $no_contact_account = $this->drupalCreateUser(); $accounts['no_contact'] = $no_contact_account; // Create an account with access to contact pages. $contact_account = $this->drupalCreateUser(array('access user contact forms')); $accounts['contact'] = $contact_account; $this->drupalLogin($admin_account); $this->drupalGet('test-contact-link'); // The admin user has access to all contact links beside his own. $this->assertContactLinks($accounts, array('root', 'no_contact', 'contact')); $this->drupalLogin($no_contact_account); $this->drupalGet('test-contact-link'); // Ensure that the user without the permission doesn't see any link. $this->assertContactLinks($accounts, array()); $this->drupalLogin($contact_account); $this->drupalGet('test-contact-link'); $this->assertContactLinks($accounts, array('root', 'admin', 'no_contact')); // Disable contact link for no_contact. $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE); $this->drupalGet('test-contact-link'); $this->assertContactLinks($accounts, array('root', 'admin')); }
/** * @inheritDoc */ public function submitForm(array &$form, FormStateInterface $form_state) { $moodle_uid = $form_state->getValue('moodle_uid'); $drupal_uid = $form_state->getValue('drupal_uid'); if ($moodle_uid > 0) { $this->userData->set('moodle', $drupal_uid, 'uid', $moodle_uid); drupal_set_message($this->t('The moodle - drupal user mapping has been saved.')); } else { $this->userData->set('moodle', $drupal_uid, 'uid', ''); drupal_set_message($this->t('You have not selected anything.')); } }
/** * Tests field handler. */ public function testDataField() { // But some random values into the user data service. $this->userData = $this->container->get('user.data'); $random_value = $this->randomMachineName(); $this->userData->set('views_test_config', $this->users[0]->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.'); $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'); }