public function SimplenewsAdministrationTest::testAccess in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsAdministrationTest.php \Drupal\Tests\simplenews\Functional\SimplenewsAdministrationTest::testAccess()
Test access for subscriber admin page.
File
- tests/
src/ Functional/ SimplenewsAdministrationTest.php, line 1069
Class
- SimplenewsAdministrationTest
- Managing of newsletter categories and content types.
Namespace
Drupal\Tests\simplenews\FunctionalCode
public function testAccess() {
$admin_user = $this
->drupalCreateUser([
'administer newsletters',
'administer simplenews subscriptions',
]);
$this
->drupalLogin($admin_user);
// Create a newsletter.
$newsletter_name = mb_strtolower($this
->randomMachineName());
$edit = [
'name' => $newsletter_name,
'id' => $newsletter_name,
];
$this
->drupalGet('admin/config/services/simplenews/add');
$this
->submitForm($edit, 'Save');
// Create a user and subscribe them.
$user = $this
->drupalCreateUser();
$subscriber = Subscriber::create([
'mail' => $user
->getEmail(),
]);
$subscriber
->subscribe('default', SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
$subscriber
->setStatus(TRUE);
$subscriber
->save();
// Check anonymous user can't access admin page.
$this
->drupalLogout();
$this
->drupalGet('admin/people/simplenews');
$this
->assertResponse(403);
// Turn off the access permission on the view.
$view = View::load('simplenews_subscribers');
$display =& $view
->getDisplay('default');
$display['display_options']['access'] = [
'type' => 'none',
'options' => [],
];
$view
->save();
\Drupal::service('router.builder')
->rebuild();
// Check username is public but email is not shown.
$this
->drupalGet('admin/people/simplenews');
$this
->assertText($user
->getAccountName());
$this
->assertNoText($user
->getEmail());
// Grant view permission.
$view_user = $this
->drupalCreateUser([
'view simplenews subscriptions',
]);
$this
->drupalLogin($view_user);
// Check can see username and email.
$this
->drupalGet('admin/people/simplenews');
$this
->assertText($user
->getAccountName());
$this
->assertText($user
->getEmail());
}