/** * Test adding files as custom links. */ public function testCustomFileLinks() { // Test an invalid file. $edit['loc'] = $this->randomMachineName(); $this->drupalPostForm('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'])); // Test an unaccessible file . $edit['loc'] = '.htaccess'; $this->drupalPostForm('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'])); // Test a valid file. $edit['loc'] = 'core/misc/drupal.js'; $this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save')); $this->assertText(t('The custom link for @link was saved.', array('@link' => $edit['loc']))); $links = $this->linkStorage->loadMultiple(array('type' => 'custom', 'loc' => $edit['loc'])); $this->assertEqual(count($links), 1, t('Custom link saved in the database.')); //Test a duplicate url. $edit['loc'] = 'core/misc/drupal.js'; $this->drupalPostForm('admin/config/search/xmlsitemap/custom/add', $edit, t('Save')); $this->assertText(t('There is already an existing link in the sitemap with the path @link.', array('@link' => $edit['loc']))); $links = $this->linkStorage->loadMultiple(array('type' => 'custom', 'loc' => $edit['loc'])); $this->assertEqual(count($links), 1, t('Custom link saved in the database.')); }
protected function assertNoSitemapLink($entity_type, $entity_id = NULL) { if (is_array($entity_type)) { $links = $this->linkStorage->loadMultiple($entity_type); $link = $links ? reset($links) : FALSE; } else { $link = $this->linkStorage->load($entity_type, $entity_id); } $this->assertFalse($link, 'Link not loaded.'); return $link; }