Loading custom_meta.info.yml +4 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,7 @@ package: SEO configure: custom_meta.admin_overview dependencies: - metatag:metatag test_dependencies: - token:token - metatag:metatag src/Controller/CustomMetaController.php +0 −2 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ namespace Drupal\custom_meta\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\custom_meta\CustomMetaStorageInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Controller routines for custom meta routes. Loading src/Form/CustomMetaSettingsForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class CustomMetaSettingsForm extends ConfigFormBase { $form['custom_meta_prefix'] = [ '#type' => 'textfield', '#title' => $this->t('Custom meta tags prefix'), '#description' => $this->t('Use this to define the prefix of the custom meta tags '), '#description' => $this->t('Use this to define the prefix of the custom meta tags.'), '#default_value' => $this->config('custom_meta.settings')->get('prefix') ?? '', ]; Loading tests/src/Functional/CustomMetaAdminTest.php 0 → 100755 +145 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\custom_meta\Functional; use Drupal\Tests\BrowserTestBase; /** * Tests the Custom Meta administration. * * @group custom_meta */ class CustomMetaAdminTest extends BrowserTestBase { /** * {@inheritdoc} */ protected static $modules = [ 'node', 'user', 'metatag', 'custom_meta', ]; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * A user with admin permissions. * * @var \Drupal\user\UserInterface */ protected $adminUser; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->adminUser = $this ->drupalCreateUser([ 'administer custom meta tags', ]); } /** * Tests the custom meta administration end to end. */ public function testCustomMeta() { // Initiate session with a user who can manage custom metatags. $this->drupalLogin($this->adminUser); // Access custom meta settings page. $this->customMetaSettingsFormTest(); // Access custom meta listing page. $this->customMetaListingPageTest(); // Access custom meta listing page operations for name type. $this->customMetaListingPageOperationsTest('name'); // Access custom meta listing page operations for property type. $this->customMetaListingPageOperationsTest('property'); // Access custom meta listing page operations for http-equiv type. $this->customMetaListingPageOperationsTest('http-equiv'); } /** * Test custom meta configuration form test. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException * @throws \Behat\Mink\Exception\ResponseTextException */ public function customMetaSettingsFormTest() { $this->drupalGet('admin/config/search/metatag/custom-meta/settings'); $this->assertSession()->statusCodeEquals(200); $this->submitForm([], 'Save configuration'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('The configuration options have been saved.'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta/settings'); } /** * Test custom meta listing page test. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException * @throws \Behat\Mink\Exception\ResponseTextException */ public function customMetaListingPageTest() { $this->drupalGet('admin/config/search/metatag/custom-meta'); $this->assertSession()->statusCodeEquals(200); // Check that the Add tag link exists. $this->assertSession()->linkByHrefExists('admin/config/search/metatag/custom-meta/add'); // Check that empty message exists. $this->assertSession()->pageTextContains('No custom meta tags available.'); } /** * Test custom meta listing page operations test. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException * @throws \Behat\Mink\Exception\ResponseTextException */ public function customMetaListingPageOperationsTest($attribute) { // Access custom meta add page. $this->drupalGet('admin/config/search/metatag/custom-meta/add'); $this->assertSession()->statusCodeEquals(200); $edit = []; $edit['attribute'] = $attribute; $edit['name'] = 'nid'; $edit['label'] = 'Nid'; $edit['description'] = 'Nid description'; $this->submitForm($edit, 'Save'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextContains('Meta tag has been saved.'); // Access custom meta edit page. $this->drupalGet('admin/config/search/metatag/custom-meta/edit/' . $edit['name']); $this->assertSession()->statusCodeEquals(200); $this->submitForm(['description' => 'Node id description'], 'Save'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextContains('Meta tag has been saved.'); // Access custom meta delete page and perform cancel operation. $this->drupalGet('admin/config/search/metatag/custom-meta/delete/' . $edit['name']); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('Are you sure you want to delete custom meta tag Nid?'); $this->clickLink('Cancel'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextContains('Node id description'); // Access custom meta delete page and perform delete operation. $this->drupalGet('admin/config/search/metatag/custom-meta/delete/' . $edit['name']); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('Are you sure you want to delete custom meta tag Nid?'); $this->submitForm([], 'Confirm'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextNotContains('Node id description'); } } Loading
custom_meta.info.yml +4 −0 Original line number Diff line number Diff line Loading @@ -6,3 +6,7 @@ package: SEO configure: custom_meta.admin_overview dependencies: - metatag:metatag test_dependencies: - token:token - metatag:metatag
src/Controller/CustomMetaController.php +0 −2 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ namespace Drupal\custom_meta\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\custom_meta\CustomMetaStorageInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Controller routines for custom meta routes. Loading
src/Form/CustomMetaSettingsForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class CustomMetaSettingsForm extends ConfigFormBase { $form['custom_meta_prefix'] = [ '#type' => 'textfield', '#title' => $this->t('Custom meta tags prefix'), '#description' => $this->t('Use this to define the prefix of the custom meta tags '), '#description' => $this->t('Use this to define the prefix of the custom meta tags.'), '#default_value' => $this->config('custom_meta.settings')->get('prefix') ?? '', ]; Loading
tests/src/Functional/CustomMetaAdminTest.php 0 → 100755 +145 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\custom_meta\Functional; use Drupal\Tests\BrowserTestBase; /** * Tests the Custom Meta administration. * * @group custom_meta */ class CustomMetaAdminTest extends BrowserTestBase { /** * {@inheritdoc} */ protected static $modules = [ 'node', 'user', 'metatag', 'custom_meta', ]; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * A user with admin permissions. * * @var \Drupal\user\UserInterface */ protected $adminUser; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->adminUser = $this ->drupalCreateUser([ 'administer custom meta tags', ]); } /** * Tests the custom meta administration end to end. */ public function testCustomMeta() { // Initiate session with a user who can manage custom metatags. $this->drupalLogin($this->adminUser); // Access custom meta settings page. $this->customMetaSettingsFormTest(); // Access custom meta listing page. $this->customMetaListingPageTest(); // Access custom meta listing page operations for name type. $this->customMetaListingPageOperationsTest('name'); // Access custom meta listing page operations for property type. $this->customMetaListingPageOperationsTest('property'); // Access custom meta listing page operations for http-equiv type. $this->customMetaListingPageOperationsTest('http-equiv'); } /** * Test custom meta configuration form test. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException * @throws \Behat\Mink\Exception\ResponseTextException */ public function customMetaSettingsFormTest() { $this->drupalGet('admin/config/search/metatag/custom-meta/settings'); $this->assertSession()->statusCodeEquals(200); $this->submitForm([], 'Save configuration'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('The configuration options have been saved.'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta/settings'); } /** * Test custom meta listing page test. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException * @throws \Behat\Mink\Exception\ResponseTextException */ public function customMetaListingPageTest() { $this->drupalGet('admin/config/search/metatag/custom-meta'); $this->assertSession()->statusCodeEquals(200); // Check that the Add tag link exists. $this->assertSession()->linkByHrefExists('admin/config/search/metatag/custom-meta/add'); // Check that empty message exists. $this->assertSession()->pageTextContains('No custom meta tags available.'); } /** * Test custom meta listing page operations test. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException * @throws \Behat\Mink\Exception\ResponseTextException */ public function customMetaListingPageOperationsTest($attribute) { // Access custom meta add page. $this->drupalGet('admin/config/search/metatag/custom-meta/add'); $this->assertSession()->statusCodeEquals(200); $edit = []; $edit['attribute'] = $attribute; $edit['name'] = 'nid'; $edit['label'] = 'Nid'; $edit['description'] = 'Nid description'; $this->submitForm($edit, 'Save'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextContains('Meta tag has been saved.'); // Access custom meta edit page. $this->drupalGet('admin/config/search/metatag/custom-meta/edit/' . $edit['name']); $this->assertSession()->statusCodeEquals(200); $this->submitForm(['description' => 'Node id description'], 'Save'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextContains('Meta tag has been saved.'); // Access custom meta delete page and perform cancel operation. $this->drupalGet('admin/config/search/metatag/custom-meta/delete/' . $edit['name']); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('Are you sure you want to delete custom meta tag Nid?'); $this->clickLink('Cancel'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextContains('Node id description'); // Access custom meta delete page and perform delete operation. $this->drupalGet('admin/config/search/metatag/custom-meta/delete/' . $edit['name']); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('Are you sure you want to delete custom meta tag Nid?'); $this->submitForm([], 'Confirm'); $this->assertSession()->addressEquals('/admin/config/search/metatag/custom-meta'); $this->assertSession()->pageTextNotContains('Node id description'); } }