summaryrefslogtreecommitdiff
path: root/modules/php
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/php
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/php')
-rw-r--r--modules/php/php.test93
1 files changed, 93 insertions, 0 deletions
diff --git a/modules/php/php.test b/modules/php/php.test
new file mode 100644
index 000000000..d0293d1f3
--- /dev/null
+++ b/modules/php/php.test
@@ -0,0 +1,93 @@
+<?php
+// $Id$
+
+class PHPTestCase extends DrupalWebTestCase {
+ /**
+ * Implementation of getInfo().
+ */
+ function getInfo() {
+ return array(
+ 'name' => t('PHP filter functionality'),
+ 'description' => t('Make sure that PHP filter evaluates PHP code when enabled and that users who don\'t have access to filter can\'t see it'),
+ 'group' => t('PHP'),
+ );
+ }
+
+ /**
+ * Implementation of getInfo().
+ */
+ function setUp() {
+ parent::setUp('php');
+
+ // Create and login admin user.
+ $admin_user = $this->drupalCreateUser(array('administer filters'));
+ $this->drupalLogin($admin_user);
+
+ // Confirm that the PHP filter is #3.
+ $this->drupalGet('admin/settings/filters/3');
+ $this->assertText('PHP code', t('On PHP code filter page.'));
+ }
+
+ /**
+ * Make sure that the PHP filter evaluates PHP code when used.
+ */
+ function testPHPFilter() {
+ // Setup PHP filter.
+ $edit = array();
+ $edit['roles[2]'] = TRUE; // Set authenticated users to have permission to use filter.
+ $this->drupalPost(NULL, $edit, 'Save configuration');
+ $this->assertText(t('The input format settings have been updated.'), t('PHP format available to authenticated users.'));
+
+ // Create node with PHP filter enabled.
+ $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
+ $this->drupalLogin($web_user);
+
+ $node = $this->createNodeWithCode($web_user);
+
+ // Make sure that the PHP code shows up as text.
+ $this->assertText('print', t('PHP code is displayed.'));
+
+ // Change filter to PHP filter and see that PHP code is evaluated.
+ $edit = array();
+ $edit['format'] = 3;
+ $this->drupalPost('node/'. $node->nid .'/edit', $edit, t('Save'));
+ $this->assertRaw(t('Page %title has been updated.', array('%title' => $node->title)), t('PHP code filter turned on.'));
+
+ // Make sure that the PHP code shows up as text.
+ $this->assertNoText('print', t('PHP code isn\'t displayed.'));
+ $this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.'));
+ }
+
+ /**
+ * Make sure that user can't use the PHP filter when not given access.
+ */
+ function testNoPrivileges() {
+ // Create node with PHP filter enabled.
+ $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
+ $this->drupalLogin($web_user);
+
+ $node = $this->createNodeWithCode($web_user);
+
+ // Make sure that the PHP code shows up as text.
+ $this->assertText('print', t('PHP code is displayed.'));
+
+ // Make sure that user doesn't have access to filter.
+ $this->drupalGet('node/'. $node->nid .'/edit');
+ $this->assertNoFieldByName('format', '3', t('Format not available.'));
+ }
+
+ /**
+ * Create a test node with PHP code in the body.
+ *
+ * @param stdObject User object to create node for.
+ * @return stdObject Node object.
+ */
+ function createNodeWithCode($user) {
+ $node = $this->drupalCreateNode(array('uid' => $user->uid));
+ $edit = array();
+ $edit['body'] = '<?php print "SimpleTest PHP was executed!"; ?>';
+ $this->drupalPost('node/'. $node->nid .'/edit', $edit, t('Save'));
+ $this->assertRaw(t('Page %title has been updated.', array('%title' => $node->title)), t('PHP code inserted into node.'));
+ return $node;
+ }
+}