function PathautoFunctionalTestCase::testNodeEditing in Pathauto 7
Same name and namespace in other branches
- 6.2 pathauto.test \PathautoFunctionalTestCase::testNodeEditing()
- 6 pathauto.test \PathautoFunctionalTestCase::testNodeEditing()
Basic functional testing of Pathauto.
File
- ./
pathauto.test, line 454 - Functionality tests for Pathauto.
Class
- PathautoFunctionalTestCase
- Test basic pathauto functionality.
Code
function testNodeEditing() {
// Delete the default node pattern. Only the page content type will have a pattern.
variable_del('pathauto_node_pattern');
// Ensure that the Pathauto checkbox is checked by default on the node add form.
$this
->drupalGet('node/add/page');
$this
->assertFieldChecked('edit-path-pathauto');
// Create node for testing by previewing and saving the node form.
$title = ' Testing: node title [';
$automatic_alias = 'content/testing-node-title';
$this
->drupalPost(NULL, array(
'title' => $title,
), 'Preview');
$this
->drupalPost(NULL, array(), 'Save');
$node = $this
->drupalGetNodeByTitle($title);
// Look for alias generated in the form.
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertFieldChecked('edit-path-pathauto');
$this
->assertFieldByName('path[alias]', $automatic_alias, 'Generated alias visible in the path alias field.');
// Check whether the alias actually works.
$this
->drupalGet($automatic_alias);
$this
->assertText($title, 'Node accessible through automatic alias.');
// Disable the update action. The checkbox should not be visible.
variable_set('pathauto_update_action', 0);
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertNoFieldById('edit-path-pathauto');
// Reset the update action back to default. The checkbox should be visible.
variable_del('pathauto_update_action');
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertFieldChecked('edit-path-pathauto');
// Manually set the node's alias.
$manual_alias = 'content/' . $node->nid;
$edit = array(
'path[pathauto]' => FALSE,
'path[alias]' => $manual_alias,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText("Basic page {$title} has been updated.");
// Check that the automatic alias checkbox is now unchecked by default.
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertNoFieldChecked('edit-path-pathauto');
$this
->assertFieldByName('path[alias]', $manual_alias);
// Submit the node form with the default values.
$this
->drupalPost(NULL, array(), t('Save'));
$this
->assertText("Basic page {$title} has been updated.");
// Test that the old (automatic) alias has been deleted and only accessible
// through the new (manual) alias.
$this
->drupalGet($automatic_alias);
$this
->assertResponse(404, 'Node not accessible through automatic alias.');
$this
->drupalGet($manual_alias);
$this
->assertText($title, 'Node accessible through manual alias.');
// Now attempt to create a node that has no pattern (article content type).
// The Pathauto checkbox should not exist.
$this
->drupalGet('node/add/article');
$this
->assertNoFieldById('edit-path-pathauto');
$this
->assertFieldByName('path[alias]', '');
$edit = array();
$edit['title'] = 'My test article';
$this
->drupalPost(NULL, $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title']);
// Pathauto checkbox should still not exist.
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertNoFieldById('edit-path-pathauto');
$this
->assertFieldByName('path[alias]', '');
$this
->assertNoEntityAlias('node', $node);
// Set the page pattern to use only tokens so we can test the checkbox
// behavior if none of the tokens have a value currently.
variable_set('pathauto_node_page_pattern', '[node:title]');
// Create a node with an empty title. The Pathauto checkbox should still be
// visible but unchecked.
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'title' => '',
));
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertNoFieldChecked('edit-path-pathauto');
$this
->assertFieldByName('path[alias]', '');
$this
->assertNoEntityAlias('node', $node);
$edit = array();
$edit['title'] = 'Valid title';
$edit['path[pathauto]'] = TRUE;
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertFieldChecked('edit-path-pathauto');
$this
->assertFieldByName('path[alias]', 'valid-title');
}