5 * Definition of Drupal\php\Tests\PhpFilterTest.
8 namespace Drupal\php\Tests;
11 * Tests to make sure the PHP filter actually evaluates PHP code when used.
15 class PhpFilterTest extends PhpTestBase {
18 * Makes sure that the PHP filter evaluates PHP code when used.
20 public function testPhpFilter() {
21 // Log in as a user with permission to use the PHP code text format.
22 $php_code_permission = entity_load('filter_format', 'php_code')->getPermissionName();
23 $web_user = $this->drupalCreateUser(['access content', 'create page content', 'edit own page content', $php_code_permission]);
24 $this->drupalLogin($web_user);
26 // Create a node with PHP code in it.
27 $node = $this->createNodeWithCode();
29 // Make sure that the PHP code shows up as text.
30 $this->drupalGet('node/' . $node->id());
31 $this->assertText('php print');
33 // Change filter to PHP filter and see that PHP code is evaluated.
35 $edit['body[0][format]'] = $this->phpCodeFormat->id();
36 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
37 $this->assertRaw(t('Basic page %title has been updated.', ['%title' => $node->label()]), 'PHP code filter turned on.');
39 // Make sure that the PHP code shows up as text.
40 $this->assertNoText('print "SimpleTest PHP was executed!"', "PHP code isn't displayed.");
41 $this->assertText('SimpleTest PHP was executed!', 'PHP code has been evaluated.');