Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / php / src / Tests / PhpTestBase.php
1 <?php
2
3 namespace Drupal\php\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\user\RoleInterface;
7
8 /**
9  * Test if PHP filter works in general.
10  *
11  * @group PHP
12  */
13 abstract class PhpTestBase extends WebTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['node', 'php'];
21
22   protected $phpCodeFormat;
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29
30     // Create Basic page node type.
31     $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
32
33     // Create and login admin user.
34     $admin_user = $this->drupalCreateUser(['administer filters']);
35     $this->drupalLogin($admin_user);
36
37     // Verify that the PHP code text format was inserted.
38     $php_format_id = 'php_code';
39     $this->phpCodeFormat = \Drupal::entityTypeManager()->getStorage('filter_format')->load($php_format_id);
40
41     $this->assertEqual($this->phpCodeFormat->label(), 'PHP code', 'PHP code text format was created.');
42
43     // Verify that the format has the PHP code filter enabled.
44     $filters = $this->phpCodeFormat->filters();
45     $this->assertTrue($filters->get('php_code')->status, 'PHP code filter is enabled.');
46
47     // Verify that the format exists on the administration page.
48     $this->drupalGet('admin/config/content/formats');
49     $this->assertText('PHP code', 'PHP code text format was created.');
50
51     // Verify that anonymous and authenticated user roles do not have access.
52     $this->drupalGet('admin/config/content/formats/manage/' . $php_format_id);
53     $this->assertFieldByName('roles[' . RoleInterface::ANONYMOUS_ID . ']', FALSE, 'Anonymous users do not have access to PHP code format.');
54     $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', FALSE, 'Authenticated users do not have access to PHP code format.');
55   }
56
57   /**
58    * Creates a test node with PHP code in the body.
59    *
60    * @return \Drupal\node\NodeInterface
61    *   Node object.
62    */
63   public function createNodeWithCode() {
64     return $this->drupalCreateNode(['body' => [['value' => '<?php print "SimpleTest PHP was executed!";print "Current state is " . Drupal::state()->get("php_state_test", "empty"); ?>']]]);
65   }
66
67 }