123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- // $Id: xmlsitemap_node.test,v 1.7 2010/01/24 07:21:22 davereid Exp $
- /**
- * @file
- * Unit tests for the xmlsitemap_node module.
- */
- class XMLSitemapNodeTestHelper extends XMLSitemapTestHelper {
- protected $admin_user;
- protected $normal_user;
- protected $nodes = array();
- function setUp() {
- parent::setUp('xmlsitemap', 'xmlsitemap_node', 'comment');
- $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap'));
- $this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content'));
- variable_set('xmlsitemap_node_status_page', 1);
- }
- //function addNodes($count) {
- // for ($i = count($this->nodes); $i < ($count + 1); $i++) {
- // $this->nodes[$i] = $this->drupalCreateNode();
- // }
- //}
- protected function assertNodeSitemapLinkVisible(stdClass $node) {
- $link = xmlsitemap_load_link(array('type' => 'node', 'id' => $node->nid));
- return $this->assertSitemapLinkVisible($link);
- }
- protected function assertNodeSitemapLinkNotVisible(stdClass $node) {
- $link = xmlsitemap_load_link(array('type' => 'node', 'id' => $node->nid));
- return $this->assertSitemapLinkNotVisible($link);
- }
- protected function assertNodeSitemapLinkValues(stdClass $node, array $values) {
- $link = xmlsitemap_load_link(array('type' => 'node', 'id' => $node->nid));
- if (!$link) {
- $this->fail(t('Could not load sitemap link for node @nid.', array('@nid' => $node->nid)));
- }
- else {
- $this->assertSitemapLinkValues($link, $values);
- }
- }
- }
- //class XMLSitemapNodeUnitTest extends DrupalWebTestCase {
- // public static function getInfo() {
- // return array(
- // 'name' => 'XML Sitemap node unit tests',
- // 'description' => 'Unit tests for the XML Sitemap node module.',
- // 'group' => 'XML Sitemap',
- // );
- // }
- //
- // function setUp() {
- // parent::setUp('xmlsitemap', 'xmlsitemap_node');
- // }
- //}
- class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
- public static function getInfo() {
- return array(
- 'name' => 'XML sitemap node functional tests',
- 'description' => 'Interface tests for the XML sitemap node module.',
- 'group' => 'XML sitemap',
- );
- }
- function testNodeSettings() {
- $node = $this->drupalCreateNode(array('status' => FALSE, 'uid' => $this->normal_user->uid));
- $this->assertNodeSitemapLinkValues($node, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
- $this->drupalLogin($this->normal_user);
- $this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertNoField('xmlsitemap[status]');
- $this->assertNoField('xmlsitemap[priority]');
- $edit = array(
- 'title' => 'Test node title',
- 'body' => 'Test node body',
- );
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertText('Page Test node title has been updated.');
- $this->assertNodeSitemapLinkValues($node, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
- $this->drupalLogin($this->admin_user);
- $this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertField('xmlsitemap[status]');
- $this->assertField('xmlsitemap[priority]');
- $edit = array(
- 'xmlsitemap[status]' => 0,
- 'xmlsitemap[priority]' => 0.9,
- 'status' => TRUE,
- );
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertText('Page Test node title has been updated.');
- $this->assertNodeSitemapLinkValues($node, array('access' => 1, 'status' => 0, 'priority' => 0.9, 'status_override' => 1, 'priority_override' => 1));
- $edit = array(
- 'xmlsitemap[status]' => 'default',
- 'xmlsitemap[priority]' => 'default',
- 'status' => FALSE,
- );
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertText('Page Test node title has been updated.');
- $this->assertNodeSitemapLinkValues($node, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
- }
- /**
- * Test the content type settings.
- */
- function testTypeSettings() {
- $this->drupalLogin($this->admin_user);
- $node_old = $this->drupalCreateNode();
- $this->assertNodeSitemapLinkValues($node_old, array('status' => 1, 'priority' => 0.5));
- $edit = array(
- 'xmlsitemap_node_status' => 0,
- 'xmlsitemap_node_priority' => '0.0',
- );
- $this->drupalGet('admin/content/node-type/page');
- $this->drupalPost('admin/content/node-type/page', $edit, t('Save content type'));
- $this->assertText(t('The content type Page has been updated.'));
- $node = $this->drupalCreateNode();
- $this->assertNodeSitemapLinkValues($node, array('status' => 0, 'priority' => 0.0));
- $this->assertNodeSitemapLinkValues($node_old, array('status' => 0, 'priority' => 0.0));
- $edit = array(
- 'xmlsitemap_node_status' => 1,
- 'xmlsitemap_node_priority' => '0.5',
- );
- $this->drupalPost('admin/content/node-type/page', $edit, t('Save content type'));
- $this->assertText(t('The content type Page has been updated.'));
- $this->assertNodeSitemapLinkValues($node, array('status' => 1, 'priority' => 0.5));
- $this->assertNodeSitemapLinkValues($node_old, array('status' => 1, 'priority' => 0.5));
- //$this->drupalPost('node/' . $node->nid . '/edit', array(), t('Save'));
- //$this->assertText(t('Page @title has been updated.', array('@title' => $node->title)));
- }
- /**
- * Test the import of old nodes via cron.
- */
- function testCron() {
- $this->drupalLogin($this->admin_user);
- $limit = 5;
- $this->drupalPost('admin/config/search/xmlsitemap', array('xmlsitemap_batch_limit' => $limit), t('Save configuration'));
- $this->assertText(t('The configuration options have been saved.'));
- $nodes = array();
- for ($i = 1; $i <= ($limit + 1); $i++) {
- $node = $this->drupalCreateNode();
- array_push($nodes, $node);
- // Need to delay by one second so the nodes don't all have the same
- // timestamp.
- sleep(1);
- }
- // Clear all the node link data so we can emulate 'old' nodes.
- db_delete('xmlsitemap')
- ->condition('type', 'node')
- ->execute();
- // Run cron to import old nodes.
- xmlsitemap_node_cron();
- for ($i = 1; $i <= ($limit + 1); $i++) {
- $node = array_pop($nodes);
- if ($i <= $limit) {
- // The first $limit nodes should be inserted.
- $this->assertNodeSitemapLinkValues($node, array('access' => 1, 'status' => 1, 'lastmod' => $node->changed));
- }
- else {
- // Any beyond $limit should not be in the sitemap.
- $this->assertNoSitemapLink(array('type' => 'node', 'id' => $node->nid));
- }
- }
- }
- }
|