diff --git a/tests/src/Functional/XmlSitemapNodeFunctionalTest.php b/tests/src/Functional/XmlSitemapNodeFunctionalTest.php index 1cf9d9f..c65842f 100644 --- a/tests/src/Functional/XmlSitemapNodeFunctionalTest.php +++ b/tests/src/Functional/XmlSitemapNodeFunctionalTest.php @@ -202,8 +202,9 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase { ]); $this->drupalLogin($this->admin_user); + + // Test fields are visible on the node add form. $this->drupalGet('node/add/page'); - $this->assertResponse(200); $this->assertSession()->fieldExists('xmlsitemap[status]'); $this->assertSession()->fieldExists('xmlsitemap[priority]'); $this->assertSession()->fieldExists('xmlsitemap[changefreq]'); diff --git a/tests/src/Functional/XmlSitemapUserFunctionalTest.php b/tests/src/Functional/XmlSitemapUserFunctionalTest.php index 157e697..b095dd4 100644 --- a/tests/src/Functional/XmlSitemapUserFunctionalTest.php +++ b/tests/src/Functional/XmlSitemapUserFunctionalTest.php @@ -30,6 +30,12 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase { xmlsitemap_link_bundle_enable('user', 'user'); + // Enable XML Sitemap settings for users. + xmlsitemap_link_bundle_settings_save('user', 'user', [ + 'status' => 1, + 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, + ]); + // Create the users. $this->admin_user = $this->drupalCreateUser([ 'administer users', @@ -37,28 +43,39 @@ class XmlSitemapUserFunctionalTest extends XmlSitemapTestBase { 'administer xmlsitemap', ]); $this->normal_user = $this->drupalCreateUser(['access content']); - - // Update the normal user to make its sitemap link visible. - $account = clone $this->normal_user; - $account->save(); } /** * Test sitemap link for a blocked user. */ public function testBlockedUser() { - $this->drupalLogin($this->admin_user); + $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(); + $this->assertSitemapLinkNotVisible('user', $this->normal_user->id()); + } - // Mark the user as blocked. - $edit = [ - 'xmlsitemap[status]' => 1, - ]; + /** + * Test sitemap fields on user forms. + */ + public function testUserForm() { + $this->drupalLogin($this->admin_user); - // This will pass when https://www.drupal.org/node/360925 is fixed. - $this->drupalPostForm('user/' . $this->normal_user->id() . '/edit', $edit, t('Save')); - $this->assertSession()->pageTextContains('The changes have been saved.'); - $this->assertSitemapLinkVisible('user', $this->normal_user->id()); + $this->drupalGet('admin/people/create'); + $this->assertSession()->fieldExists('xmlsitemap[status]'); + $this->assertSession()->fieldExists('xmlsitemap[priority]'); + $this->assertSession()->fieldExists('xmlsitemap[changefreq]'); + + $this->drupalGet('user/' . $this->normal_user->id() . '/edit'); + $this->assertSession()->fieldExists('xmlsitemap[status]'); + $this->assertSession()->fieldExists('xmlsitemap[priority]'); + $this->assertSession()->fieldExists('xmlsitemap[changefreq]'); } } diff --git a/xmlsitemap.module b/xmlsitemap.module index e04ef2d..b94fa20 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -1533,7 +1533,11 @@ function xmlsitemap_form_alter(array &$form, FormStateInterface $form_state, $fo if ($form_object instanceof ContentEntityFormInterface) { $entity = $form_object->getEntity(); // Some entity types use 'default' for add/edit forms. - if (in_array($form_object->getOperation(), ['default', 'edit'], TRUE) && xmlsitemap_link_bundle_check_enabled($entity->getEntityTypeId(), $entity->bundle())) { + $operations = ['default', 'edit']; + if ($entity->getEntityTypeId() === 'user') { + $operations[] = 'register'; + } + if (in_array($form_object->getOperation(), $operations, TRUE) && xmlsitemap_link_bundle_check_enabled($entity->getEntityTypeId(), $entity->bundle())) { xmlsitemap_add_form_link_options($form, $entity->getEntityTypeId(), $entity->bundle(), $entity->id()); $form['xmlsitemap']['#weight'] = 10; }