Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / php / src / Tests / PhpFilterTest.php
1 <?php
2
3 namespace Drupal\php\Tests;
4
5 /**
6  * Tests to make sure the PHP filter actually evaluates PHP code when used.
7  *
8  * @group PHP
9  */
10 class PhpFilterTest extends PhpTestBase {
11
12   /**
13    * Makes sure that the PHP filter evaluates PHP code when used.
14    */
15   public function testPhpFilter() {
16     // Log in as a user with permission to use the PHP code text format.
17     $php_code_permission = entity_load('filter_format', 'php_code')->getPermissionName();
18     $permissions = [
19       'access content',
20       'create page content',
21       'edit own page content',
22       $php_code_permission,
23     ];
24     $web_user = $this->drupalCreateUser($permissions);
25     $this->drupalLogin($web_user);
26
27     // Create a node with PHP code in it.
28     $node = $this->createNodeWithCode();
29
30     // Make sure that the PHP code shows up as text.
31     $this->drupalGet('node/' . $node->id());
32     $this->assertText('php print');
33
34     // Change filter to PHP filter and see that PHP code is evaluated.
35     $edit = [];
36     $edit['body[0][format]'] = $this->phpCodeFormat->id();
37     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
38     $this->assertRaw(t('@type %title has been updated.', ['@type' => 'Basic page', '%title' => $node->link($node->getTitle())]), 'PHP code filter turned on.');
39
40     // Make sure that the PHP code shows up as text.
41     $this->assertNoText('print "SimpleTest PHP was executed!"', "PHP code isn't displayed.");
42     $this->assertText('SimpleTest PHP was executed!', 'PHP code has been evaluated.');
43
44     // Verify that cache is disabled for PHP evaluates.
45     $this->assertText('Current state is empty', 'PHP code has been evaluated once.');
46     \Drupal::state()->set('php_state_test', 'not empty');
47     $this->drupalGet('node/' . $node->id());
48     $this->assertText('Current state is not empty', 'PHP code has been evaluated again.');
49   }
50
51 }