Commit c1d35966 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Cleaned up tests and added basic menu, taxonomy and user tests for now.

parent a6553960
......@@ -91,42 +91,50 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $link;
}
protected function assertSitemapLinkVisible() {
$links = func_get_args();
foreach ($links as $link) {
$this->assertTrue($link && $link['access'] && $link['status'], 'Sitemap link is visible.');
}
protected function assertSitemapLinkVisible($entity_type, $entity_id) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$this->assertTrue($link && $link['access'] && $link['status'], t('Sitemap link @type @id is visible.', array('@type' => $entity_type, '@id' => $entity_id)));
}
protected function assertSitemapLinkNotVisible() {
$links = func_get_args();
foreach ($links as $link) {
$this->assertTrue($link && !($link['access'] && $link['status']), 'Sitemap link is not visible.');
}
protected function assertSitemapLinkNotVisible($entity_type, $entity_id) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$this->assertTrue($link && !($link['access'] && $link['status']), t('Sitemap link @type @id is not visible.', array('@type' => $entity_type, '@id' => $entity_id)));
}
protected function assertSitemapLinkValues(array $link, array $conditions) {
protected function assertSitemapLinkValues($entity_type, $entity_id, array $conditions) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', array('@type' => $entity_type, '@id' => $entity_id)));
}
foreach ($conditions as $key => $value) {
if ($value === NULL || $link[$key] === NULL) {
// For nullable fields, always check for identical values (===).
$this->assertIdentical($link[$key], $value, t('Identical values for link field @key.', array('@key' => $key)));
$this->assertIdentical($link[$key], $value, t('Identical values for @type @id link field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
}
else {
// Otherwise check simple equality (==).
$this->assertEqual($link[$key], $value, t('Equal values for link field @key.', array('@key' => $key)));
$this->assertEqual($link[$key], $value, t('Equal values for @type @id link field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
}
}
}
protected function assertNotSitemapLinkValues(array $link, array $conditions) {
protected function assertNotSitemapLinkValues($entity_type, $entity_id, array $conditions) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', array('@type' => $entity_type, '@id' => $entity_id)));
}
foreach ($conditions as $key => $value) {
if ($value === NULL || $link[$key] === NULL) {
// For nullable fields, always check for identical values (===).
$this->assertNotIdentical($link[$key], $value, t('Not identical values for link field @key.', array('@key' => $key)));
$this->assertNotIdentical($link[$key], $value, t('Not identical values for @type @id link field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
}
else {
// Otherwise check simple equality (==).
$this->assertNotEqual($link[$key], $value, t('Not equal values for link field @key.', array('@key' => $key)));
$this->assertNotEqual($link[$key], $value, t('Not equal values for link @type @id field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
}
}
}
......
......@@ -7,8 +7,6 @@
*/
class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
protected $admin_user;
public static function getInfo() {
return array(
'name' => 'XML sitemap custom interface tests',
......@@ -19,6 +17,7 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
function setUp() {
parent::setUp('xmlsitemap_custom', 'path');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
}
......@@ -57,7 +56,7 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
$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);
$this->assertSitemapLinkValues($link, array('priority' => 0.5, 'changefreq' => 0, 'access' => 1, 'status' => 1));
$this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.5, 'changefreq' => 0, 'access' => 1, 'status' => 1));
$this->clickLink('Edit');
$edit = array(
......@@ -66,8 +65,7 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText('The custom link for system/files was saved');
$link = $this->assertSitemapLink('custom', $link['id']);
$this->assertSitemapLinkValues($link, array('priority' => 0.1, 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS, 'access' => 1, 'status' => 1));
$this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.1, 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS, 'access' => 1, 'status' => 1));
$this->clickLink('Delete');
$this->drupalPost(NULL, array(), t('Delete'));
......
......@@ -21,6 +21,12 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
parent::setUp('xmlsitemap_engines', 'xmlsitemap_engines_test');
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
$this->drupalLogin($this->admin_user);
// @todo For some reason the test client does not have clean URLs while
// the test runner does, so it causes mismatches in watchdog assertions
// later.
variable_set('clean_url', 0);
$this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
......
......@@ -7,3 +7,4 @@ dependencies[] = xmlsitemap
dependencies[] = menu
files[] = xmlsitemap_menu.module
files[] = xmlsitemap_menu.install
files[] = xmlsitemap_menu.test
......@@ -85,7 +85,6 @@ function xmlsitemap_menu_form_menu_edit_menu_alter(&$form, $form_state) {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_link_bundle_settings($form, $form_state, 'menu', $menu);
$form['#submit'][] = 'xmlsitemap_menu_menu_edit_menu_submit';
}
//function xmlsitemap_menu_form_menu_overview_form_alter(&$form, $form_state) {
......
<?php
// $Id$
/**
* @file
* Unit tests for the xmlsitemap_menu module.
*/
class XMLSitemapMenuFunctionalTest extends XMLSitemapTestHelper {
protected $normal_user;
protected $menu_items = array();
public static function getInfo() {
return array(
'name' => 'XML sitemap menu',
'description' => 'Functional tests for the XML sitemap menu module.',
'group' => 'XML sitemap',
);
}
function setUp() {
parent::setUp('xmlsitemap_menu', 'menu');
$this->admin_user = $this->drupalCreateUser(array('administer menu', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('access content'));
}
function testMenuSettings() {
$this->drupalLogin($this->admin_user);
$edit = array(
'title' => $this->randomName(),
'menu_name' => drupal_strtolower($this->randomName()),
'xmlsitemap[status]' => '1',
'xmlsitemap[priority]' => '1.0',
);
$this->drupalPost('admin/structure/menu/add', $edit, 'Save');
$menu = menu_load($edit['menu_name']);
$this->clickLink('Add link');
$edit = array(
'link_title' => $this->randomName(),
'link_path' => 'node',
'xmlsitemap[status]' => 'default',
'xmlsitemap[priority]' => 'default',
);
$this->drupalPost(NULL, $edit, 'Save');
}
}
......@@ -6,59 +6,31 @@
* Unit tests for the xmlsitemap_node module.
*/
class XMLSitemapNodeTestHelper extends XMLSitemapTestHelper {
protected $admin_user;
class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
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', 'view own unpublished content'));
xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5));
}
//function addNodes($count) {
// for ($i = count($this->nodes); $i < ($count + 1); $i++) {
// $this->nodes[$i] = $this->drupalCreateNode();
// }
//}
protected function assertNodeSitemapLinkVisible(stdClass $node) {
$link = xmlsitemap_link_load('node', $node->nid);
return $this->assertSitemapLinkVisible($link);
}
protected function assertNodeSitemapLinkNotVisible(stdClass $node) {
$link = xmlsitemap_link_load('node', $node->nid);
return $this->assertSitemapLinkNotVisible($link);
}
protected function assertNodeSitemapLinkValues(stdClass $node, array $values) {
$link = xmlsitemap_link_load('node', $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 XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
public static function getInfo() {
return array(
'name' => 'XML sitemap node functional tests',
'description' => 'Interface tests for the XML sitemap node module.',
'name' => 'XML sitemap node',
'description' => 'Functional tests for the XML sitemap node module.',
'group' => 'XML sitemap',
);
}
function setUp() {
parent::setUp('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', 'view own unpublished content'));
xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5));
}
function testNodeSettings() {
$body_field = 'body[' . LANGUAGE_NONE . '][0][value]';
$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->assertSitemapLinkValues('node', $node->nid, 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');
......@@ -71,7 +43,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('Basic 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->assertSitemapLinkValues('node', $node->nid, 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');
......@@ -85,7 +57,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertNodeSitemapLinkValues($node, array('access' => 1, 'status' => 0, 'priority' => 0.9, 'status_override' => 1, 'priority_override' => 1));
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 1, 'status' => 0, 'priority' => 0.9, 'status_override' => 1, 'priority_override' => 1));
$edit = array(
'xmlsitemap[status]' => 'default',
......@@ -94,7 +66,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('Basic 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->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
}
/**
......@@ -104,7 +76,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
$this->drupalLogin($this->admin_user);
$node_old = $this->drupalCreateNode();
$this->assertNodeSitemapLinkValues($node_old, array('status' => 1, 'priority' => 0.5));
$this->assertSitemapLinkValues('node', $node_old->nid, array('status' => 1, 'priority' => 0.5));
$edit = array(
'xmlsitemap[status]' => 0,
......@@ -114,8 +86,8 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
$this->assertText('The content type Basic 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));
$this->assertSitemapLinkValues('node', $node->nid, array('status' => 0, 'priority' => 0.0));
$this->assertSitemapLinkValues('node', $node_old->nid, array('status' => 0, 'priority' => 0.0));
$edit = array(
'type' => 'page2',
......@@ -126,8 +98,8 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
$this->assertText('Changed the content type of 2 posts from page to page2.');
$this->assertText('The content type Basic page has been updated.');
$this->assertNodeSitemapLinkValues($node, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertNodeSitemapLinkValues($node_old, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertSitemapLinkValues('node', $node->nid, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertSitemapLinkValues('node', $node_old->nid, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page'))), 0);
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page2'))), 2);
......@@ -143,7 +115,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
$this->drupalLogin($this->admin_user);
$limit = 5;
$this->drupalPost('admin/config/search/xmlsitemap', array('xmlsitemap_batch_limit' => $limit), t('Save configuration'));
$this->drupalPost('admin/config/search/xmlsitemap/settings', array('xmlsitemap_batch_limit' => $limit), t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$nodes = array();
......@@ -167,7 +139,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
$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));
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 1, 'status' => 1, 'lastmod' => $node->changed));
}
else {
// Any beyond $limit should not be in the sitemap.
......
......@@ -7,3 +7,4 @@ dependencies[] = xmlsitemap
dependencies[] = taxonomy
files[] = xmlsitemap_taxonomy.module
files[] = xmlsitemap_taxonomy.install
files[] = xmlsitemap_taxonomy.test
<?php
// $Id$
/**
* @file
* Unit tests for the xmlsitemap_taxonomy module.
*/
class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
protected $normal_user;
protected $terms = array();
public static function getInfo() {
return array(
'name' => 'XML sitemap taxonomy',
'description' => 'Functional tests for the XML sitemap taxonomy module.',
'group' => 'XML sitemap',
);
}
function setUp() {
parent::setUp('xmlsitemap_taxonomy', 'taxonomy');
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('access content'));
}
function testTaxonomySettings() {
$this->drupalLogin($this->admin_user);
$edit = array(
'name' => $this->randomName(),
'machine_name' => drupal_strtolower($this->randomName()),
'xmlsitemap[status]' => '1',
'xmlsitemap[priority]' => '1.0',
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, 'Save');
$this->assertText("Created new vocabulary {$edit['name']}.");
$vocabularies = taxonomy_vocabulary_get_names();
$vid = $vocabularies[$edit['machine_name']]->vid;
$vocabulary = taxonomy_vocabulary_load($vid);
$edit = array(
'name' => $this->randomName(),
'xmlsitemap[status]' => 'default',
'xmlsitemap[priority]' => 'default',
);
$this->drupalPost("admin/structure/taxonomy/$vid/add", $edit, 'Save');
}
}
......@@ -6,3 +6,4 @@ dependencies[] = xmlsitemap
core = 7.x
files[] = xmlsitemap_user.module
files[] = xmlsitemap_user.install
files[] = xmlsitemap_user.test
<?php
// $Id$
/**
* @file
* Unit tests for the xmlsitemap_user module.
*/
class XMLSitemapUserFunctionalTest extends XMLSitemapTestHelper {
protected $normal_user;
protected $accounts = array();
public static function getInfo() {
return array(
'name' => 'XML sitemap user',
'description' => 'Functional tests for the XML sitemap user module.',
'group' => 'XML sitemap',
);
}
function setUp() {
parent::setUp('xmlsitemap_user');
$this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('access content'));
xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 1, 'priority' => 0.5));
}
function testBlockedUser() {
$this->drupalLogin($this->admin_user);
$account = $this->drupalCreateUser();
$this->assertSitemapLinkVisible('user', $account->uid);
// Mark the user as blocked.
$edit = array(
'status' => 0,
);
// This will pass when http://drupal.org/node/360925 is fixed.
$this->drupalPost('user/' . $account->uid . '/edit', $edit, t('Save'));
$this->assertText(t('The changes have been saved.'));
$this->assertSitemapLinkNotVisible('user', $account->uid);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment