3 namespace Drupal\metatag\Tests;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\simpletest\WebTestBase;
9 * Verify that different meta tag API options are supported.
13 class MetatagTagTypesTest extends WebTestBase {
18 protected $profile = 'testing';
23 * @var \Drupal\Core\Session\AccountInterface
32 public static $modules = [
33 // Needed for token handling.
36 // Needed for the field UI testing.
39 // Needed for the basic entity testing.
42 // Needed to verify that nothing is broken for unsupported entities.
48 // Some extra custom logic for testing Metatag.
51 // Needed for testSecureTagOption().
56 * Permissions to grant admin user.
60 protected $permissions = [
61 'access administration pages',
63 'administer entity_test fields',
64 'administer entity_test content',
65 'administer meta tags',
71 protected function setUp() {
73 $this->adminUser = $this->drupalCreateUser($this->permissions);
74 $this->drupalLogin($this->adminUser);
76 // Add a metatag field to the entity type test_entity.
77 $this->drupalGet('entity_test/structure/entity_test/fields/add-field');
78 $this->assertResponse(200);
81 'field_name' => 'metatag',
82 'new_storage_type' => 'metatag',
84 $this->drupalPostForm(NULL, $edit, t('Save and continue'));
85 $this->drupalPostForm(NULL, [], t('Save field settings'));
86 $this->container->get('entity.manager')->clearCachedFieldDefinitions();
90 * Tests whether HTML is correctly removed from metatags
92 * Tests three values in metatags -- one without any HTML; one with raw html; and one with escaped HTML.
93 * To pass all HTML including escaped should be removed.
95 public function testHTMLIsRemoved() {
96 $this->drupalGet('admin/config/search/metatag/global');
97 $this->assertResponse(200);
99 'abstract' => 'No HTML here',
100 'description' => '<html><body><p class="test">Surrounded by raw HTML</p></body></html>',
101 'keywords' => '<html><body><p class="test">Surrounded by escaped HTML</p></body></html>',
104 $this->drupalPostForm(NULL, $values, 'Save');
105 $this->assertText('Saved the Global Metatag defaults.');
106 drupal_flush_all_caches();
107 $this->drupalGet('hit-a-404');
108 $this->assertResponse(404);
110 $this->assertRaw('<meta name="abstract" content="No HTML here" />', t('Test with no HTML content'));
111 $this->assertRaw('<meta name="description" content="Surrounded by raw HTML" />', t('Test with raw HTML content'));
112 $this->assertRaw('<meta name="keywords" content="Surrounded by escaped HTML" />', t('Test with escaped HTML content'));
116 * Tests whether insecure links in Tags with attribute secure = TRUE are
117 * correctly changed to secure links
119 * Tests insecure values in og:image:secure_url (a tag with secure attribue
120 * set to TRUE) and in og:image (a tag with secure attribue set to FALSE). To
121 * To pass og:image_secure should be changed to https:// and og:image
124 public function testSecureTagOption() {
125 $this->drupalGet('admin/config/search/metatag/global');
126 $this->assertResponse(200);
128 'og_image' => 'http://blahblahblah.com/insecure.jpg',
129 'og_image_secure_url' => 'http://blahblahblah.com/secure.jpg',
131 $this->drupalPostForm(NULL, $values, 'Save');
132 $this->assertText('Saved the Global Metatag defaults.');
133 drupal_flush_all_caches();
134 $this->drupalGet('');
135 $this->assertResponse(200);
137 $this->assertRaw('<meta property="og:image" content="http://blahblahblah.com/insecure.jpg" />', t('Test og:image with regular http:// link'));
138 $this->assertRaw('<meta property="og:image:secure_url" content="https://blahblahblah.com/secure.jpg" />', t('Test og:image:secure_url updated regular http:// link to https:// '));
142 * @todo Move this somewhere else.
144 function testContactForm() {
145 // Test a route where the entity for that route does not implement
146 // ContentEntityInterface.
147 $controller = \Drupal::entityTypeManager()->getStorage('contact_form');
148 $controller->create([
149 'id' => 'test_contact_form',
151 $account = $this->drupalCreateUser(['access site-wide contact form']);
152 $this->drupalLogin($account);
153 $this->drupalGet('contact/test_contact_form');
154 $this->assertResponse(200);
160 // public function testUrl() {
161 // // Tests metatags with URLs work.
162 // $this->drupalGet($this->entity_add_path);
163 // $this->assertResponse(200);
165 // 'name[0][value]' => 'UrlTags',
166 // 'user_id[0][target_id]' => 'foo (' . $this->adminUser->id() . ')',
167 // 'field_metatag[0][advanced][original_source]' => 'http://example.com/foo.html',
169 // $this->drupalPostForm(NULL, $edit, t('Save'));
170 // $entities = entity_load_multiple_by_properties('entity_test', [
171 // 'name' => 'UrlTags',
173 // $this->assertEqual(1, count($entities), 'Entity was saved');
174 // $entity = reset($entities);
175 // $this->drupalGet($this->entity_base_path . '/' . $entity->id());
176 // $this->assertResponse(200);
177 // $elements = $this->cssSelect("meta[name='original-source']");
178 // $this->assertTrue(count($elements) === 1, 'Found original source metatag from defaults');
179 // $this->assertEqual((string) $elements[0]['content'], $edit['field_metatag[0][advanced][original_source]']);