XmlSitemapUserFunctionalTest.php 2.18 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\xmlsitemap\Functional;
4

amateescu's avatar
amateescu committed
5 6 7
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;

8
/**
9
 * Tests the generation of user links.
10 11
 *
 * @group xmlsitemap
12
 */
13
class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase {
14

15 16 17
  /**
   * {@inheritdoc}
   */
18
  protected $accounts = [];
19 20 21 22

  /**
   * {@inheritdoc}
   */
23
  protected function setUp() {
24 25
    parent::setUp();

26
    // Allow anonymous user to view user profiles.
amateescu's avatar
amateescu committed
27
    $user_role = Role::load(AccountInterface::ANONYMOUS_ROLE);
28 29 30
    $user_role->grantPermission('access user profiles');
    $user_role->save();

31
    xmlsitemap_link_bundle_enable('user', 'user');
32

33 34 35 36 37 38
    // Enable XML Sitemap settings for users.
    xmlsitemap_link_bundle_settings_save('user', 'user', [
      'status' => 1,
      'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
    ]);

39
    // Create the users.
40 41 42 43 44
    $this->admin_user = $this->drupalCreateUser([
      'administer users',
      'administer permissions',
      'administer xmlsitemap',
    ]);
45
    $this->normal_user = $this->drupalCreateUser(['access content']);
46 47
  }

48
  /**
49
   * Test sitemap link for a blocked user.
50
   */
51
  public function testBlockedUser() {
52 53 54 55 56 57 58 59 60
    $this->assertSitemapLinkVisible('user', $this->normal_user->id());

    // Reset the user entity access cache before updating the entity.
    $this->container->get('entity_type.manager')->getAccessControlHandler('user')->resetCache();

    // Block the user.
    $this->normal_user->block();
    $this->normal_user->save();

61
    $this->assertSitemapLinkNotVisible('user', $this->normal_user->id());
62
  }
63

64 65 66 67 68
  /**
   * Test sitemap fields on user forms.
   */
  public function testUserForm() {
    $this->drupalLogin($this->admin_user);
69

70 71 72 73 74
    $this->drupalGet('admin/people/create');
    $this->assertSession()->fieldExists('xmlsitemap[status]');
    $this->assertSession()->fieldExists('xmlsitemap[priority]');
    $this->assertSession()->fieldExists('xmlsitemap[changefreq]');

75
    $this->drupalGet('user/' . $this->normal_user->id() . '/edit');
76 77 78
    $this->assertSession()->fieldExists('xmlsitemap[status]');
    $this->assertSession()->fieldExists('xmlsitemap[priority]');
    $this->assertSession()->fieldExists('xmlsitemap[changefreq]');
79 80 81
  }

}