xmlsitemap_custom.test 4.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php

/**
 * @file
 * Unit tests for the xmlsitemap_custom module.
 */

class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
  public static function getInfo() {
    return array(
      'name' => 'XML sitemap custom interface tests',
      'description' => 'Functional tests for the XML sitemap custom module.',
      'group' => 'XML sitemap',
    );
  }

17 18 19 20
  function setUp($modules = array()) {
    $modules[] = 'xmlsitemap_custom';
    $modules[] = 'path';
    parent::setUp($modules);
21

22 23
    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
    $this->drupalLogin($this->admin_user);
24
  }
25

26
  function testCustomLinks() {
27
    // Set a path alias for the node page.
28
    $alias = array('source' => 'system/files', 'alias' => 'public-files');
29
    path_save($alias);
30

31
    $this->drupalGet('admin/config/search/xmlsitemap/custom');
32 33 34 35 36 37
    $this->clickLink(t('Add custom link'));

    // Test an invalid path.
    $edit['loc'] = 'invalid-testing-path';
    $this->drupalPost(NULL, $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'])));
38
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
39 40

    // Test a path not accessible to anonymous user.
41
    $edit['loc'] = 'admin/people/people';
42 43
    $this->drupalPost(NULL, $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'])));
44
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
45 46 47

    // Test that the current page, which should not give a false positive for
    // $menu_item['access'] since the result has been cached already.
48
    $edit['loc'] = 'admin/config/search/xmlsitemap/custom/add';
49 50
    $this->drupalPost(NULL, $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'])));
51
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
52 53

    // Add an aliased path with padded spaces.
54
    $edit['loc'] = ' public-files ';
55
    $this->drupalPost(NULL, $edit, t('Save'));
56
    $this->assertText('The custom link for system/files was saved');
57 58 59
    $links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => 'system/files'));
    $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
    $link = reset($links);
60
    $this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.5, 'changefreq' => 0, 'access' => 1, 'status' => 1));
61 62 63 64 65 66 67 68

    $this->clickLink('Edit');
    $edit = array(
      'priority' => 0.1,
      'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
    );
    $this->drupalPost(NULL, $edit, t('Save'));
    $this->assertText('The custom link for system/files was saved');
69
    $this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.1, 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS, 'access' => 1, 'status' => 1));
70 71 72 73 74

    $this->clickLink('Delete');
    $this->drupalPost(NULL, array(), t('Delete'));
    $this->assertText('The custom link for system/files has been deleted.');
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => 'system/files'));
75 76 77 78 79 80 81 82
  }

  /**
   * Test adding files as custom links.
   */
  function testCustomFileLinks() {
    // Test an invalid file.
    $edit['loc'] = $this->randomName();
83
    $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
84
    $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
85
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
86 87 88

    // Test an unaccessible file .
    //$edit['loc'] = '.htaccess';
89
    //$this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
90
    //$this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
91
    //$this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
92 93 94

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

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