123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- /**
- * @file
- * Tests for the Metatag Favicons module.
- */
- class MetatagFaviconsTest extends MetatagTestHelper {
- /**
- * {@inheritdoc}
- */
- public static function getInfo() {
- return array(
- 'name' => 'Metatag Favicons tests',
- 'description' => 'Test the Metatag:Favicons module.',
- 'group' => 'Metatag',
- );
- }
- /**
- * {@inheritdoc}
- */
- function setUp(array $modules = array()) {
- $modules[] = 'metatag_favicons';
- parent::setUp($modules);
- // Create an admin user and log them in.
- $this->adminUser = $this->createAdminUser();
- $this->drupalLogin($this->adminUser);
- }
- /**
- * Confirm that it's possible to load the main admin page.
- */
- public function testAdminPage() {
- $this->drupalGet('admin/config/search/metatags');
- $this->assertResponse(200);
- // Confirm the page is correct.
- $this->assertText(t('To view a summary of the default meta tags and the inheritance, click on a meta tag type.'));
- }
- /**
- * Confirm the mask-icon meta tag works correctly.
- */
- public function testMaskIconValue() {
- // The SVG image is copied from the archive obtained from
- // https://www.drupal.org/about/media-kit/logos on 6/20/2016.
- $svg_path = drupal_get_path('module', 'metatag_favicons') . '/tests/druplicon-vector.svg';
- $relative_path = url($svg_path, array('absolute' => FALSE));
- $absolute_path = url($svg_path, array('absolute' => TRUE));
- // Testbot doesn't have "clean_url" enabled.
- $relative_path = str_replace('?q=', '', $relative_path);
- $absolute_path = str_replace('?q=', '', $absolute_path);
- // Try filling in a path relative to the Drupal installation.
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $svg_path;
- metatag_config_save($config);
- // Load the config page.
- $this->drupalGet('admin/config/search/metatags');
- $this->assertResponse(200);
- // Confirm the meta tag's value is on the page.
- $this->assertText(t('Icon: SVG') . ':');
- $this->assertText($absolute_path);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertNotEqual((string)$xpath[0]['href'], $svg_path);
- $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
- // Before proceeding, clear the site's caches.
- drupal_flush_all_caches();
- // Try filling in a relative path.
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $relative_path;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertNotEqual((string)$xpath[0]['href'], $svg_path);
- $this->assertNotEqual((string)$xpath[0]['href'], $relative_path);
- // Before proceeding, clear the site's caches.
- drupal_flush_all_caches();
- // Test filling in an absolute path.
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $absolute_path;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertNotEqual((string)$xpath[0]['href'], $svg_path);
- $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
- // Before proceeding, clear the site's caches.
- drupal_flush_all_caches();
- // Test filling in an absolute path for an external file
- $path = 'https://www.example.com/example.svg';
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $path;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertNotEqual((string)$xpath[0]['href'], $absolute_path);
- $this->assertEqual((string)$xpath[0]['href'], $path);
- }
- /**
- * Confirm the mask-icon meta tag 'color' attribute works correctly.
- */
- public function testMaskIconColor() {
- // The SVG image is copied from the archive obtained from
- // https://www.drupal.org/about/media-kit/logos on 6/20/2016.
- $svg_path = drupal_get_path('module', 'metatag_favicons') . '/tests/druplicon-vector.svg';
- $absolute_path = url($svg_path, array('absolute' => TRUE));
- // Testbot doesn't have "clean_url" enabled.
- $absolute_path = str_replace('?q=', '', $absolute_path);
- // Try a color string.
- $color = 'red';
- // Update the global config.
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $svg_path;
- $config->config['mask-icon']['color'] = $color;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
- $this->assertEqual((string)$xpath[0]['color'], $color);
- // Before proceeding, clear the site's caches.
- drupal_flush_all_caches();
- // Try a color hex code.
- $color = '#990000';
- // Update the global config.
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $svg_path;
- $config->config['mask-icon']['color'] = $color;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
- $this->assertEqual((string)$xpath[0]['color'], $color);
- // Try a color RGB value.
- $color = 'rgb(153, 0, 0)';
- // Update the global config.
- $config = metatag_config_load('global');
- $config->config['mask-icon']['value'] = $svg_path;
- $config->config['mask-icon']['color'] = $color;
- metatag_config_save($config);
- // Load the front page.
- $this->drupalGet('<front>');
- $this->assertResponse(200);
- // Confirm the meta tag is present.
- $xpath = $this->xpath("//link[@rel='mask-icon']");
- $this->assertEqual(count($xpath), 1, 'One mask-icon meta tag found.');
- $this->assertEqual((string)$xpath[0]['href'], $absolute_path);
- $this->assertEqual((string)$xpath[0]['color'], $color);
- }
- }
|