diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-12-03 15:33:42 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-12-03 15:33:42 +0000 |
commit | d1a2de607e23da467c1366aca04ac5f61328a37a (patch) | |
tree | cbaca2bea89c96d310b1dabbf99d5b134c809f23 /modules/php | |
parent | f43ee59e056e3d769545f90a3ab26244fb229b00 (diff) | |
download | brdo-d1a2de607e23da467c1366aca04ac5f61328a37a.tar.gz brdo-d1a2de607e23da467c1366aca04ac5f61328a37a.tar.bz2 |
- Patch #626024 by sun, catch: fixed filter_list_format() hits database too often / filter_format_save() doesn't save all filters.
Diffstat (limited to 'modules/php')
-rw-r--r-- | modules/php/php.install | 39 | ||||
-rw-r--r-- | modules/php/php.test | 28 |
2 files changed, 39 insertions, 28 deletions
diff --git a/modules/php/php.install b/modules/php/php.install index c010fc738..a8ac75ce7 100644 --- a/modules/php/php.install +++ b/modules/php/php.install @@ -7,34 +7,33 @@ */ /** - * Implement hook_install(). + * Implements hook_enable(). */ -function php_install() { +function php_enable() { $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField(); // Add a PHP code text format, if it does not exist. Do this only for the // first install (or if the format has been manually deleted) as there is no // reliable method to identify the format in an uninstall hook or in // subsequent clean installs. if (!$format_exists) { - $format = db_insert('filter_format') - ->fields(array( - 'name' => 'PHP code', - 'cache' => 0, - )) - ->execute(); + $php_format = array( + 'name' => 'PHP code', + // 'Plain text' format is installed with a weight of 10 by default. Use a + // higher weight here to ensure that this format will not be the default + // format for anyone. + 'weight' => 11, + 'filters' => array( + // Enable the PHP evaluator filter. + 'php_code' => array( + 'weight' => 0, + 'status' => 1, + ), + ), + ); + $php_format = (object) $php_format; + filter_format_save($php_format); - // Enable the PHP evaluator filter. - db_insert('filter') - ->fields(array( - 'format' => $format, - 'module' => 'php', - 'name' => 'php_code', - 'weight' => 0, - 'status' => 1, - )) - ->execute(); - - drupal_set_message(t('A !php-code text format has been created.', array('!php-code' => l('PHP code', 'admin/config/content/formats/' . $format)))); + drupal_set_message(t('A !php-code text format has been created.', array('!php-code' => l('PHP code', 'admin/config/content/formats/' . $php_format->format)))); } } diff --git a/modules/php/php.test b/modules/php/php.test index a70fb0ac6..778cb1052 100644 --- a/modules/php/php.test +++ b/modules/php/php.test @@ -14,14 +14,26 @@ class PHPTestCase extends DrupalWebTestCase { $admin_user = $this->drupalCreateUser(array('administer filters')); $this->drupalLogin($admin_user); - // Confirm that the PHP code text format was inserted as the newest format - // on the site. - $newest_format_id = db_query("SELECT MAX(format) FROM {filter_format}")->fetchField(); - $newest_format = filter_format_load($newest_format_id); - $this->assertEqual($newest_format->name, 'PHP code', t('PHP code text format was created.')); + // Verify that the PHP code text format was inserted. + $php_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField(); + $php_format = filter_format_load($php_format_id); + $this->assertEqual($php_format->name, 'PHP code', t('PHP code text format was created.')); + + // Verify that the format has the PHP code filter enabled. + $filters = filter_list_format($php_format_id); + $this->assertTrue($filters['php_code']->status, t('PHP code filter is enabled.')); + + // Verify that the format exists on the administration page. + $this->drupalGet('admin/config/content/formats'); + $this->assertText('PHP code', t('PHP code text format was created.')); + + // Verify that anonymous and authenticated user roles do not have access. + $this->drupalGet('admin/config/content/formats/' . $php_format_id); + $this->assertFieldByName('roles[1]', FALSE, t('Anonymous users do not have access to PHP code format.')); + $this->assertFieldByName('roles[2]', FALSE, t('Authenticated users do not have access to PHP code format.')); // Store the format ID of the PHP code text format for later use. - $this->php_code_format = $newest_format_id; + $this->php_code_format = $php_format_id; } /** @@ -60,7 +72,7 @@ class PHPFilterTestCase extends PHPTestCase { // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->nid); - $this->assertText('print', t('PHP code is displayed.')); + $this->assertText('print', t('PHP code was not evaluated.')); // Change filter to PHP filter and see that PHP code is evaluated. $edit = array(); @@ -98,7 +110,7 @@ class PHPAccessTestCase extends PHPTestCase { // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->nid); - $this->assertText('print', t('PHP code is displayed.')); + $this->assertText('print', t('PHP code was not evaluated.')); // Make sure that user doesn't have access to filter. $this->drupalGet('node/' . $node->nid . '/edit'); |