Skip to content
Snippets Groups Projects
Commit c034303b authored by catch's avatar catch
Browse files

Issue #1593402 by Rob Loach, aspilicious: Convert php tests to PSR-0.

parent 8b9b034c
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Definition of Drupal\php\Tests\PhpAccessTest.
*/
namespace Drupal\php\Tests;
/**
* Tests to make sure access to the PHP filter is properly restricted.
*/
class PhpAccessTest extends PhpTestBase {
public static function getInfo() {
return array(
'name' => 'PHP filter access check',
'description' => 'Make sure that users who don\'t have access to the PHP filter can\'t see it.',
'group' => 'PHP',
);
}
/**
* Makes sure that the 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();
// Make sure that the PHP code shows up as text.
$this->drupalGet('node/' . $node->nid);
$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');
$this->assertNoRaw('<option value="' . $this->php_code_format->format . '">', t('PHP code format not available.'));
}
}
<?php
/**
* @file
* Definition of Drupal\php\Tests\PhpFilterTest.
*/
namespace Drupal\php\Tests;
/**
* Tests to make sure the PHP filter actually evaluates PHP code when used.
*/
class PhpFilterTest extends PhpTestBase {
public static function getInfo() {
return array(
'name' => 'PHP filter functionality',
'description' => 'Make sure that PHP filter properly evaluates PHP code when enabled.',
'group' => 'PHP',
);
}
/**
* Makes sure that the PHP filter evaluates PHP code when used.
*/
function testPhpFilter() {
// Log in as a user with permission to use the PHP code text format.
$php_code_permission = filter_permission_name(filter_format_load('php_code'));
$web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission));
$this->drupalLogin($web_user);
// Create a node with PHP code in it.
$node = $this->createNodeWithCode();
// Make sure that the PHP code shows up as text.
$this->drupalGet('node/' . $node->nid);
$this->assertText('php print');
// Change filter to PHP filter and see that PHP code is evaluated.
$edit = array();
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit["body[$langcode][0][format]"] = $this->php_code_format->format;
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Basic 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 "SimpleTest PHP was executed!"', t("PHP code isn't displayed."));
$this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.'));
}
}
......@@ -2,15 +2,17 @@
/**
* @file
* Tests for php.module.
* Definition of Drupal\php\Tests\PhpTestBase.
*/
namespace Drupal\php\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Defines a base PHP test case class.
*/
class PHPTestCase extends WebTestBase {
class PhpTestBase extends WebTestBase {
protected $php_code_format;
function setUp() {
......@@ -51,75 +53,3 @@ function createNodeWithCode() {
return $this->drupalCreateNode(array('body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => '<?php print "SimpleTest PHP was executed!"; ?>')))));
}
}
/**
* Tests to make sure the PHP filter actually evaluates PHP code when used.
*/
class PHPFilterTestCase extends PHPTestCase {
public static function getInfo() {
return array(
'name' => 'PHP filter functionality',
'description' => 'Make sure that PHP filter properly evaluates PHP code when enabled.',
'group' => 'PHP',
);
}
/**
* Makes sure that the PHP filter evaluates PHP code when used.
*/
function testPHPFilter() {
// Log in as a user with permission to use the PHP code text format.
$php_code_permission = filter_permission_name(filter_format_load('php_code'));
$web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission));
$this->drupalLogin($web_user);
// Create a node with PHP code in it.
$node = $this->createNodeWithCode();
// Make sure that the PHP code shows up as text.
$this->drupalGet('node/' . $node->nid);
$this->assertText('php print');
// Change filter to PHP filter and see that PHP code is evaluated.
$edit = array();
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit["body[$langcode][0][format]"] = $this->php_code_format->format;
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Basic 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 "SimpleTest PHP was executed!"', t("PHP code isn't displayed."));
$this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.'));
}
}
/**
* Tests to make sure access to the PHP filter is properly restricted.
*/
class PHPAccessTestCase extends PHPTestCase {
public static function getInfo() {
return array(
'name' => 'PHP filter access check',
'description' => 'Make sure that users who don\'t have access to the PHP filter can\'t see it.',
'group' => 'PHP',
);
}
/**
* Makes sure that the 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();
// Make sure that the PHP code shows up as text.
$this->drupalGet('node/' . $node->nid);
$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');
$this->assertNoRaw('<option value="' . $this->php_code_format->format . '">', t('PHP code format not available.'));
}
}
......@@ -3,4 +3,3 @@ description = Allows embedded PHP code/snippets to be evaluated.
package = Core
version = VERSION
core = 8.x
files[] = php.test
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment