' . print_r($config, TRUE) . ''); + $this->verbose($config); // Load the front page. $this->drupalGet('
' . print_r($config, TRUE) . ''); + $this->verbose($config); // Load the front page. $this->drupalGet('
' . print_r($config, TRUE) . ''); + $this->verbose($config); // Load the front page. $this->drupalGet('
' . print_r($config, TRUE) . ''); + $this->verbose($config); // Load the front page. $this->drupalGet('
' . print_r($config, TRUE) . ''); + $this->verbose($config); // Load the front page. $this->drupalGet('
' . print_r($config, TRUE) . ''); + $this->verbose($config); // Load the front page. $this->drupalGet('
' . print_r($image, TRUE) . ''); + $this->verbose($image); // Update the article-image default settings to use the new image field. $entity_type = 'node'; @@ -295,7 +334,7 @@ class MetatagCoreImageTest extends MetatagTestHelper { $image_url = file_create_url($image->uri); // Dump out the file object, to aid with debugging. - $this->verbose('
' . print_r($image, TRUE) . ''); + $this->verbose($image); // Create an example node. $args = array( @@ -310,7 +349,7 @@ class MetatagCoreImageTest extends MetatagTestHelper { // Forcibly reload the node, to avoid working with a cached version. $node = node_load($node->nid, NULL, TRUE); - $this->verbose('
Node:
' . print_r($node, TRUE) . ''); + $this->verbose($node, 'Node'); // Load the node page. $this->drupalGet('node/' . $node->nid); @@ -350,8 +389,8 @@ class MetatagCoreImageTest extends MetatagTestHelper { $image2_url = file_create_url($image2->uri); // Dump out the file objects, to aid with debugging. - $this->verbose('
Image #1
' . print_r($image1, TRUE) . ''); - $this->verbose('
Image #2
' . print_r($image2, TRUE) . ''); + $this->verbose($image1, 'Image #1'); + $this->verbose($image2, 'Image #2'); // Create an example node. $args = array( @@ -367,7 +406,7 @@ class MetatagCoreImageTest extends MetatagTestHelper { // Forcibly reload the node, to avoid working with a cached version. $node = node_load($node->nid, NULL, TRUE); - $this->verbose('
Node:
' . print_r($node, TRUE) . ''); + $this->verbose($node, 'Node'); // Load the node page. $this->drupalGet('node/' . $node->nid); @@ -409,8 +448,8 @@ class MetatagCoreImageTest extends MetatagTestHelper { $image2_url = file_create_url($image2->uri); // Dump out the file objects, to aid with debugging. - $this->verbose('
Image #1
' . print_r($image1, TRUE) . ''); - $this->verbose('
Image #2
' . print_r($image2, TRUE) . ''); + $this->verbose($image1, 'Image #1'); + $this->verbose($image2, 'Image #2'); // Create an example node. $args = array( @@ -426,7 +465,7 @@ class MetatagCoreImageTest extends MetatagTestHelper { // Forcibly reload the node, to avoid working with a cached version. $node = node_load($node->nid, NULL, TRUE); - $this->verbose('
Node:
' . print_r($node, TRUE) . ''); + $this->verbose($node, 'Node'); // Load the node page. $this->drupalGet('node/' . $node->nid); diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.locale.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.locale.test index 37c2abe5..0b2a8a83 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.locale.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.locale.test @@ -1,10 +1,10 @@ 'Metatag core tests for Locale', 'description' => 'Test Metatag integration with the locale module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), ); } @@ -37,6 +38,9 @@ class MetatagCoreLocaleTest extends MetatagTestHelper { // Create a content type. $this->createContentType($content_type, $label); + // Add more locales. + $this->setupLocales(); + // Create an admin user and log them in. $perms = array( // Needed for the content type. @@ -49,10 +53,9 @@ class MetatagCoreLocaleTest extends MetatagTestHelper { 'translate interface', ); $this->adminUser = $this->createAdminUser($perms); - $this->drupalLogin($this->adminUser); - // Prep the locales. - $this->setupLocales(); + // Log in the admin user. + $this->drupalLogin($this->adminUser); // Load the node form in each locale, confirm it has the fields. This also // preloads the field labels into the locale system. diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.node.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.node.test index f256fc7c..6c3bb184 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.node.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.node.test @@ -1,10 +1,10 @@ 'Metatag core tests for nodes', 'description' => 'Test Metatag edit functionality for nodes.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), ); } @@ -43,6 +44,8 @@ class MetatagCoreNodeTest extends MetatagTestHelper { 'administer nodes', ); $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. $this->drupalLogin($this->adminUser); // Assign default values for the new content type. @@ -65,12 +68,7 @@ class MetatagCoreNodeTest extends MetatagTestHelper { // Submit the form with some values. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[node:title]', - 'metatags[und][dcterms.creator][value]' => '[node:author]', - 'metatags[und][dcterms.date][value]' => '[node:created:custom:Y-m-d\TH:iP]', - 'metatags[und][dcterms.format][value]' => 'text/html', - 'metatags[und][dcterms.identifier][value]' => '[current-page:url:absolute]', - 'metatags[und][dcterms.language][value]' => '[node:language]', + 'metatags[und][abstract][value]' => '[node:title]', ), t('Save')); $this->assertResponse(200); @@ -92,7 +90,7 @@ class MetatagCoreNodeTest extends MetatagTestHelper { // Verify that it's possible to submit values to the form. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[node:title] ponies', + 'metatags[und][abstract][value]' => '[node:title] ponies', 'title' => 'Who likes magic', ), t('Save')); $this->assertResponse(200); @@ -100,7 +98,7 @@ class MetatagCoreNodeTest extends MetatagTestHelper { // The meta tags that will be checked for. $expected = array( 'und' => array( - 'dcterms.subject' => array( + 'abstract' => array( 'value' => '[node:title] ponies', ), ), @@ -121,25 +119,25 @@ class MetatagCoreNodeTest extends MetatagTestHelper { if (preg_match('@node/(\d+)$@', $this->getUrl(), $matches)) { $nid = end($matches); $node = node_load($nid); - $this->verbose('
node_load(' . $nid . ')
' . print_r($node, TRUE) . ''); + $this->verbose($node, 'node_load(' . $nid . ')'); // Only the non-default values are stored. $this->assertEqual($expected, $node->metatags); // Confirm the APIs can load the data for this node. $metatags = metatag_metatags_load('node', $node->nid); - $this->verbose('
metatag_metatags_load("node", ' . $node->nid . ')
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load("node", ' . $node->nid . ')'); $this->assertEqual($expected, $metatags); $metatags = metatag_metatags_load_multiple('node', array($node->nid)); - $this->verbose('
metatag_metatags_load_multiple("node", array(' . $node->nid . '))
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load_multiple("node", array(' . $node->nid . '))'); $this->assertEqual(array($node->nid => array($node->vid => $expected)), $metatags); // Confirm the APIs can load the data for this node revision. $metatags = metatag_metatags_load('node', $node->nid, $node->vid); - $this->verbose('
metatag_metatags_load("node", ' . $node->nid . ', ' . $node->vid . ')
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load("node", ' . $node->nid . ', ' . $node->vid . ')'); $this->assertEqual($expected, $metatags); $metatags = metatag_metatags_load_multiple('node', array($node->nid), array($node->vid)); - $this->verbose('
metatag_metatags_load_multiple("node", array(' . $node->nid . '), array(' . $node->vid . '))
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load_multiple("node", array(' . $node->nid . '), array(' . $node->vid . '))'); $this->assertEqual(array($node->nid => array($node->vid => $expected)), $metatags); } @@ -149,8 +147,8 @@ class MetatagCoreNodeTest extends MetatagTestHelper { } // Verify the title is using the custom default for this content type. - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); $this->assertEqual($xpath[0]['content'], 'Who likes magic ponies'); // Core's canonical tag is a relative URL, whereas Metatag outputs an @@ -180,7 +178,7 @@ class MetatagCoreNodeTest extends MetatagTestHelper { $this->assertResponse(200); // Try submitting text to the page. $args = array( - 'metatags[und][dcterms.subject][value]' => '[node:title] kittens', + 'metatags[und][abstract][value]' => '[node:title] kittens', 'title' => $new_title, 'revision' => 1, 'log' => 'Creating a new revision', @@ -192,7 +190,7 @@ class MetatagCoreNodeTest extends MetatagTestHelper { // A new version of the expected results $expected_updated = array( 'und' => array( - 'dcterms.subject' => array( + 'abstract' => array( 'value' => '[node:title] kittens', ), ), @@ -208,10 +206,10 @@ class MetatagCoreNodeTest extends MetatagTestHelper { $this->assertText(strip_tags(t('@type %title has been updated.', $t_args))); // Verify the title is still using the custom default for this content type. - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertNotEqual($xpath[0]['content'], $old_title . ' ponies', 'Did not find the new dcterms.subject meta tag.'); - $this->assertEqual($xpath[0]['content'], $new_title . ' kittens', 'Found the old dcterms.subject meta tag.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertNotEqual($xpath[0]['content'], $old_title . ' ponies', 'Did not find the new abstract meta tag.'); + $this->assertEqual($xpath[0]['content'], $new_title . ' kittens', 'Found the old abstract meta tag.'); // Load the node revisions page. $this->drupalGet('node/' . $node->nid . '/revisions'); @@ -226,43 +224,43 @@ class MetatagCoreNodeTest extends MetatagTestHelper { $this->drupalGet('node/' . $node->nid . '/revisions/' . $old_vid . '/view'); // Verify the page loaded correctly. $this->assertResponse(200, 'Loaded the original revision of this node.'); - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new dcterms.subject meta tag.'); - $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old dcterms.subject meta tag.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new abstract meta tag.'); + $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old abstract meta tag.'); // Load the updated node; force-load it to make sure it's loaded properly. $updated_node = node_load($node->nid, NULL, TRUE); $updated_vid = $updated_node->vid; - $this->verbose('
node_load(' . $node->nid . ', NULL, TRUE)
' . print_r($updated_node, TRUE) . ''); + $this->verbose($updated_node, 'node_load(' . $node->nid . ', NULL, TRUE)'); // Confirm the APIs can load the data for this node. $metatags = metatag_metatags_load('node', $updated_node->nid); - $this->verbose('
metatag_metatags_load("node", ' . $updated_node->nid . ')
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load("node", ' . $updated_node->nid . ')'); $this->assertEqual($expected_updated, $metatags); $this->assertNotEqual($expected, $metatags); // This one is complicated. If only the entity id is passed in it will load // the {metatag} records for *all* of the entity's revisions. $metatags = metatag_metatags_load_multiple('node', array($updated_node->nid)); - $this->verbose('
metatag_metatags_load_multiple("node", array(' . $updated_node->nid . '))
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load_multiple("node", array(' . $updated_node->nid . '))'); $this->assertEqual(array($updated_node->nid => array($node->vid => $expected, $updated_node->vid => $expected_updated)), $metatags); // Confirm the APIs can load the data for this node revision. $metatags = metatag_metatags_load('node', $updated_node->nid, $updated_vid); - $this->verbose('
metatag_metatags_load("node", ' . $updated_node->nid . ', ' . $updated_node->vid . ')
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load("node", ' . $updated_node->nid . ', ' . $updated_node->vid . ')'); $this->assertEqual($expected_updated, $metatags); $this->assertNotEqual($expected, $metatags); $metatags = metatag_metatags_load_multiple('node', array($updated_node->nid), array($updated_node->vid)); - $this->verbose('
metatag_metatags_load_multiple("node", array(' . $updated_node->nid . '), array(' . $updated_node->vid . '))
' . print_r($metatags, TRUE) . ''); + $this->verbose($metatags, 'metatag_metatags_load_multiple("node", array(' . $updated_node->nid . '), array(' . $updated_node->vid . '))'); $this->assertEqual(array($updated_node->nid => array($updated_node->vid => $expected_updated)), $metatags); // Load the current revision again. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200, 'Loaded the current revision of this node.'); - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertNotEqual($xpath[0]['content'], $old_title . ' ponies', 'Did not find the old dcterms.subject meta tag.'); - $this->assertEqual($xpath[0]['content'], $new_title . ' kittens', 'Found the new dcterms.subject meta tag.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertNotEqual($xpath[0]['content'], $old_title . ' ponies', 'Did not find the old abstract meta tag.'); + $this->assertEqual($xpath[0]['content'], $new_title . ' kittens', 'Found the new abstract meta tag.'); // Revert to the original revision. $this->drupalGet('node/' . $node->nid . '/revisions/' . $old_vid . '/revert'); @@ -279,10 +277,10 @@ class MetatagCoreNodeTest extends MetatagTestHelper { // Load the current revision, which will now have the old meta tags. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200, 'Loaded the current revision of this node.'); - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new dcterms.subject meta tag.'); - $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old dcterms.subject meta tag again.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new abstract meta tag.'); + $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old abstract meta tag again.'); // Delete the original revision. $this->drupalGet('node/' . $node->nid . '/revisions/' . $old_vid . '/delete'); @@ -301,10 +299,10 @@ class MetatagCoreNodeTest extends MetatagTestHelper { metatag_config_cache_clear(); $this->drupalGet('node/' . $node->nid); $this->assertResponse(200, 'Loaded the current revision of this node again.'); - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new dcterms.subject meta tag.'); - $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old dcterms.subject meta tag again.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new abstract meta tag.'); + $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old abstract meta tag again.'); // Delete the second revision. $this->drupalGet('node/' . $node->nid . '/revisions/' . $updated_vid . '/delete'); @@ -323,9 +321,107 @@ class MetatagCoreNodeTest extends MetatagTestHelper { metatag_config_cache_clear(); $this->drupalGet('node/' . $node->nid); $this->assertResponse(200, 'Loaded the current revision of this node again.'); - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new dcterms.subject meta tag.'); - $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old dcterms.subject meta tag again.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertNotEqual($xpath[0]['content'], $new_title . ' kittens', 'Did not find the new abstract meta tag.'); + $this->assertEqual($xpath[0]['content'], $old_title . ' ponies', 'Found the old abstract meta tag again.'); } + + /** + * Tests different 'preview' options. #1: Disabled. + */ + public function testNodePreviewOption0() { + $this->checkNodePreviewOption(0); + } + + /** + * Tests different 'preview' options. #2: Optional, without preview. + */ + public function testNodePreviewOption1NoPreview() { + $this->checkNodePreviewOption(1, FALSE); + } + + /** + * Tests different 'preview' options. #2: Optional, with preview. + */ + public function testNodePreviewOption1Preview() { + $this->checkNodePreviewOption(1, TRUE); + } + + /** + * Tests different 'preview' options. #3: Preview required. + */ + public function testNodePreviewOption2() { + $this->checkNodePreviewOption(2); + } + + /** + * Change the node preview option at the content type level, confirm meta tags + * still save correctly. + * + * @param int $option + * A suitable value for the 'node_preview' option for a content type, must + * be either 0, 1 or 2. + * @param bool $preview + * Whether to perform a preview. Has the following implications: + * - if $option === 0, $preview is ignored, no preview is performed. + * - if $option === 1, $preview is considered, a preview may be performed. + * - if $option === 2, $preview is ignored, a preview is performed. + */ + function checkNodePreviewOption($option, $preview = FALSE) { + $content_type = 'article'; + $label = 'Test'; + + // Create an admin user and log them in. + $perms = array( + // Needed for the content type. + 'create ' . $content_type . ' content', + 'edit any ' . $content_type . ' content', + + // Required for customizing the node preview option. + 'administer content types', + ); + $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. + $this->drupalLogin($this->adminUser); + + // Set the node preview mode. + $this->drupalGet('admin/structure/types/manage/' . $content_type); + $this->assertResponse(200); + $edit = array( + 'node_preview' => $option, + ); + $this->drupalPost(NULL, $edit, t('Save content type')); + $this->assertText(strip_tags(t('The content type %name has been updated.', array('%name' => t('Article'))))); + + // Create a test node. + $this->drupalGet('node/add/' . $content_type); + $this->assertResponse(200); + + // Save a custom meta tag. + $edit = array( + 'metatags[und][abstract][value]' => '[node:title] ponies', + 'title' => 'Who likes magic', + ); + + // A preview may be optionally performed. Core allows three combinations: + // * 0 = Disallowed. + // * 1 = Optional. + // * 2 = Required. + if (($option === 1 && $preview) || $option === 2) { + $this->drupalPost(NULL, $edit, t('Preview')); + $this->drupalPost(NULL, array(), t('Save')); + } + else { + $this->drupalPost(NULL, $edit, t('Save')); + } + $this->assertResponse(200); + + // Verify the title is using the custom default for this content type. + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertEqual($xpath[0]['content'], 'Who likes magic ponies'); + } + } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_node.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.node.with_i18n.test similarity index 92% rename from sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_node.test rename to sites/all/modules/contrib/seo/metatag/tests/metatag.node.with_i18n.test index 351ed8f5..424013c8 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_node.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.node.with_i18n.test @@ -1,18 +1,19 @@ 'Metatag core tests with i18n: node', + 'name' => 'Metatag core node tests with i18n', 'description' => 'Test Metatag node config integration with the i18n module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'i18n'), ); } @@ -27,6 +28,9 @@ class MetatagCoreWithI18nNodeTest extends MetatagTestHelper { // Enable all of the modules that are needed. parent::setUp($modules); + // Add more locales. + $this->setupLocales(); + // Set up the locales. $perms = array( 'administer languages', @@ -36,7 +40,9 @@ class MetatagCoreWithI18nNodeTest extends MetatagTestHelper { 'translate user-defined strings', ); $this->adminUser = $this->createAdminUser($perms); - $this->setupLocales(); + + // Log in the admin user. + $this->drupalLogin($this->adminUser); // Reload the translations. drupal_flush_all_caches(); diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.output_caching.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.output_caching.test new file mode 100644 index 00000000..dc637b6f --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.output_caching.test @@ -0,0 +1,123 @@ + 'Metatag: output caching', + 'description' => 'Test the output caching functionality in Metatag.', + 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), + ); + } + + /** + * Test how user tokens are handled when cache is enabled. + */ + public function testUserTokensCacheEnabled() { + // Enable output caching. + variable_set('metatag_cache_output', TRUE); + + // Create two user accounts. + $account1 = $this->drupalCreateUser(); + $account2 = $this->drupalCreateUser(); + + // Log in the first account. + $this->drupalLogin($account1); + + // Load the test page. + $this->drupalGet('account-test-page'); + $this->assertResponse(200); + + // Verify the page loaded correctly and has the correct title. + $this->assertText('Test page for user tokens.'); + $this->assertText('Hello ' . $account1->name); + $xpath = $this->xpath("//h1"); + $this->verbose($xpath); + $this->assertEqual(trim((string)$xpath[0]), 'Hello ' . $account1->name); + + // Confirm the page title itself. + $this->assertTitle('Hello ' . $account1->name . ' | Drupal'); + + // Log out the user. + $this->drupalLogout(). + + // Log in the second account. + $this->drupalLogin($account2); + + // Load the test page. + $this->drupalGet('account-test-page'); + $this->assertResponse(200); + + // Verify the page loaded correctly and now shows the second user account's + // name on the page. + $this->assertText('Test page for user tokens.'); + $this->assertText('Hello ' . $account2->name); + $xpath = $this->xpath("//h1"); + $this->verbose($xpath); + $this->assertEqual(trim((string)$xpath[0]), 'Hello ' . $account2->name); + + // Confirm the page title has not been updated, which is as designed. + $this->assertTitle('Hello ' . $account1->name . ' | Drupal'); + $this->assertNoTitle('Hello ' . $account2->name . ' | Drupal'); + } + + /** + * Test how user tokens are handled when cache is Disabled. + */ + public function testUserTokensCacheDisabled() { + // Disable output caching. + variable_set('metatag_cache_output', FALSE); + + // Create two user accounts. + $account1 = $this->drupalCreateUser(); + $account2 = $this->drupalCreateUser(); + + // Log in the first account. + $this->drupalLogin($account1); + + // Load the test page. + $this->drupalGet('account-test-page'); + $this->assertResponse(200); + + // Verify the page loaded correctly and has the correct title. + $this->assertText('Test page for user tokens.'); + $this->assertText('Hello ' . $account1->name); + $xpath = $this->xpath("//h1"); + $this->verbose($xpath); + $this->assertEqual(trim((string)$xpath[0]), 'Hello ' . $account1->name); + + // Confirm the page title itself. + $this->assertTitle('Hello ' . $account1->name . ' | Drupal'); + + // Log out the user. + $this->drupalLogout(). + + // Log in the second account. + $this->drupalLogin($account2); + + // Load the test page. + $this->drupalGet('account-test-page'); + $this->assertResponse(200); + + // Verify the page loaded correctly and now shows the second user account's + // name on the page. + $this->assertText('Test page for user tokens.'); + $this->assertText('Hello ' . $account2->name); + $xpath = $this->xpath("//h1"); + $this->verbose($xpath); + $this->assertEqual(trim((string)$xpath[0]), 'Hello ' . $account2->name); + + // Confirm the page title has changed, i.e. it shows the second account name + // rather than the first. + $this->assertNoTitle('Hello ' . $account1->name . ' | Drupal'); + $this->assertTitle('Hello ' . $account2->name . ' | Drupal'); + } + +} diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling.test index 6dd04b10..37933acb 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling.test @@ -1,11 +1,7 @@ 'Metatag core tests for string handling', 'description' => "Tests Metatag's string handling.", 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), ); } @@ -45,6 +42,8 @@ class MetatagCoreStringHandlingTest extends MetatagTestHelper { 'administer nodes', ); $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. $this->drupalLogin($this->adminUser); } @@ -176,6 +175,11 @@ class MetatagCoreStringHandlingTest extends MetatagTestHelper { ), ), ), + 'metatags' => array( + LANGUAGE_NONE => array( + 'abstract' => array('value' => '[node:title]'), + ), + ), )); // Page titles have a suffix added automatically. @@ -198,15 +202,7 @@ class MetatagCoreStringHandlingTest extends MetatagTestHelper { // Test a few other versions of the title, to ensure it isn't broken // on another tag. - $xpath = $this->xpath("//meta[@name='dcterms.title']"); - $this->assertEqual($xpath[0]['content'], $title_original); - $this->assertNotEqual($xpath[0]['content'], $title_encoded); - $this->assertNotEqual($xpath[0]['content'], $title_encodeded); - $xpath = $this->xpath("//meta[@property='og:title']"); - $this->assertEqual($xpath[0]['content'], $title_original); - $this->assertNotEqual($xpath[0]['content'], $title_encoded); - $this->assertNotEqual($xpath[0]['content'], $title_encodeded); - $xpath = $this->xpath("//meta[@name='twitter:title']"); + $xpath = $this->xpath("//meta[@name='abstract']"); $this->assertEqual($xpath[0]['content'], $title_original); $this->assertNotEqual($xpath[0]['content'], $title_encoded); $this->assertNotEqual($xpath[0]['content'], $title_encodeded); diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling_with_i18n.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling_with_i18n.test index 0d2b8447..f2cdd02d 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling_with_i18n.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.string_handling_with_i18n.test @@ -1,11 +1,7 @@ 'Metatag core tests for string handling w i18n', 'description' => "Tests Metatag's string handling when i18n is enabled.", 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'i18n'), ); } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.tags.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.tags.test new file mode 100644 index 00000000..3c4dc860 --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.tags.test @@ -0,0 +1,291 @@ + 'Metatag tags: Basic', + 'description' => 'Test the basic meta tags.', + 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), + ); + } + + /** + * {@inheritdoc} + */ + public $tags = array( + 'abstract', + 'cache-control', + 'canonical', + 'content-language', + 'description', + 'expires', + 'generator', + 'geo.placename', + 'geo.position', + 'geo.region', + 'icbm', + 'image_src', + 'keywords', + 'news_keywords', + 'next', + 'original-source', + 'pragma', + 'prev', + 'rating', + 'referrer', + 'refresh', + // @todo 'revisit-after', + 'rights', + 'robots', + 'shortlink', + 'standout', + 'title', + ); + + /** + * Implements {meta_tag_name}_test_field_xpath() for 'abstract'. + */ + public function abstract_test_field_xpath() { + return "//textarea[@name='metatags[und][abstract][value]']"; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'cache_control'. + */ + public function cache_control_test_output_xpath() { + return "//meta[@http-equiv='cache-control']"; + } + + /** + * Implements {meta_tag_name}_test_value_attribute() for 'canonical'. + */ + public function canonical_test_value_attribute() { + return 'href'; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'canonical'. + */ + public function canonical_test_output_xpath() { + return "//link[@rel='canonical']"; + } + + /** + * Implements {meta_tag_name}_test_name_attribute() for 'content_language'. + */ + public function content_language_test_name_attribute() { + return 'http-equiv'; + } + + /** + * Implements {meta_tag_name}_test_tag_name() for 'content_language'. + */ + public function content_language_test_tag_name() { + return 'content-language'; + } + + /** + * Implements {meta_tag_name}_test_field_xpath() for 'description'. + */ + public function description_test_field_xpath() { + return "//textarea[@name='metatags[und][description][value]']"; + } + + /** + * Implements {meta_tag_name}_test_tag_name() for 'geo_placename'. + */ + public function geo_placename_test_tag_name() { + return 'geo.placename'; + } + + /** + * Implements {meta_tag_name}_test_tag_name() for 'geo_position'. + */ + public function geo_position_test_tag_name() { + return 'geo.position'; + } + + /** + * Implements {meta_tag_name}_test_tag_name() for 'geo_region'. + */ + public function geo_region_test_tag_name() { + return 'geo.region'; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'image_src'. + */ + public function image_src_test_output_xpath() { + return "//link[@rel='image_src']"; + } + + /** + * Implements {meta_tag_name}_test_value_attribute() for 'image_src'. + */ + public function image_src_test_value_attribute() { + return 'href'; + } + + /** + * Implements {meta_tag_name}_test_value() for 'image_src'. + */ + public function image_src_test_value() { + return 'http://example.com/images/test-image.gif'; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'next'. + */ + public function next_test_output_xpath() { + return "//link[@rel='next']"; + } + + /** + * Implements {meta_tag_name}_test_value_attribute() for 'next'. + */ + public function next_test_value_attribute() { + return 'href'; + } + + /** + * Implements {meta_tag_name}_test_tag_name() for 'original-source'. + */ + public function original_source_test_tag_name() { + return 'original-source'; + } + + /** + * Implements {meta_tag_name}_test_name_attribute() for 'pragma'. + */ + public function pragma_test_name_attribute() { + return 'http-equiv'; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'prev'. + */ + public function prev_test_output_xpath() { + return "//link[@rel='prev']"; + } + + /** + * Implements {meta_tag_name}_test_value_attribute() for 'prev'. + */ + public function prev_test_value_attribute() { + return 'href'; + } + + /** + * Implements {meta_tag_name}_test_key() for 'rating'. + */ + public function rating_test_key() { + return 'metatags[und][rating][value]'; + } + + /** + * Implements {meta_tag_name}_test_value() for 'general'. + */ + public function rating_test_value() { + return 'general'; + } + + /** + * Implements {meta_tag_name}_test_field_xpath() for 'rating'. + */ + public function rating_test_field_xpath() { + return "//select[@name='metatags[und][rating][value]']"; + } + + /** + * Implements {meta_tag_name}_test_key() for 'referrer'. + */ + public function referrer_test_key() { + return 'metatags[und][referrer][value]'; + } + + /** + * Implements {meta_tag_name}_test_value() for 'referrer'. + */ + public function referrer_test_value() { + return 'origin'; + } + + /** + * Implements {meta_tag_name}_test_field_xpath() for 'referrer'. + */ + public function referrer_test_field_xpath() { + return "//select[@name='metatags[und][referrer][value]']"; + } + + /** + * Implements {meta_tag_name}_test_name_attribute() for 'refresh'. + */ + public function refresh_test_name_attribute() { + return 'http-equiv'; + } + + /** + * Implements {meta_tag_name}_test_value() for 'robots'. + */ + public function robots_test_key() { + return 'metatags[und][robots][value][index]'; + } + + /** + * Implements {meta_tag_name}_test_value() for 'robots'. + */ + public function robots_test_value() { + return TRUE; + } + + /** + * Implements {meta_tag_name}_test_field_xpath() for 'robots'. + */ + public function robots_test_field_xpath() { + return "//input[@name='metatags[und][robots][value][index]' and @type='checkbox']"; + } + + /** + * Implements {meta_tag_name}_test_value() for 'revisit-after'. + */ + public function revisit_after_test_value() { + return 2; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'shortlink'. + */ + public function shortlink_test_output_xpath() { + return "//link[@rel='shortlink']"; + } + + /** + * Implements {meta_tag_name}_test_value_attribute() for 'shortlink'. + */ + public function shortlink_test_value_attribute() { + return 'href'; + } + + /** + * Implements {meta_tag_name}_test_output_xpath() for 'title'. + */ + public function title_test_output_xpath() { + return "//title"; + } + + /** + * Implements {meta_tag_name}_test_value_attribute() for 'title'; + */ + public function title_test_value_attribute() { + return ''; + } + +} diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.tags_helper.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.tags_helper.test new file mode 100644 index 00000000..832e88ce --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.tags_helper.test @@ -0,0 +1,261 @@ +createAdminUser(); + $this->drupalLogin($account); + } + + /** + * Tests that this module's tags are available. + */ + function testTagsArePresent() { + // Load the global config. + $this->drupalGet('admin/config/search/metatags/config/global'); + $this->assertResponse(200); + + // Confirm the various meta tags are available. + foreach ($this->tags as $tag) { + // Convert tag names to something more suitable for a function name. + $tag_name = str_replace(array('.', '-', ':'), '_', $tag); + + // Look for a custom method named "{$tag_name}_test_field_xpath", if found + // use that method to get the xpath definition for this meta tag, + // otherwise it defaults to just looking for a text input field. + $method = "{$tag_name}_test_field_xpath"; + if (method_exists($this, $method)) { + $xpath = $this->$method(); + } + else { + $xpath = "//input[@name='metatags[und][{$tag}][value]' and @type='text']"; + } + $this->assertFieldByXPath($xpath, NULL, format_string('The "%tag" tag field was found.', array('%tag' => $tag))); + } + } + + /** + * Confirm that each tag can be saved and that the output of each tag is + * correct. + */ + function testTagsInputOutput() { + // Load the global config. + $this->drupalGet('admin/config/search/metatags/config/global'); + $this->assertResponse(200); + + // Update the Global defaults and test them. + $all_values = $values = array(); + foreach ($this->tags as $tag_raw) { + // Convert tag names to something more suitable for a function name. + $tag_name = str_replace(array('.', '-', ':', ' '), '_', $tag_raw); + + // Look for a custom method named "{$tag_name}_test_key", if found use + // that method to get the test string for this meta tag, otherwise it + // defaults to the meta tag's name. + $method = "{$tag_name}_test_key"; + if (method_exists($this, $method)) { + $test_key = $this->$method(); + } + else { + $test_key = "metatags[und][{$tag_raw}][value]"; + } + + // Look for a custom method named "{$tag_name}_test_value", if found use + // that method to get the test string for this meta tag, otherwise it + // defaults to just generating a random string. + $method = "{$tag_name}_test_value"; + if (method_exists($this, $method)) { + $test_value = $this->$method(); + } + else { + // Generate a random string. + $test_value = $this->getTestTagValue(); + } + + $values[$test_key] = $test_value; + + // Look for a custom method named "{$tag_name}_test_preprocess_output", if + // found use that method provide any additional processing on the value + // e.g. adding a prefix. + $method = "{$tag_name}_test_preprocess_output"; + if (method_exists($this, $method)) { + $test_value = $this->$method($test_value); + } + + $all_values[$tag_name] = $test_value; + } + $this->drupalPost(NULL, $values, 'Save'); + $this->assertText(strip_tags(t('The meta tag defaults for @label have been saved.', array('@label' => 'Global')))); + + // Load the test page. + $this->drupalGet('moosqueakoinkmeow'); + $this->assertResponse(200); + $this->assertText(t('Test page.')); + + // Look for the values. + foreach ($this->tags as $tag_raw) { + // Convert tag names to something more suitable for a function name. + $tag_name = str_replace(array('.', '-', ':', ' '), '_', $tag_raw); + + // Verify this meta tag was output. + $this->assertTrue(!empty($all_values[$tag_name])); + + // Look for a custom method named "{$tag_name}_test_output_xpath", if + // found use that method to get the xpath definition for this meta tag, + // otherwise it defaults to just looking for a meta tag matching: + // <$test_tag $test_name_attribute=$tag_name $test_value_attribute=$value /> + $method = "{$tag_name}_test_output_xpath"; + if (method_exists($this, $method)) { + $xpath_string = $this->$method(); + } + else { + // Look for a custom method named "{$tag_name}_test_tag", if + // found use that method to get the xpath definition for this meta tag, + // otherwise it defaults to $this->test_tag. + $method = "{$tag_name}_test_tag"; + if (method_exists($this, $method)) { + $xpath_tag = $this->$method(); + } + else { + $xpath_tag = $this->test_tag; + } + + // Look for a custom method named "{$tag_name}_test_name_attribute", if + // found use that method to get the xpath definition for this meta tag, + // otherwise it defaults to $this->test_name_attribute. + $method = "{$tag_name}_test_name_attribute"; + if (method_exists($this, $method)) { + $xpath_name_attribute = $this->$method(); + } + else { + $xpath_name_attribute = $this->test_name_attribute; + } + + // Look for a custom method named "{$tag_name}_test_tag_name", if + // found use that method to get the xpath definition for this meta tag, + // otherwise it defaults to $tag_name. + $method = "{$tag_name}_test_tag_name"; + if (method_exists($this, $method)) { + $xpath_name_tag = $this->$method(); + } + else { + $xpath_name_tag = $this->getTestTagName($tag_name); + } + + // Compile the xpath. + $xpath_string = "//{$xpath_tag}[@{$xpath_name_attribute}='{$xpath_name_tag}']"; + } + + // Something should have been found. + $this->assertTrue(!empty($xpath_string)); + + // Look for a custom method named "{$tag_name}_test_value_attribute", if + // found use that method to get the xpath definition for this meta tag, + // otherwise it defaults to $this->test_value_attribute. + $method = "{$tag_name}_test_value_attribute"; + if (method_exists($this, $method)) { + $xpath_value_attribute = $this->$method(); + } + else { + $xpath_value_attribute = $this->test_value_attribute; + } + + // Extract the meta tag from the HTML. + $xpath = $this->xpath($xpath_string); + $this->assertEqual(count($xpath), 1, format_string('One @name tag found.', array('@name' => $tag_name))); + + // Most meta tags have an attribute, but some don't. + if (!empty($xpath_value_attribute)) { + $this->assertTrue($xpath_value_attribute); + $this->assertTrue(isset($xpath[0][$xpath_value_attribute])); + // Help with debugging. + if (!isset($xpath[0][$xpath_value_attribute])) { + $this->verbose($xpath, $tag_name . ': ' . $xpath_string); + } + else { + if ((string)$xpath[0][$xpath_value_attribute] != $all_values[$tag_name]) { + $this->verbose($xpath, $tag_name . ': ' . $xpath_string); + } + $this->assertTrue($xpath[0][$xpath_value_attribute]); + $this->assertEqual($xpath[0][$xpath_value_attribute], $all_values[$tag_name]);//, "The meta tag was found with the expected value."); + } + } + else { + $this->verbose($xpath, $tag_name . ': ' . $xpath_string); + $this->assertTrue((string)$xpath[0]); + $this->assertEqual((string)$xpath[0], $all_values[$tag_name], "The meta tag was found with the expected value."); + } + } + } + + /** + * Convert a tag's internal name to the string which is actually used in HTML. + * + * The meta tag internal name will be machine names, i.e. only contain a-z, + * A-Z, 0-9 and the underline character. Meta tag names will actually contain + * any possible character. + * + * @param string $tag_name + * The tag name to be converted. + * + * @return string + * The converted tag name. + */ + public function getTestTagName($tag_name) { + return $tag_name; + } + + /** + * Generate a random value for testing meta tag fields. + * + * As a reasonable default, this will generating two words of 8 characters + * each with simple machine name -style strings. + * + * @return string + * A normal string. + */ + public function getTestTagValue() { + return $this->randomMachineName() . ' ' . $this->randomMachineName(); + } + + /** + * Generate a URL for an image. + * + * @return string + * An absolute URL to a non-existant image. + */ + public function randomImageUrl() { + return 'http://www.example.com/images/' . $this->randomMachineName() . '.png'; + } + +} diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.term.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.term.test index 5361c0bc..460eb232 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.term.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.term.test @@ -1,10 +1,10 @@ 'Metatag core tests for terms', 'description' => 'Test Metatag edit functionality for terms.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), ); } @@ -58,6 +59,8 @@ class MetatagCoreTermTest extends MetatagTestHelper { 'create url aliases', ); $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. $this->drupalLogin($this->adminUser); // Assign default values for the new vocabulary. @@ -80,9 +83,7 @@ class MetatagCoreTermTest extends MetatagTestHelper { // Submit the form with some values. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[term:name]', - 'metatags[und][dcterms.format][value]' => 'text/html', - 'metatags[und][dcterms.identifier][value]' => '[current-page:url:absolute]', + 'metatags[und][abstract][value]' => '[term:name]', ), t('Save')); $this->assertResponse(200); @@ -104,7 +105,7 @@ class MetatagCoreTermTest extends MetatagTestHelper { // Verify that it's possible to submit values to the form. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[term:name] ponies', + 'metatags[und][abstract][value]' => '[term:name] ponies', 'name' => $term_name, 'path[alias]' => $term_path, ), t('Save')); @@ -144,7 +145,7 @@ class MetatagCoreTermTest extends MetatagTestHelper { // Only the non-default values are stored. $expected = array( 'und' => array( - 'dcterms.subject' => array( + 'abstract' => array( 'value' => '[term:name] ponies', ), ), @@ -158,8 +159,8 @@ class MetatagCoreTermTest extends MetatagTestHelper { } // Verify the title is using the custom default for this vocabulary. - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); $this->assertEqual($xpath[0]['content'], "Who likes magic ponies"); } } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.term.with_i18n.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.term.with_i18n.test new file mode 100644 index 00000000..91070c91 --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.term.with_i18n.test @@ -0,0 +1,113 @@ + 'Metatag core term tests with i18n', + 'description' => 'Test Metatag taxonomy config integration with the i18n module.', + 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'i18n'), + ); + } + + /** + * {@inheritdoc} + */ + function setUp(array $modules = array()) { + // Need the i18n and i18n_strings modules. + $modules[] = 'i18n'; + $modules[] = 'i18n_string'; + + // Enable all of the modules that are needed. + parent::setUp($modules); + + // Add more locales. + $this->setupLocales(); + + // Set up the locales. + $perms = array( + 'administer languages', + 'translate interface', + // From i18n. + 'translate admin strings', + 'translate user-defined strings', + ); + $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. + $this->drupalLogin($this->adminUser); + + // Reload the translations. + drupal_flush_all_caches(); + module_load_include('admin.inc', 'i18n_string'); + i18n_string_refresh_group('metatag'); + } + + /** + * Test translations of the main taxonomy term configuration. + */ + public function testI18nTermConfig() { + // Plan out the different translation string tests. + $string_en = 'It is a term page!'; + $config_name = 'metatag_config:taxonomy_term:title'; + + // Confirm the translation page exists and has some Metatag strings. + $this->searchTranslationPage('', $config_name); + + // Confirm the string is not present yet. + $this->searchTranslationPage($string_en, $config_name, FALSE); + + // Load the meta tags. + $instance = 'taxonomy_term'; + $config = metatag_config_load($instance); + + // Set something specific as the homepage. + $config->config['title']['value'] = $string_en; + metatag_config_save($config); + + // Confirm the string is present now. + $this->searchTranslationPage($string_en, $config_name); + + // Get the translation string lid for the term's title. + $lid = $this->getTranslationLidByContext($config_name); + $this->assertNotEqual($lid, 0, 'Found the locales_source string for the taxonomy term title tag.'); + } + + /** + * Test translations of the 'tags' vocabulary configuration. + */ + public function testI18nTermTagsConfig() { + // Plan out the different translation string tests. + $string_en = 'It is a taxonomy term Tags page!'; + $config_name = 'metatag_config:taxonomy_term:tags:title'; + + // Confirm the translation page exists and has some Metatag strings. + $this->searchTranslationPage('', $config_name); + + // Confirm the string is not present yet. + $this->searchTranslationPage($string_en, $config_name, FALSE); + + // Create a new config object for the taxonomy_term:tags structure. + $config = new StdClass(); + $config->instance = 'taxonomy_term:tags'; + + // Set an example tag. + $config->config['title']['value'] = $string_en; + metatag_config_save($config); + + // Confirm the string is present now. + $this->searchTranslationPage($string_en, $config_name); + + // Get the translation string lid for the term's title. + $lid = $this->getTranslationLidByContext($config_name); + $this->assertNotEqual($lid, 0, 'Found the locales_source string for the taxonomy term title tag.'); + } + +} diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.unit.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.unit.test index 3049e69a..ec2d6fce 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.unit.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.unit.test @@ -1,18 +1,21 @@ 'Metatag unit tests', 'description' => 'Test basic meta tag functionality for entities.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), ); } @@ -34,6 +37,9 @@ class MetatagCoreUnitTest extends MetatagTestHelper { $this->assertEqual($defaults, $new_values); } + /** + * Test the basic entity handling. + */ public function testEntitySupport() { $test_cases[1] = array('type' => 'node', 'bundle' => 'article', 'expected' => TRUE); $test_cases[2] = array('type' => 'node', 'bundle' => 'page', 'expected' => TRUE); @@ -59,6 +65,19 @@ class MetatagCoreUnitTest extends MetatagTestHelper { } } + /** + * Confirm an entity supports meta tags. + * + * @param string $entity_type + * The name of the entity type to test. + * @param string $bundle + * The name of the entity bundle to test. + * @param array $expected + * The expected results. + * + * @return object + * An assertion. + */ function assertMetatagEntitySupportsMetatags($entity_type, $bundle, $expected) { $entity = entity_create_stub_entity($entity_type, array(0, NULL, $bundle)); return $this->assertEqual( diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.user.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.user.test index 3f42c80a..ea083a3c 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.user.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.user.test @@ -1,10 +1,10 @@ 'Metatag core tests for users', 'description' => 'Test Metatag edit functionality for users.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token'), ); } @@ -38,7 +39,7 @@ class MetatagCoreUserTest extends MetatagTestHelper { // Submit the form with some values. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[user:name]', + 'metatags[und][abstract][value]' => '[user:name]', ), t('Save')); $this->assertResponse(200); @@ -58,7 +59,7 @@ class MetatagCoreUserTest extends MetatagTestHelper { // Verify that it's possible to submit values to the form. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[user:name] ponies', + 'metatags[und][abstract][value]' => '[user:name] ponies', ), t('Save')); $this->assertResponse(200); @@ -76,7 +77,7 @@ class MetatagCoreUserTest extends MetatagTestHelper { // Only the non-default values are stored. $expected = array( 'und' => array( - 'dcterms.subject' => array( + 'abstract' => array( 'value' => '[user:name] ponies', ), ), @@ -87,21 +88,4 @@ class MetatagCoreUserTest extends MetatagTestHelper { $this->assertUserEntityTags($this->adminUser); } - /** - * Verify a user entity's meta tags load correctly. - * - * @param object $user - * A user object that is to be tested. - */ - function assertUserEntityTags($user) { - // Load the user's profile page. - $this->drupalGet('user/' . $user->uid); - $this->assertResponse(200); - - // Verify the title is using the custom default for this vocabulary. - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); - $this->assertEqual($xpath[0]['content'], $user->name . " ponies"); - } - } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_config.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_config.test index 95d0d17d..dcf7cf70 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_config.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_config.test @@ -1,10 +1,10 @@ 'Metatag core tests with i18n: configs', 'description' => 'Test Metatag configuration integration with the i18n module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'i18n'), ); } @@ -27,6 +28,9 @@ class MetatagCoreWithI18nConfigTest extends MetatagTestHelper { // Enable all of the modules that are needed. parent::setUp($modules); + // Add more locales. + $this->setupLocales(); + // Set up the locales. $perms = array( 'administer languages', @@ -40,7 +44,9 @@ class MetatagCoreWithI18nConfigTest extends MetatagTestHelper { 'administer nodes', ); $this->adminUser = $this->createAdminUser($perms); - $this->setupLocales(); + + // Log in the admin user. + $this->drupalLogin($this->adminUser); // Reload the translations. drupal_flush_all_caches(); diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_disabled.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_disabled.test index 82da280a..060f4783 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_disabled.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_disabled.test @@ -1,10 +1,10 @@ 'Metatag core tests with i18n disabled', 'description' => 'Test Metatag integration with the i18n module enabled but the integration disabled.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'i18n'), ); } @@ -27,6 +28,9 @@ class MetatagCoreWithI18nDisabledTest extends MetatagTestHelper { // Enable all of the modules that are needed. parent::setUp($modules); + // Add more locales. + $this->setupLocales(); + // Set up the locales. $perms = array( 'administer languages', @@ -36,7 +40,9 @@ class MetatagCoreWithI18nDisabledTest extends MetatagTestHelper { 'translate user-defined strings', ); $this->adminUser = $this->createAdminUser($perms); - $this->setupLocales(); + + // Log in the admin user. + $this->drupalLogin($this->adminUser); // Turn off i18n integration. variable_set('metatag_i18n_disabled', TRUE); diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_output.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_output.test index e5a227d4..73922fb2 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_output.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_i18n_output.test @@ -1,10 +1,10 @@ 'Metatag core tests with i18n: output', 'description' => 'Test Metatag integration with the i18n module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'i18n'), ); } @@ -27,6 +28,9 @@ class MetatagCoreWithI18nOutputTest extends MetatagTestHelper { // Enable all of the modules that are needed. parent::setUp($modules); + // Add more locales. + $this->setupLocales(); + // Set up the locales. $perms = array( 'administer languages', @@ -36,7 +40,9 @@ class MetatagCoreWithI18nOutputTest extends MetatagTestHelper { 'translate user-defined strings', ); $this->adminUser = $this->createAdminUser($perms); - $this->setupLocales(); + + // Log in the admin user. + $this->drupalLogin($this->adminUser); } /** diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_me.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_me.test new file mode 100644 index 00000000..a04ed2fd --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_me.test @@ -0,0 +1,68 @@ + 'Metatag core tests with Me', + 'description' => 'Test Metatag integration with the Me module.', + 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'me'), + ); + } + + /** + * {@inheritdoc} + */ + function setUp(array $modules = array()) { + $modules[] = 'me'; + + parent::setUp($modules); + } + + /** + * Make sure the /user/me path doesn't load any meta tags. + */ + public function testMePath() { + // Create an admin user and log them in. + if (!isset($this->adminUser)) { + $this->adminUser = $this->createAdminUser(); + } + $this->drupalLogin($this->adminUser); + + // Load the user's profile page. + // Load the 'me' page. + $this->drupalGet('user/' . $this->adminUser->uid); + $this->assertResponse(200); + + // Look for some meta tags that should exist. + $xpath = $this->xpath("//meta[@name='generator']"); + $this->assertEqual(count($xpath), 1, 'Exactly one generator meta tag found.'); + $this->assertEqual($xpath[0]['content'], 'Drupal 7 (http://drupal.org)'); + $xpath = $this->xpath("//link[@rel='canonical']"); + $this->assertEqual(count($xpath), 1, 'Exactly one canonical meta tag found.'); + $this->assertEqual($xpath[0]['href'], url('user/' . $this->adminUser->uid, array('absolute' => TRUE))); + $xpath = $this->xpath("//link[@rel='shortlink']"); + $this->assertEqual(count($xpath), 1, 'Exactly one shortlink meta tag found.'); + $this->assertEqual($xpath[0]['href'], url('user/' . $this->adminUser->uid, array('absolute' => TRUE))); + + // Load the 'me' page. + $this->drupalGet('user/me'); + $this->assertResponse(200); + + // Confirm the meta tags defined above don't exist. + $xpath = $this->xpath("//meta[@name='generator']"); + $this->assertEqual(count($xpath), 0, 'Did not find the generator meta tag.'); + $xpath = $this->xpath("//link[@rel='canonical']"); + $this->assertEqual(count($xpath), 0, 'Did not find the canonical meta tag.'); + $xpath = $this->xpath("//link[@rel='shortlink']"); + $this->assertEqual(count($xpath), 0, 'Did not find the shortlink meta tag.'); + } + +} diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_media.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_media.test index 9356eb37..41db779d 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_media.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_media.test @@ -1,9 +1,8 @@ 'Metatag core tests with Media', 'description' => 'Test Metatag integration with the Media module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'file_entity', 'media'), ); } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_panels.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_panels.test index 8fa5fbcb..5c923d27 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_panels.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_panels.test @@ -1,11 +1,11 @@ 'Metatag core tests with Panels', 'description' => 'Test Metatag integration with the Panels module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'panels', 'page_manager'), ); } @@ -51,6 +52,8 @@ class MetatagCoreWithPanelsTest extends MetatagTestHelper { 'administer page manager', ); $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. $this->drupalLogin($this->adminUser); // Create a test node. @@ -65,7 +68,7 @@ class MetatagCoreWithPanelsTest extends MetatagTestHelper { // Verify that it's possible to submit values to the form. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[node:title] ponies', + 'metatags[und][abstract][value]' => '[node:title] ponies', 'title' => 'Who likes magic', ), t('Save')); $this->assertResponse(200); @@ -148,8 +151,8 @@ class MetatagCoreWithPanelsTest extends MetatagTestHelper { } // Verify the title is using the custom default for this content type. - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); $this->assertEqual($xpath[0]['content'], 'Who likes magic ponies'); } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_profile2.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_profile2.test index b3077e12..4ff7d3c5 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_profile2.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_profile2.test @@ -1,11 +1,11 @@ 'Metatag core tests with Profile2', 'description' => 'Test Metatag integration with the Profile2 module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'profile2'), ); } @@ -56,7 +57,7 @@ class MetatagCoreWithProfile2Test extends MetatagCoreUserTest { // Verify that it's possible to submit values to the form. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[user:name] ponies', + 'metatags[und][abstract][value]' => '[user:name] ponies', ), t('Save')); $this->assertResponse(200); @@ -109,7 +110,7 @@ class MetatagCoreWithProfile2Test extends MetatagCoreUserTest { // Verify that it's possible to submit values to the form. $edit = array( - 'metatags[und][dcterms.subject][value]' => '[user:name] ponies', + 'metatags[und][abstract][value]' => '[user:name] ponies', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertResponse(200); diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_search_api.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_search_api.test index d8ec01e6..6c8ada29 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_search_api.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_search_api.test @@ -1,11 +1,7 @@ 'Metatag Search API tests', 'description' => 'Tests the Metatag Search API integration.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'entity', 'search_api'), ); } @@ -63,6 +60,8 @@ class MetatagCoreWithSearchAPITest extends MetatagTestHelper { 'administer search_api', ); $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. $this->drupalLogin($this->adminUser); // Create an index. diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_views.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_views.test index 00d5c3c9..b02a8f25 100644 --- a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_views.test +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_views.test @@ -1,11 +1,11 @@ 'Metatag core tests with Views', 'description' => 'Test Metatag integration with the Views module.', 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'views'), ); } @@ -58,6 +59,8 @@ class MetatagCoreWithViewsTest extends MetatagTestHelper { 'administer views', ); $this->adminUser = $this->createAdminUser($perms); + + // Log in the admin user. $this->drupalLogin($this->adminUser); // Load the "add default configuration" page. @@ -78,9 +81,7 @@ class MetatagCoreWithViewsTest extends MetatagTestHelper { // Submit the form with some values. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[term:name]', - 'metatags[und][dcterms.format][value]' => 'text/html', - 'metatags[und][dcterms.identifier][value]' => '[current-page:url:absolute]', + 'metatags[und][abstract][value]' => '[term:name]', ), t('Save')); $this->assertResponse(200); @@ -102,7 +103,7 @@ class MetatagCoreWithViewsTest extends MetatagTestHelper { // Verify that it's possible to submit values to the form. $this->drupalPost(NULL, array( - 'metatags[und][dcterms.subject][value]' => '[term:name] ponies', + 'metatags[und][abstract][value]' => '[term:name] ponies', 'name' => $term_name, 'path[alias]' => $term_path, ), t('Save')); @@ -133,7 +134,7 @@ class MetatagCoreWithViewsTest extends MetatagTestHelper { $this->assertResponse(200); $vars = variable_get('views_defaults'); - $this->verbose(print_r($vars, TRUE)); + $this->verbose($vars); $this->assertFalse($vars['taxonomy_term'], 'Taxonomy term page is enabled.'); // Load the page again. @@ -166,7 +167,7 @@ class MetatagCoreWithViewsTest extends MetatagTestHelper { // Only the non-default values are stored. $expected = array( 'und' => array( - 'dcterms.subject' => array( + 'abstract' => array( 'value' => '[term:name] ponies', ), ), @@ -180,8 +181,8 @@ class MetatagCoreWithViewsTest extends MetatagTestHelper { } // Verify the title is using the custom default for this vocabulary. - $xpath = $this->xpath("//meta[@name='dcterms.subject']"); - $this->assertEqual(count($xpath), 1, 'Exactly one dcterms.subject meta tag found.'); + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); $this->assertEqual($xpath[0]['content'], "Who likes magic ponies"); } diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.with_workbench_moderation.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_workbench_moderation.test new file mode 100644 index 00000000..98007d55 --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.with_workbench_moderation.test @@ -0,0 +1,113 @@ + 'Metatag core tests with Workbench Moderation v3', + 'description' => 'Test Metatag integration with the Workbench Moderation module (v3).', + 'group' => 'Metatag', + 'dependencies' => array('ctools', 'token', 'workbench_moderation'), + ); + } + + /** + * {@inheritdoc} + */ + function setUp(array $modules = array()) { + $modules[] = 'workbench_moderation'; + + parent::setUp($modules); + } + + /** + * Confirm that WM-based node edit workflows work properly. + */ + public function testNodeEdit() { + // Create a new content type and enable moderation on it. + $content_type = 'metatag_test'; + $content_type_path = str_replace('_', '-', $content_type); + $label = 'Test'; + $this->createContentType($content_type, $label); + variable_set('node_options_' . $content_type, array('revision', 'moderation')); + + // Create a brand new unpublished node programmatically. + $settings = array( + 'title' => 'Who likes magic', + 'type' => $content_type, + 'metatags' => array( + LANGUAGE_NONE => array( + 'abstract' => array('value' => '[node:title] ponies'), + ), + ), + 'status' => NODE_NOT_PUBLISHED, + ); + $node = $this->drupalCreateNode($settings); + + // Check that page is not published. + $this->drupalGet('node/' . $node->nid); + $this->assertResponse(403); + + // Create and login user. + $moderator_user = $this->drupalCreateUser(array( + 'access content', + 'view revisions', + 'view all unpublished content', + 'view moderation history', + 'view moderation messages', + 'bypass workbench moderation', + "create {$content_type} content", + "edit any {$content_type} content", + )); + $this->drupalLogin($moderator_user); + + // Publish the node via the moderation form. + $moderate = array('state' => workbench_moderation_state_published()); + $this->drupalPost("node/{$node->nid}/moderation", $moderate, t('Apply')); + + // Create draft with different node title. + $edit = array( + 'title' => 'I like magic', + ); + $this->drupalPost("node/{$node->nid}/edit", $edit, t('Save')); + + // Logout user. + $this->drupalLogout(); + + // Check that page is already published. + $this->drupalGet('node/' . $node->nid); + $this->assertResponse(200); + + // Verify the title is using the custom default for this content type. + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertEqual($xpath[0]['content'], 'Who likes magic ponies'); + + // Login user again. + $this->drupalLogin($moderator_user); + + // Publish draft via the moderation form. + $moderate = array('state' => workbench_moderation_state_published()); + $this->drupalPost("node/{$node->nid}/moderation", $moderate, t('Apply')); + + // Logout user. + $this->drupalLogout(); + + // Check that page is already published. + $this->drupalGet('node/' . $node->nid); + $this->assertResponse(200); + + // Verify the title is using the custom default for this content type. + $xpath = $this->xpath("//meta[@name='abstract']"); + $this->assertEqual(count($xpath), 1, 'Exactly one abstract meta tag found.'); + $this->assertEqual($xpath[0]['content'], 'I like magic ponies'); + } + +} diff --git a/sites/all/modules/contrib/seo/metatag/tests/metatag.xss.test b/sites/all/modules/contrib/seo/metatag/tests/metatag.xss.test new file mode 100644 index 00000000..9d2deb0c --- /dev/null +++ b/sites/all/modules/contrib/seo/metatag/tests/metatag.xss.test @@ -0,0 +1,190 @@ +alert("xss");'; + + /** + * String that causes an alert when metatags aren't filtered for xss. + * + * @var string + */ + private $xssString = '">'; + + /** + * String that causes an alert when metatags aren't filtered for xss. + * + * "Image" meta tags are processed differently to others, so this checks for a + * different string. + * + * @var string + */ + private $xssImageString = '/">'; + + /** + * {@inheritdoc} + */ + public static function getInfo() { + return array( + 'name' => 'Metatag core tests for XSS.', + 'description' => 'Test Metatag for XSS vulnerabilities.', + 'group' => 'Metatag', + ); + } + + /** + * {@inheritdoc} + */ + function setUp(array $modules = array()) { + parent::setUp($modules); + + $content_type = 'page'; + + // Create an admin user and log them in. + $perms = array( + // Needed for the content type. + 'create ' . $content_type . ' content', + 'delete any ' . $content_type . ' content', + 'edit any ' . $content_type . ' content', + + // This permission is required in order to create new revisions. + 'administer nodes', + ); + $this->adminUser = $this->createAdminUser($perms); + $this->drupalLogin($this->adminUser); + } + + /** + * Verify XSS injected in global Node config is not rendered. + */ + function testXssMetatagConfig() { + // Submit the form with some example XSS values. + $this->drupalGet('admin/config/search/metatags/config/global'); + $this->assertResponse(200); + $edit = array( + 'metatags[und][title][value]' => $this->xssTitleString, + 'metatags[und][abstract][value]' => $this->xssString, + 'metatags[und][image_src][value]' => $this->xssImageString, + ); + $this->drupalPost(NULL, $edit, t('Save')); + $this->assertResponse(200); + + // Use front page to test. + $this->drupalGet('