summaryrefslogtreecommitdiff
path: root/modules/path
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-04-20 18:24:07 +0000
committerDries Buytaert <dries@buytaert.net>2008-04-20 18:24:07 +0000
commitaf474609e3e80db9ba1d16b9ad2eae89775f51c8 (patch)
treee525479dd6381b94d21943c3d2decf1c749c028c /modules/path
parentfe7b9baff62379f5a0c901d27cbb677345791bd0 (diff)
downloadbrdo-af474609e3e80db9ba1d16b9ad2eae89775f51c8.tar.gz
brdo-af474609e3e80db9ba1d16b9ad2eae89775f51c8.tar.bz2
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable the module and check it out ... :) Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran Lal, Moshe Weitzman, and the many other people that helped with testing over the past years and that drove this home. It all works but it is still rough around the edges (i.e. documentation is still being written, the coding style is not 100% yet, a number of tests still fail) but we spent the entire weekend working on it in Paris and made a ton of progress. The best way to help and to get up to speed, is to start writing and contributing some tests ... as well as fixing some of the failures. For those willing to help with improving the test framework, here are some next steps and issues to resolve: - How to best approach unit tests and mock functions? - How to test drupal_mail() and drupal_http_request()? - How to improve the admin UI so we have a nice progress bar? - How best to do code coverage? - See http://g.d.o/node/10099 for more ...
Diffstat (limited to 'modules/path')
-rw-r--r--modules/path/path.test139
1 files changed, 139 insertions, 0 deletions
diff --git a/modules/path/path.test b/modules/path/path.test
new file mode 100644
index 000000000..f12322966
--- /dev/null
+++ b/modules/path/path.test
@@ -0,0 +1,139 @@
+<?php
+// $Id$
+
+class PathTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Path alias functionality'),
+ 'description' => t('Add, edit, delete, and change alias and verify its consistency in the database.'),
+ 'group' => t('Path'),
+ );
+ }
+
+ /**
+ * Create user, setup permissions, log user in, and create a node.
+ */
+ function setUp() {
+ parent::setUp('path');
+ // create and login user
+ $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content', 'administer url aliases', 'create url aliases'));
+ $this->drupalLogin($web_user);
+ }
+
+ /**
+ * Test alias functionality through the admin interfaces.
+ */
+ function testAdminAlias() {
+ // create test node
+ $node1 = $this->createNode();
+
+ // create alias
+ $edit = array();
+ $edit['src'] = 'node/' . $node1->nid;
+ $edit['dst'] = $this->randomName(8);
+ $this->drupalPost('admin/build/path/add', $edit, t('Create new alias'));
+
+ // confirm that the alias works
+ $this->drupalGet($edit['dst']);
+ $this->assertText($node1->title, 'Alias works.');
+
+ // change alias
+ $pid = $this->getPID($edit['dst']);
+
+ $previous = $edit['dst'];
+ $edit['dst'] = $this->randomName(8);
+ $this->drupalPost('admin/build/path/edit/' . $pid, $edit, t('Update alias'));
+
+ // confirm that the alias works
+ $this->drupalGet($edit['dst']);
+ $this->assertText($node1->title, 'Changed alias works.');
+
+ // make sure that previous alias no longer works
+ $this->drupalGet($previous);
+ $this->assertNoText($node1->title, 'Previous alias no longer works.');
+ $this->assertResponse(404);
+
+ // create second test node
+ $node2 = $this->createNode();
+
+ // set alias to second test node
+ $edit['src'] = 'node/' . $node2->nid;
+ // leave $edit['dst'] the same
+ $this->drupalPost('admin/build/path/add', $edit, t('Create new alias'));
+
+ // confirm that the alias didn't make a duplicate
+ $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['dst'])), 'Attempt to move alias was rejected.');
+
+ // delete alias
+ $this->drupalPost('admin/build/path/delete/' . $pid, array(), t('Confirm'));
+
+ // confirm that the alias no longer works
+ $this->drupalGet($edit['dst']);
+ $this->assertNoText($node1->title, 'Alias was successfully deleted.');
+ }
+
+ /**
+ * Test alias functionality through the node interfaces.
+ */
+ function testNodeAlias() {
+ // create test node
+ $node1 = $this->createNode();
+
+ // create alias
+ $edit = array();
+ $edit['path'] = $this->randomName(8);
+ $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
+
+ // confirm that the alias works
+ $this->drupalGet($edit['path']);
+ $this->assertText($node1->title, 'Alias works.');
+
+ // change alias
+ $previous = $edit['path'];
+ $edit['path'] = $this->randomName(8);
+ $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
+
+ // confirm that the alias works
+ $this->drupalGet($edit['path']);
+ $this->assertText($node1->title, 'Changed alias works.');
+
+ // make sure that previous alias no longer works
+ $this->drupalGet($previous);
+ $this->assertNoText($node1->title, 'Previous alias no longer works.');
+ $this->assertResponse(404);
+
+ // create second test node
+ $node2 = $this->createNode();
+
+ // set alias to second test node
+ // leave $edit['path'] the same
+ $this->drupalPost('node/' . $node2->nid . '/edit', $edit, t('Save'));
+
+ // confirm that the alias didn't make a duplicate
+ $this->assertText(t('The path is already in use.'), 'Attempt to moved alias was rejected.');
+
+ // delete alias
+ $this->drupalPost('node/' . $node1->nid . '/edit', array('path' => ''), t('Save'));
+
+ // confirm that the alias no longer works
+ $this->drupalGet($edit['path']);
+ $this->assertNoText($node1->title, 'Alias was successfully deleted.');
+ }
+
+ function getPID($dst) {
+ return db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $dst));
+ }
+
+ function createNode() {
+ $edit = array();
+ $edit['title'] = '!SimpleTest test node! ' . $this->randomName(10);
+ $edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
+ $this->drupalPost('node/add/page', $edit, t('Save'));
+
+ // check to make sure the node was created
+ $node = node_load(array('title' => $edit['title']));
+ $this->assertNotNull(($node === FALSE ? NULL : $node), 'Node found in database. %s');
+
+ return $node;
+ }
+}