From c034303bb3d9bce20b4f395c4afe4c3933b929d2 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 29 May 2012 13:29:45 +0900
Subject: [PATCH] Issue #1593402 by Rob Loach, aspilicious: Convert php tests
 to PSR-0.

---
 .../lib/Drupal/php/Tests/PhpAccessTest.php    |  39 ++++++
 .../lib/Drupal/php/Tests/PhpFilterTest.php    |  49 +++++++
 .../php/lib/Drupal/php/Tests/PhpTestBase.php  |  55 ++++++++
 core/modules/php/php.info                     |   1 -
 core/modules/php/php.test                     | 125 ------------------
 5 files changed, 143 insertions(+), 126 deletions(-)
 create mode 100644 core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php
 create mode 100644 core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php
 create mode 100644 core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php
 delete mode 100644 core/modules/php/php.test

diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php b/core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php
new file mode 100644
index 000000000000..ec7f740d392a
--- /dev/null
+++ b/core/modules/php/lib/Drupal/php/Tests/PhpAccessTest.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\php\Tests\PhpAccessTest.
+ */
+
+namespace Drupal\php\Tests;
+
+/**
+ * Tests to make sure access to the PHP filter is properly restricted.
+ */
+class PhpAccessTest extends PhpTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'PHP filter access check',
+      'description' => 'Make sure that users who don\'t have access to the PHP filter can\'t see it.',
+      'group' => 'PHP',
+    );
+  }
+
+  /**
+   * Makes sure that the user can't use the PHP filter when not given access.
+   */
+  function testNoPrivileges() {
+    // Create node with PHP filter enabled.
+    $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
+    $this->drupalLogin($web_user);
+    $node = $this->createNodeWithCode();
+
+    // Make sure that the PHP code shows up as text.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText('print', t('PHP code was not evaluated.'));
+
+    // Make sure that user doesn't have access to filter.
+    $this->drupalGet('node/' . $node->nid . '/edit');
+    $this->assertNoRaw('<option value="' . $this->php_code_format->format . '">', t('PHP code format not available.'));
+  }
+}
diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php b/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php
new file mode 100644
index 000000000000..71ee5beee587
--- /dev/null
+++ b/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\php\Tests\PhpFilterTest.
+ */
+
+namespace Drupal\php\Tests;
+
+/**
+ * Tests to make sure the PHP filter actually evaluates PHP code when used.
+ */
+class PhpFilterTest extends PhpTestBase {
+  public static function getInfo() {
+    return array(
+      'name' => 'PHP filter functionality',
+      'description' => 'Make sure that PHP filter properly evaluates PHP code when enabled.',
+      'group' => 'PHP',
+    );
+  }
+
+  /**
+   * Makes sure that the PHP filter evaluates PHP code when used.
+   */
+  function testPhpFilter() {
+    // Log in as a user with permission to use the PHP code text format.
+    $php_code_permission = filter_permission_name(filter_format_load('php_code'));
+    $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission));
+    $this->drupalLogin($web_user);
+
+    // Create a node with PHP code in it.
+    $node = $this->createNodeWithCode();
+
+    // Make sure that the PHP code shows up as text.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText('php print');
+
+    // Change filter to PHP filter and see that PHP code is evaluated.
+    $edit = array();
+    $langcode = LANGUAGE_NOT_SPECIFIED;
+    $edit["body[$langcode][0][format]"] = $this->php_code_format->format;
+    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
+    $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->title)), t('PHP code filter turned on.'));
+
+    // Make sure that the PHP code shows up as text.
+    $this->assertNoText('print "SimpleTest PHP was executed!"', t("PHP code isn't displayed."));
+    $this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.'));
+  }
+}
diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php b/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php
new file mode 100644
index 000000000000..2af8c8b61ad7
--- /dev/null
+++ b/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\php\Tests\PhpTestBase.
+ */
+
+namespace Drupal\php\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Defines a base PHP test case class.
+ */
+class PhpTestBase extends WebTestBase {
+  protected $php_code_format;
+
+  function setUp() {
+    parent::setUp('php');
+
+    // Create Basic page node type.
+    $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
+
+    // Create and login admin user.
+    $admin_user = $this->drupalCreateUser(array('administer filters'));
+    $this->drupalLogin($admin_user);
+
+    // Verify that the PHP code text format was inserted.
+    $php_format_id = 'php_code';
+    $this->php_code_format = filter_format_load($php_format_id);
+    $this->assertEqual($this->php_code_format->name, 'PHP code', t('PHP code text format was created.'));
+
+    // Verify that the format has the PHP code filter enabled.
+    $filters = filter_list_format($php_format_id);
+    $this->assertTrue($filters['php_code']->status, t('PHP code filter is enabled.'));
+
+    // Verify that the format exists on the administration page.
+    $this->drupalGet('admin/config/content/formats');
+    $this->assertText('PHP code', t('PHP code text format was created.'));
+
+    // Verify that anonymous and authenticated user roles do not have access.
+    $this->drupalGet('admin/config/content/formats/' . $php_format_id);
+    $this->assertFieldByName('roles[' . DRUPAL_ANONYMOUS_RID . ']', FALSE, t('Anonymous users do not have access to PHP code format.'));
+    $this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', FALSE, t('Authenticated users do not have access to PHP code format.'));
+  }
+
+  /**
+   * Creates a test node with PHP code in the body.
+   *
+   * @return stdObject Node object.
+   */
+  function createNodeWithCode() {
+    return $this->drupalCreateNode(array('body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => '<?php print "SimpleTest PHP was executed!"; ?>')))));
+  }
+}
diff --git a/core/modules/php/php.info b/core/modules/php/php.info
index e1f2d570d524..f155609dd209 100644
--- a/core/modules/php/php.info
+++ b/core/modules/php/php.info
@@ -3,4 +3,3 @@ description = Allows embedded PHP code/snippets to be evaluated.
 package = Core
 version = VERSION
 core = 8.x
-files[] = php.test
diff --git a/core/modules/php/php.test b/core/modules/php/php.test
deleted file mode 100644
index 980fb7bebf11..000000000000
--- a/core/modules/php/php.test
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-
-/**
- * @file
- * Tests for php.module.
- */
-
-use Drupal\simpletest\WebTestBase;
-
-/**
- * Defines a base PHP test case class.
- */
-class PHPTestCase extends WebTestBase {
-  protected $php_code_format;
-
-  function setUp() {
-    parent::setUp('php');
-
-    // Create Basic page node type.
-    $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
-
-    // Create and login admin user.
-    $admin_user = $this->drupalCreateUser(array('administer filters'));
-    $this->drupalLogin($admin_user);
-
-    // Verify that the PHP code text format was inserted.
-    $php_format_id = 'php_code';
-    $this->php_code_format = filter_format_load($php_format_id);
-    $this->assertEqual($this->php_code_format->name, 'PHP code', t('PHP code text format was created.'));
-
-    // Verify that the format has the PHP code filter enabled.
-    $filters = filter_list_format($php_format_id);
-    $this->assertTrue($filters['php_code']->status, t('PHP code filter is enabled.'));
-
-    // Verify that the format exists on the administration page.
-    $this->drupalGet('admin/config/content/formats');
-    $this->assertText('PHP code', t('PHP code text format was created.'));
-
-    // Verify that anonymous and authenticated user roles do not have access.
-    $this->drupalGet('admin/config/content/formats/' . $php_format_id);
-    $this->assertFieldByName('roles[' . DRUPAL_ANONYMOUS_RID . ']', FALSE, t('Anonymous users do not have access to PHP code format.'));
-    $this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', FALSE, t('Authenticated users do not have access to PHP code format.'));
-  }
-
-  /**
-   * Creates a test node with PHP code in the body.
-   *
-   * @return stdObject Node object.
-   */
-  function createNodeWithCode() {
-    return $this->drupalCreateNode(array('body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => '<?php print "SimpleTest PHP was executed!"; ?>')))));
-  }
-}
-
-/**
- * Tests to make sure the PHP filter actually evaluates PHP code when used.
- */
-class PHPFilterTestCase extends PHPTestCase {
-  public static function getInfo() {
-    return array(
-      'name' => 'PHP filter functionality',
-      'description' => 'Make sure that PHP filter properly evaluates PHP code when enabled.',
-      'group' => 'PHP',
-    );
-  }
-
-  /**
-   * Makes sure that the PHP filter evaluates PHP code when used.
-   */
-  function testPHPFilter() {
-    // Log in as a user with permission to use the PHP code text format.
-    $php_code_permission = filter_permission_name(filter_format_load('php_code'));
-    $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission));
-    $this->drupalLogin($web_user);
-
-    // Create a node with PHP code in it.
-    $node = $this->createNodeWithCode();
-
-    // Make sure that the PHP code shows up as text.
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertText('php print');
-
-    // Change filter to PHP filter and see that PHP code is evaluated.
-    $edit = array();
-    $langcode = LANGUAGE_NOT_SPECIFIED;
-    $edit["body[$langcode][0][format]"] = $this->php_code_format->format;
-    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
-    $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->title)), t('PHP code filter turned on.'));
-
-    // Make sure that the PHP code shows up as text.
-    $this->assertNoText('print "SimpleTest PHP was executed!"', t("PHP code isn't displayed."));
-    $this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.'));
-  }
-}
-
-/**
- * Tests to make sure access to the PHP filter is properly restricted.
- */
-class PHPAccessTestCase extends PHPTestCase {
-  public static function getInfo() {
-    return array(
-      'name' => 'PHP filter access check',
-      'description' => 'Make sure that users who don\'t have access to the PHP filter can\'t see it.',
-      'group' => 'PHP',
-    );
-  }
-
-  /**
-   * Makes sure that the user can't use the PHP filter when not given access.
-   */
-  function testNoPrivileges() {
-    // Create node with PHP filter enabled.
-    $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
-    $this->drupalLogin($web_user);
-    $node = $this->createNodeWithCode();
-
-    // Make sure that the PHP code shows up as text.
-    $this->drupalGet('node/' . $node->nid);
-    $this->assertText('print', t('PHP code was not evaluated.'));
-
-    // Make sure that user doesn't have access to filter.
-    $this->drupalGet('node/' . $node->nid . '/edit');
-    $this->assertNoRaw('<option value="' . $this->php_code_format->format . '">', t('PHP code format not available.'));
-  }
-}
-- 
GitLab