diff --git a/tests/modules/metatag_test_integration/metatag_test_integration.info.yml b/tests/modules/metatag_test_integration/metatag_test_integration.info.yml new file mode 100644 index 0000000..bbf7bb6 --- /dev/null +++ b/tests/modules/metatag_test_integration/metatag_test_integration.info.yml @@ -0,0 +1,7 @@ +name: "Metatag: Test Integration" +type: module +description: Support module for integration with metatag module. +core_version_requirement: '^8.7.7 || ^9' +package: Testing +dependencies: + - metatag:metatag diff --git a/tests/modules/metatag_test_integration/metatag_test_integration.module b/tests/modules/metatag_test_integration/metatag_test_integration.module new file mode 100644 index 0000000..b5a27bd --- /dev/null +++ b/tests/modules/metatag_test_integration/metatag_test_integration.module @@ -0,0 +1,69 @@ +replace($title), $metatag_attachments); + } +} + +/** + * Replaces meta tag in html head with given content. + * + * @param type $name + * + * @param type $content + * + * @param array $attachments + */ +function _metatag_test_integration_replace_tag($name, $content, array &$attachments) { + if (empty($attachments['#attached'])) { + $attachments['#attached'] = []; + } + + if (empty($attachments['#attached']['html_head'])) { + $attachments['#attached']['html_head'] = []; + } + + $index = _metatag_test_integration_find_tag($name, $attachments); + + if ($index > -1) { + $attachments['#attached']['html_head'][$index][0]['#attributes']['content'] = $content; + } + else { + $attachments['#attached']['html_head'][] = [ + 0 => [ + '#attributes' => ['name' => $name, 'content' => $content], + '#tag' => 'meta', + ], + 1 => 'description', + ]; + } +} + +/** + * Finds the index of a meta tag in the html head. + * + * @param type $name + * + * @param array $attachments + * + * @return int + */ +function _metatag_test_integration_find_tag($name, array &$attachments) { + foreach ($attachments['#attached']['html_head'] as $index => $attachment) { + if ($attachment[1] == $name) { + return $index; + } + } + return -1; +} diff --git a/tests/src/Functional/MetatagIntegrationTest.php b/tests/src/Functional/MetatagIntegrationTest.php new file mode 100644 index 0000000..ede781e --- /dev/null +++ b/tests/src/Functional/MetatagIntegrationTest.php @@ -0,0 +1,39 @@ +drupalGet(''); + $this->assertSession()->titleEquals('This is the title I want | Drupal | Yeah!'); + } + +}