| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: xmlsitemap_node.test,v 1.1.2.24 2010/04/29 16:22:05 davereid Exp $ 3 4 /** 5 * @file 6 * Unit tests for the xmlsitemap_node module. 7 */ 8 9 class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper { 10 protected $normal_user; 11 protected $nodes = array(); 12 13 public static function getInfo() { 14 return array( 15 'name' => 'XML sitemap node', 16 'description' => 'Functional tests for the XML sitemap node module.', 17 'group' => 'XML sitemap', 18 ); 19 } 20 21 function setUp() { 22 parent::setUp('xmlsitemap_node', 'comment'); 23 24 $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'administer xmlsitemap')); 25 $this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content')); 26 xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5)); 27 } 28 29 function testNodeSettings() { 30 $node = $this->drupalCreateNode(array('status' => FALSE, 'uid' => $this->normal_user->uid)); 31 $this->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0)); 32 33 $this->drupalLogin($this->normal_user); 34 $this->drupalGet('node/' . $node->nid . '/edit'); 35 $this->assertNoField('xmlsitemap[status]'); 36 $this->assertNoField('xmlsitemap[priority]'); 37 38 $edit = array( 39 'title' => 'Test node title', 40 'body' => 'Test node body', 41 ); 42 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); 43 $this->assertText('Page Test node title has been updated.'); 44 $this->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0)); 45 46 $this->drupalLogin($this->admin_user); 47 $this->drupalGet('node/' . $node->nid . '/edit'); 48 $this->assertField('xmlsitemap[status]'); 49 $this->assertField('xmlsitemap[priority]'); 50 51 $edit = array( 52 'xmlsitemap[status]' => 0, 53 'xmlsitemap[priority]' => 0.9, 54 'status' => TRUE, 55 ); 56 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); 57 $node = node_load($node->nid); 58 $this->assertText('Page Test node title has been updated.'); 59 $this->assertSitemapLinkValues('node', $node->nid, array('access' => 1, 'status' => 0, 'priority' => 0.9, 'status_override' => 1, 'priority_override' => 1)); 60 61 $edit = array( 62 'xmlsitemap[status]' => 'default', 63 'xmlsitemap[priority]' => 'default', 64 'status' => FALSE, 65 ); 66 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); 67 $this->assertText('Page Test node title has been updated.'); 68 $this->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0)); 69 } 70 71 /** 72 * Test the content type settings. 73 */ 74 function testTypeSettings() { 75 $this->drupalLogin($this->admin_user); 76 77 $node_old = $this->drupalCreateNode(); 78 $this->assertSitemapLinkValues('node', $node_old->nid, array('status' => 1, 'priority' => 0.5)); 79 80 $edit = array( 81 'xmlsitemap[status]' => 0, 82 'xmlsitemap[priority]' => '0.0', 83 ); 84 $this->drupalPost('admin/content/node-type/page', $edit, t('Save content type')); 85 $this->assertText('The content type Page has been updated.'); 86 87 $node = $this->drupalCreateNode(); 88 $this->assertSitemapLinkValues('node', $node->nid, array('status' => 0, 'priority' => 0.0)); 89 $this->assertSitemapLinkValues('node', $node_old->nid, array('status' => 0, 'priority' => 0.0)); 90 91 $edit = array( 92 'type' => 'page2', 93 'xmlsitemap[status]' => 1, 94 'xmlsitemap[priority]' => '0.5', 95 ); 96 $this->drupalPost('admin/content/node-type/page', $edit, t('Save content type')); 97 $this->assertText('Changed the content type of 2 posts from page to page2.'); 98 $this->assertText('The content type Page has been updated.'); 99 100 $this->assertSitemapLinkValues('node', $node->nid, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5)); 101 $this->assertSitemapLinkValues('node', $node_old->nid, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5)); 102 $this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page'))), 0); 103 $this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page2'))), 2); 104 105 $this->drupalPost('admin/content/node-type/page2/delete', array(), t('Delete')); 106 $this->assertText('The content type Page has been deleted.'); 107 $this->assertFalse(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page2')), 'Nodes with deleted node type removed from {xmlsitemap}.'); 108 } 109 110 /** 111 * Test the import of old nodes via cron. 112 */ 113 function testCron() { 114 $limit = 5; 115 variable_set('xmlsitemap_batch_limit', $limit); 116 117 $nodes = array(); 118 for ($i = 1; $i <= ($limit + 1); $i++) { 119 $node = $this->drupalCreateNode(); 120 array_push($nodes, $node); 121 // Need to delay by one second so the nodes don't all have the same 122 // timestamp. 123 sleep(1); 124 } 125 126 // Clear all the node link data so we can emulate 'old' nodes. 127 db_query("DELETE FROM {xmlsitemap} WHERE type = 'node'"); 128 129 // Run cron to import old nodes. 130 xmlsitemap_node_cron(); 131 132 for ($i = 1; $i <= ($limit + 1); $i++) { 133 $node = array_pop($nodes); 134 if ($i <= $limit) { 135 // The first $limit nodes should be inserted. 136 $this->assertSitemapLinkValues('node', $node->nid, array('access' => 1, 'status' => 1, 'lastmod' => $node->changed)); 137 } 138 else { 139 // Any beyond $limit should not be in the sitemap. 140 $this->assertNoSitemapLink(array('type' => 'node', 'id' => $node->nid)); 141 } 142 } 143 } 144 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |