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