You are here

function XMLSitemapCustomFunctionalTest::testCustomFileLinks in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap_custom/xmlsitemap_custom.test \XMLSitemapCustomFunctionalTest::testCustomFileLinks()

Test adding files as custom links.

File

xmlsitemap_custom/xmlsitemap_custom.test, line 79
Unit tests for the xmlsitemap_custom module.

Class

XMLSitemapCustomFunctionalTest
@file Unit tests for the xmlsitemap_custom module.

Code

function testCustomFileLinks() {

  // Test an invalid file.
  $edit['loc'] = $this
    ->randomName();
  $this
    ->drupalPost('admin/settings/xmlsitemap/custom/add', $edit, t('Save'));
  $this
    ->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array(
    '@link' => $edit['loc'],
  )));
  $this
    ->assertNoSitemapLink(array(
    'type' => 'custom',
    'loc' => $edit['loc'],
  ));

  // Test an unaccessible file .

  //$edit['loc'] = '.htaccess';

  //$this->drupalPost('admin/settings/xmlsitemap/custom/add', $edit, t('Save'));

  //$this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));

  //$this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));

  // Test a valid file.
  $edit['loc'] = 'misc/drupal.js';
  $this
    ->drupalPost('admin/settings/xmlsitemap/custom/add', $edit, t('Save'));
  $this
    ->assertText('The custom link for ' . $edit['loc'] . ' was saved');
  $links = xmlsitemap_link_load_multiple(array(
    'type' => 'custom',
    'loc' => $edit['loc'],
  ));
  $this
    ->assertEqual(count($links), 1, t('Custom link saved in the database.'));

  // Test a valid folder.
  $edit['loc'] = 'misc';
  $this
    ->drupalPost('admin/settings/xmlsitemap/custom/add', $edit, t('Save'));
  $this
    ->assertText('The custom link for ' . $edit['loc'] . ' was saved');
  $links = xmlsitemap_link_load_multiple(array(
    'type' => 'custom',
    'loc' => $edit['loc'],
  ));
  $this
    ->assertEqual(count($links), 1, t('Custom link saved in the database.'));
}