X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fphp%2Fsrc%2FTests%2FPhpTestBase.php;fp=web%2Fmodules%2Fcontrib%2Fphp%2Fsrc%2FTests%2FPhpTestBase.php;h=129e4878309d47ff5ce58c5e669ed93e3f1dfc79;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/php/src/Tests/PhpTestBase.php b/web/modules/contrib/php/src/Tests/PhpTestBase.php new file mode 100644 index 000000000..129e48783 --- /dev/null +++ b/web/modules/contrib/php/src/Tests/PhpTestBase.php @@ -0,0 +1,72 @@ +drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]); + + // Create and login admin user. + $admin_user = $this->drupalCreateUser(['administer filters']); + $this->drupalLogin($admin_user); + + // Verify that the PHP code text format was inserted. + $php_format_id = 'php_code'; + $this->phpCodeFormat = \Drupal::entityTypeManager()->getStorage('filter_format')->load($php_format_id); + + $this->assertEqual($this->phpCodeFormat->label(), 'PHP code', 'PHP code text format was created.'); + + // Verify that the format has the PHP code filter enabled. + $filters = $this->phpCodeFormat->filters(); + $this->assertTrue($filters->get('php_code')->status, 'PHP code filter is enabled.'); + + // Verify that the format exists on the administration page. + $this->drupalGet('admin/config/content/formats'); + $this->assertText('PHP code', 'PHP code text format was created.'); + + // Verify that anonymous and authenticated user roles do not have access. + $this->drupalGet('admin/config/content/formats/manage/' . $php_format_id); + $this->assertFieldByName('roles[' . RoleInterface::ANONYMOUS_ID . ']', FALSE, 'Anonymous users do not have access to PHP code format.'); + $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', FALSE, 'Authenticated users do not have access to PHP code format.'); + } + + /** + * Creates a test node with PHP code in the body. + * + * @return \Drupal\node\NodeInterface + * Node object. + */ + public function createNodeWithCode() { + return $this->drupalCreateNode(['body' => [['value' => '']]]); + } + +}