Further modules included.
[yaffs-website] / web / modules / contrib / php / src / Tests / PhpFilterTest.php
1 <?php
2
3 /**
4  * @file
5  * Definition of Drupal\php\Tests\PhpFilterTest.
6  */
7
8 namespace Drupal\php\Tests;
9
10 /**
11  * Tests to make sure the PHP filter actually evaluates PHP code when used.
12  *
13  * @group PHP
14  */
15 class PhpFilterTest extends PhpTestBase {
16
17   /**
18    * Makes sure that the PHP filter evaluates PHP code when used.
19    */
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);
25
26     // Create a node with PHP code in it.
27     $node = $this->createNodeWithCode();
28
29     // Make sure that the PHP code shows up as text.
30     $this->drupalGet('node/' . $node->id());
31     $this->assertText('php print');
32
33     // Change filter to PHP filter and see that PHP code is evaluated.
34     $edit = [];
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.');
38
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.');
42   }
43
44 }