From 876d410c8c4f8dda97ee0aad4129fdb2fee701f5 Mon Sep 17 00:00:00 2001
From: Jennifer Hodgdon <yahgrp@poplarware.com>
Date: Wed, 30 May 2012 10:26:11 -0700
Subject: [PATCH] Issue #1598588 by Niklas Fiekas: PSR-0 conversion of mail
 tests

---
 .../Drupal/system/Tests/Common/MailTest.php   | 92 +++++++++++++++++++
 core/modules/system/system.info               |  1 -
 core/modules/system/tests/mail.test           | 90 +-----------------
 3 files changed, 97 insertions(+), 86 deletions(-)
 create mode 100644 core/modules/system/lib/Drupal/system/Tests/Common/MailTest.php

diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/MailTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/MailTest.php
new file mode 100644
index 000000000000..cf33f487e778
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/MailTest.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\system\Tests\Common\MailTest.
+ */
+
+namespace Drupal\system\Tests\Common;
+
+use Drupal\Core\Mail\MailInterface;
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Defines a mail class used for testing.
+ */
+class MailTest extends WebTestBase implements MailInterface {
+  /**
+   * The most recent message that was sent through the test case.
+   *
+   * We take advantage here of the fact that static variables are shared among
+   * all instance of the same class.
+   */
+  private static $sent_message;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Mail system',
+      'description' => 'Performs tests on the pluggable mailing framework.',
+      'group' => 'Mail',
+    );
+  }
+
+  function setUp() {
+    parent::setUp(array('simpletest'));
+
+    // Set MailTestCase (i.e. this class) as the SMTP library
+    variable_set('mail_system', array('default-system' => 'Drupal\system\Tests\Common\MailTest'));
+  }
+
+  /**
+   * Assert that the pluggable mail system is functional.
+   */
+  public function testPluggableFramework() {
+    global $language_interface;
+
+    // Use MailTestCase for sending a message.
+    $message = drupal_mail('simpletest', 'mail_test', 'testing@example.com', $language_interface);
+
+    // Assert whether the message was sent through the send function.
+    $this->assertEqual(self::$sent_message['to'], 'testing@example.com', t('Pluggable mail system is extendable.'));
+  }
+
+  /**
+   * Test that message sending may be canceled.
+   *
+   * @see simpletest_mail_alter()
+   */
+  public function testCancelMessage() {
+    global $language;
+
+    // Reset the class variable holding a copy of the last sent message.
+    self::$sent_message = NULL;
+
+    // Send a test message that simpletest_mail_alter should cancel.
+    $message = drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language);
+
+    // Assert that the message was not actually sent.
+    $this->assertNull(self::$sent_message, 'Message was canceled.');
+  }
+
+  /**
+   * Concatenate and wrap the e-mail body for plain-text mails.
+   *
+   * @see Drupal\Core\Mail\PhpMail
+   */
+  public function format(array $message) {
+    // Join the body array into one string.
+    $message['body'] = implode("\n\n", $message['body']);
+    // Convert any HTML to plain-text.
+    $message['body'] = drupal_html_to_text($message['body']);
+    // Wrap the mail body for sending.
+    $message['body'] = drupal_wrap_mail($message['body']);
+    return $message;
+  }
+
+  /**
+   * Send function that is called through the mail system.
+   */
+  public function mail(array $message) {
+    self::$sent_message = $message;
+  }
+}
diff --git a/core/modules/system/system.info b/core/modules/system/system.info
index 8a11985572ec..a95825c0bd18 100644
--- a/core/modules/system/system.info
+++ b/core/modules/system/system.info
@@ -22,7 +22,6 @@ files[] = tests/form.test
 files[] = tests/image.test
 files[] = tests/installer.test
 files[] = tests/lock.test
-files[] = tests/mail.test
 files[] = tests/menu.test
 files[] = tests/module.test
 files[] = tests/pager.test
diff --git a/core/modules/system/tests/mail.test b/core/modules/system/tests/mail.test
index 38c6dc8c0af2..a30c3c106dcb 100644
--- a/core/modules/system/tests/mail.test
+++ b/core/modules/system/tests/mail.test
@@ -2,97 +2,17 @@
 
 /**
  * @file
- * Test the Drupal mailing system.
+ * Definition of Drupal\system\Tests\Common\HtmlToTextTest.
  */
 
-use Drupal\Core\Mail\MailInterface;
-use Drupal\simpletest\WebTestBase;
-
-/**
- * Defines a mail class used for testing.
- */
-class MailTestCase extends WebTestBase implements MailInterface {
-  /**
-   * The most recent message that was sent through the test case.
-   *
-   * We take advantage here of the fact that static variables are shared among
-   * all instance of the same class.
-   */
-  private static $sent_message;
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Mail system',
-      'description' => 'Performs tests on the pluggable mailing framework.',
-      'group' => 'Mail',
-    );
-  }
-
-  function setUp() {
-    parent::setUp(array('simpletest'));
-
-    // Set MailTestCase (i.e. this class) as the SMTP library
-    variable_set('mail_system', array('default-system' => 'MailTestCase'));
-  }
-
-  /**
-   * Assert that the pluggable mail system is functional.
-   */
-  public function testPluggableFramework() {
-    global $language_interface;
-
-    // Use MailTestCase for sending a message.
-    $message = drupal_mail('simpletest', 'mail_test', 'testing@example.com', $language_interface);
+namespace Drupal\system\Tests\Common;
 
-    // Assert whether the message was sent through the send function.
-    $this->assertEqual(self::$sent_message['to'], 'testing@example.com', t('Pluggable mail system is extendable.'));
-  }
-
-  /**
-   * Test that message sending may be canceled.
-   *
-   * @see simpletest_mail_alter()
-   */
-  public function testCancelMessage() {
-    global $language;
-
-    // Reset the class variable holding a copy of the last sent message.
-    self::$sent_message = NULL;
-
-    // Send a test message that simpletest_mail_alter should cancel.
-    $message = drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language);
-
-    // Assert that the message was not actually sent.
-    $this->assertNull(self::$sent_message, 'Message was canceled.');
-  }
-
-  /**
-   * Concatenate and wrap the e-mail body for plain-text mails.
-   *
-   * @see Drupal\Core\Mail\PhpMail
-   */
-  public function format(array $message) {
-    // Join the body array into one string.
-    $message['body'] = implode("\n\n", $message['body']);
-    // Convert any HTML to plain-text.
-    $message['body'] = drupal_html_to_text($message['body']);
-    // Wrap the mail body for sending.
-    $message['body'] = drupal_wrap_mail($message['body']);
-    return $message;
-  }
-
-  /**
-   * Send function that is called through the mail system.
-   */
-  public function mail(array $message) {
-    self::$sent_message = $message;
-  }
-}
+use Drupal\simpletest\WebTestBase;
 
 /**
- * Unit tests for drupal_html_to_text().
+ * Tests for drupal_html_to_text().
  */
-class DrupalHtmlToTextTestCase extends WebTestBase {
+class HtmlToTextTest extends WebTestBase {
   public static function getInfo() {
     return array(
       'name'  => 'HTML to text conversion',
-- 
GitLab