xmlsitemap_custom.test 5.18 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Unit tests for the xmlsitemap_custom.
6 7
 */

8 9 10
/**
 * Class with Functional Test for XML Sitemap Custom.
 */
11
class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
12 13 14 15

  /**
   * Get Info.
   */
16 17 18 19 20 21 22 23
  public static function getInfo() {
    return array(
      'name' => 'XML sitemap custom interface tests',
      'description' => 'Functional tests for the XML sitemap custom module.',
      'group' => 'XML sitemap',
    );
  }

24 25 26 27
  /**
   * Setup.
   */
  public function setUp($modules = array()) {
28 29 30
    $modules[] = 'xmlsitemap_custom';
    $modules[] = 'path';
    parent::setUp($modules);
31

32 33
    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
    $this->drupalLogin($this->admin_user);
34
  }
35

36 37 38 39
  /**
   * Test Custom Links.
   */
  public function testCustomLinks() {
40
    // Set a path alias for the node page.
41
    $alias = array('source' => 'system/files', 'alias' => 'public-files');
42
    path_save($alias);
43

44
    $this->drupalGet('admin/config/search/xmlsitemap/custom');
45 46 47 48 49 50
    $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'])));
51
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
52 53

    // Test a path not accessible to anonymous user.
54
    $edit['loc'] = 'admin/people/people';
55 56
    $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'])));
57
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
58 59 60

    // Test that the current page, which should not give a false positive for
    // $menu_item['access'] since the result has been cached already.
61
    $edit['loc'] = 'admin/config/search/xmlsitemap/custom/add';
62 63
    $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'])));
64
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
65 66

    // Add an aliased path with padded spaces.
67
    $edit['loc'] = ' public-files ';
68
    $this->drupalPost(NULL, $edit, t('Save'));
69
    $this->assertText('The custom link for system/files was saved');
70 71 72
    $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);
73 74 75 76 77 78
    $this->assertSitemapLinkValues('custom', $link['id'], array(
      'priority' => 0.5,
      'changefreq' => 0,
      'access' => 1,
      'status' => 1,
    ));
79 80 81 82 83 84 85 86

    $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');
87 88 89 90 91 92
    $this->assertSitemapLinkValues('custom', $link['id'], array(
      'priority' => 0.1,
      'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
      'access' => 1,
      'status' => 1,
    ));
93 94 95 96 97

    $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'));
98 99 100 101 102
  }

  /**
   * Test adding files as custom links.
   */
103
  public function testCustomFileLinks() {
104 105
    // Test an invalid file.
    $edit['loc'] = $this->randomName();
106
    $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
107
    $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
108
    $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
109 110

    // Test an unaccessible file .
111 112 113 114 115 116
    // @codingStandardsIgnoreStart
    // $edit['loc'] = '.htaccess';
    // $this->drupalPost('admin/config/search/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']));
    // @codingStandardsIgnoreEnd
117 118
    // Test a valid file.
    $edit['loc'] = 'misc/drupal.js';
119
    $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
120
    $this->assertText('The custom link for ' . $edit['loc'] . ' was saved');
121 122
    $links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => $edit['loc']));
    $this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
123 124 125

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

132
}