MailFactory is now a swappable service thanks to #1889644: Convert drupal_mail_system() to a MailFactory service to allow more flexible replacements. However, alternative implementations are hobbled by the lack of any kind of discovery mechanism for MailInterface classes.

For example, a contrib module like Mailsystem has no way of building a user interface for selecting mail methods, because it has no way of knowing what mail classes are available.

A simple and low-impact solution would be turn existing mail classes into annotated plugins and create a simple plugin manager for them. This would open up options for contrib.

Proposed change notice

Mail backends are now annotated plugins, and can be discovered and implemented via the new plugin.manager.mail service.

The earlier mail.factory service has been removed, and its functionality has been merged into plugin.manager.mail.

Furthermore, the config setting system.mail.interface, which identifies the mail plugin used for a particular message, now takes plugin IDs as values rather than class names.

Creating a mail plugin

To provide a new mail backend in a custom module named mymodule, you must implement Drupal\Core\Mail\MailInterface within the \Drupal\mymodule\Plugin\Mail namespace, and annotate the class:

namespace Drupal\mymodule\Plugin\Mail;

use Drupal\Core\Mail\MailInterface;

/**
 * A custom mail backend.
 *
 * @Mail(
 *   id = "mymodule_mailer",
 *   label = @Translation("My custom mailer"),
 *   description = @Translation("An example mail plugin implementation.")
 * )
 */
class MymoduleMailer implements MailInterface {
  public function format(array $message) {
    // ...
  }
  public function mail(array $message) {
    // ...
  }
}

See the API documentation for MailInterface for implementation details.

Retrieving mail plugins

Previously in Drupal 8, there was no way to retrieve a list of MailInterface classes. Now, you can use the plugin.manager.mail service:

// Get a keyed array of mail plugin definitions.
$definitions = \Drupal::service('plugin.manager.mail')->getDefinitions();

// Get a single definition by plugin ID.
$plugin_id = 'php_mail';
$definition = \Drupal::service('plugin.manager.mail')->getDefinition($plugin_id);

// Create an instance of a specific mail plugin.
$plugin_id = 'php_mail';
$mailer = \Drupal::service('plugin.manager.mail')->createInstance($plugin_id);

Mail plugin selection

The Drupal 8 config setting system.mail.interface is a keyed array that maps the message ID to the mail plugin it should use. The values used in this array are now plugin IDs.

Before in Drupal 8

\Drupal::config('system.mail')->set('interface.default', 'Drupal\Core\Mail\Plugin\Mail\PhpMail')->save();

After

\Drupal::config('system.mail')->set('interface.default', 'php_mail')->save();
CommentFileSizeAuthor
#71 2187495-mail-plugins-71.patch32.37 KBlongwave
#68 core-2187495-68-mail-to-plugins.patch32.35 KBles lim
#65 interdiff-2187495-62-65.txt2.28 KBles lim
#65 core-2187495-65-mail-to-plugins.patch42.8 KBles lim
#63 interdiff.txt3.22 KBlongwave
#62 interdiff.txt3.22 KBlongwave
#62 2187495-mail-plugins-62.patch32.5 KBlongwave
#58 interdiff-2187495-57-58.txt875 bytesles lim
#58 core-2187495-58-mail-to-plugins.patch32.24 KBles lim
#57 interdiff-2187495-53-57.txt1.04 KBles lim
#57 core-2187495-57-mail-to-plugins.patch32.3 KBles lim
#53 interdiff-2187495-45-53.txt4.98 KBles lim
#53 core-2187495-53-mail-to-plugins.patch32.09 KBles lim
#45 core-2187495-45-mail-to-plugins.patch27.11 KBles lim
#44 interdiff-2187495-41-44.txt1.53 KBles lim
#44 core-2187495-44-mail-to-plugins.patch27.13 KBles lim
#41 2187495-mail-plugins-41.patch26.39 KBlongwave
#41 interdiff.txt3.06 KBlongwave
#37 core-2187495-37-mail-to-plugins.patch25.51 KBles lim
#29 core-2187495-29-mail-to-plugins.patch26.39 KBles lim
#26 interdiff-2187495-23-26.txt3.88 KBles lim
#26 core-2187495-26-mail-to-plugins.patch26.38 KBles lim
#23 interdiff-2187495-20-23.txt1.16 KBles lim
#23 core-2187495-23-mail-to-plugins.patch27.92 KBles lim
#20 interdiff-2187495-15-20.txt14.02 KBles lim
#20 core-2187495-20-mail-to-plugins.patch27.2 KBles lim
#15 interdiff-2187495-13-15.patch6.37 KBles lim
#15 core-2187495-15-mail-to-plugins.patch26.79 KBles lim
#13 interdiff-2187495-7-13.txt15.51 KBles lim
#13 core-2187495-13-mail-to-plugins.patch26.8 KBles lim
#7 interdiff-2187495-4-7.txt7.17 KBles lim
#7 core-2187495-7-mail-to-plugins.patch22.07 KBles lim
#4 core-2187495-4-mail-to-plugins.patch15.75 KBles lim
#3 core-2187495-3-mail-to-plugins.patch15.74 KBles lim
#1 core-2187495-mail-to-plugins.patch10.58 KBles lim

Comments

les lim’s picture

Status: Active » Needs review
StatusFileSize
new10.58 KB

Here's a first pass at it. There will probably be tests that need refactoring.

Status: Needs review » Needs work

The last submitted patch, 1: core-2187495-mail-to-plugins.patch, failed testing.

les lim’s picture

Status: Needs work » Needs review
StatusFileSize
new15.74 KB

Fixed the mail implementation in WebTestBase, which should account for most of the failures. The tests in MailTest will need some deeper renovation, though.

les lim’s picture

StatusFileSize
new15.75 KB

Dang it, test this one, not that one.

les lim’s picture

Status: Needs review » Needs work

The last submitted patch, 4: core-2187495-4-mail-to-plugins.patch, failed testing.

les lim’s picture

Status: Needs work » Needs review
StatusFileSize
new22.07 KB
new7.17 KB

This one should be green.

The last submitted patch, 3: core-2187495-3-mail-to-plugins.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: core-2187495-7-mail-to-plugins.patch, failed testing.

berdir’s picture

Issue tags: +API change, +beta target

Agreed that this would be great to have but it would be good to have this approved as an API change before you waste time on it if it won't be possible to get it in. Tagging as API change and beta target, as it probably has to happen before beta.

+++ b/core/modules/system/lib/Drupal/system/Plugin/Mail/PhpMail.php
@@ -2,13 +2,20 @@
  * @file
- * Definition of Drupal\Core\Mail\PhpMail.
+ * Definition of Drupal\system\Plugin\Mail\PhpMail.
  */
 

components can provide plugins too, it just work just fine if you have it in Drupal\Core\Mail\Plugin\Mail\PhpMail.

We started experimenting with a plugin manager and a more flexible mail factory for mailsystem as well, as we want to improve the ability to use separate plugins for send and format there. We just added the core implementation as a hardcoded list. Wondering what's the best way to combine them.

Previously, mailsystem used to find implementations by searching the registry table for a given class suffix, similar to how simpletest works in 7.x, that is now impossible, so we need some kind of discovery.

alexpott’s picture

This change looks like a good idea. In fact because of

Previously, mailsystem used to find implementations by searching the registry table for a given class suffix, similar to how simpletest works in 7.x, that is now impossible, so we need some kind of discovery.

you could argue that this is a regression. If @Berdir and @Les Lim can agree a scope and a way forward that is as limited as possible and with the least impact of other parts of Drupal I'm +1 to doing this.

les lim’s picture

Thanks, Berdir and alexpott!

We started experimenting with a plugin manager and a more flexible mail factory for mailsystem as well, as we want to improve the ability to use separate plugins for send and format there. We just added the core implementation as a hardcoded list. Wondering what's the best way to combine them.

Well, MailManager and MailFactory can be easily combined, since MailFactory only contains a public get() method. That can just be moved into MailManager.

With regard to @alexpott's stipulations, though, I don't know if there's a low-impact way to have core use different plugins for format and for send. That may be okay, though; as long as they're plugins, contrib can find a way forward for this.

les lim’s picture

Status: Needs work » Needs review
StatusFileSize
new26.8 KB
new15.51 KB

Changes since last patch:

  • Merged MailFactory into MailManager, removing MailFactory altogether
  • Moved PhpMail and TestMailCollector to \Drupal\Core\Mail\Plugin\Mail
  • Added "label" and "description" to mail plugin annotations
berdir’s picture

  1. +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php
    @@ -17,13 +17,15 @@
    + *   label = @Translation("Mail Collector"),
    + *   description = @Translation("Does not send the message, but stores it in Drupal within the state system. Used for development and testing.")
    

    I think you can leave out the "for development", this is really only about testing.

  2. +++ b/core/modules/system/tests/modules/system_mail_failure_test/lib/Drupal/system_mail_failure_test/Plugin/Mail/TestPhpMailFailure.php
    @@ -21,13 +21,15 @@
     
       /**
    -   * Overrides Drupal\system\Plugin\Mail\PhpMail::mail().
    +   * Overrides Drupal\Core\Mail\Plugin\Mail\PhpMail::mail().
        */
    

    When changing Overrides/Implements docblock, just change them to {@inheritdoc}

Looks great.

I think we will want to update/expand the existing change record at https://drupal.org/node/2073215. You could already prepare an updated version of that in the issue summary here, the new change record draft system can't handle new revisions yet I think :)

les lim’s picture

I think you can leave out the "for development", this is really only about testing.

Done.

When changing Overrides/Implements docblock, just change them to {@inheritdoc}

Since the purpose of the override is to prevent sending the message, the parent docblock doesn't apply. I've better documented the docblock to explain this.

Also removed the annotation-specific "use" statements -- I followed some obsolete documentation.

Status: Needs review » Needs work

The last submitted patch, 15: interdiff-2187495-13-15.patch, failed testing.

les lim’s picture

Status: Needs work » Needs review

Whoopsies.

tim.plunkett’s picture

  1. +++ b/core/lib/Drupal/Core/Mail/MailManager.php
    @@ -0,0 +1,137 @@
    +  public function get($module, $key) {
    

    I think this should use getInstance, which is on MapperInterface (which all plugin managers implement).

    See FormatterPluginManager, WidgetPluginManager, SelectionPluginManager, or ResourcePluginManager for example implementations

  2. +++ b/core/lib/Drupal/Core/Mail/MailManager.php
    @@ -0,0 +1,137 @@
    +        throw new \Exception(String::format('Class %class does not implement interface %interface', array('%class' => get_class($plugin), '%interface' => 'Drupal\Core\Mail\MailInterface')));
    

    I can't remember offhand, but we usually use a more specific exception class for this

  3. +++ b/core/lib/Drupal/Core/Mail/MailManager.php
    @@ -0,0 +1,137 @@
    +      $interfaces = class_implements($plugin);
    +      if (isset($interfaces['Drupal\Core\Mail\MailInterface'])) {
    

    Use is_subclass_of

  4. +++ b/core/lib/Drupal/Core/Mail/MailManager.php
    @@ -0,0 +1,137 @@
    +    $this->mailConfig = $configFactory->get('system.mail');
    ...
    +  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, ConfigFactory $configFactory) {
    

    $config_factory

  5. +++ b/core/modules/system/tests/modules/system_mail_failure_test/lib/Drupal/system_mail_failure_test/Plugin/Mail/TestPhpMailFailure.php
    @@ -0,0 +1,38 @@
    + *   id = "TestPhpMailFailure",
    

    There's no written rule for this, but every other plugin ID in core is lower_snake_case, not UpperCamelCase.

les lim’s picture

Issue summary: View changes
les lim’s picture

Updated patch with the fixes from #18.

les lim’s picture

Issue summary: View changes

Updating change notice proposal for lower_snake_case plugin IDs.

les lim’s picture

Issue summary: View changes
les lim’s picture

Somehow missed updating the docblock for drupal_mail_system().

berdir’s picture

  1. +++ b/core/includes/mail.inc
    @@ -189,7 +189,7 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply =
     
     /**
    - * Returns an object that implements Drupal\Core\Mail\MailInterface.
    + * Returns an instance of the mail plugin to use for a given message ID.
      *
    
    @@ -198,14 +198,14 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply =
      *
      * @return \Drupal\Core\Mail\MailInterface
    - *   An object that implements Drupal\Core\Mail\MailInterface.
    + *   A mail plugin object.
      *
    

    First you change object to instance but below you keep it? Should probably use instance in both cases?

  2. +++ b/core/modules/system/tests/modules/system_mail_failure_test/lib/Drupal/system_mail_failure_test/Plugin/Mail/TestPhpMailFailure.php
    @@ -0,0 +1,38 @@
    +
    +  /**
    +   * Overrides Drupal\Core\Mail\Plugin\Mail\PhpMail::mail().
    +   *
    +   * Intentionally fails to send the message.
    +   */
    +  public function mail(array $message) {
    +    return FALSE;
    +  }
    

    Our coding standards have nothing to say about this, so I'm not sure. There are issues to discuss this, so let's not waste time on this :)

    Looks like git doesn't see this file as a move anymore, maybe you can use lower -M numbers (e.g. git diff -M25) to force it, would make the changes easier to review. Don't worry if it doesn't work, it's a small class anyway.

Looks good otherwise I think, change notice also looks great.

The last submitted patch, 20: core-2187495-20-mail-to-plugins.patch, failed testing.

les lim’s picture

First you change object to instance but below you keep it? Should probably use instance in both cases?

Good point. Here's an updated patch for more standardized language in docblocks. Also used git diff -M25, which even picked up the move from MailFactory to MailManager.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Approved API change
+++ b/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php
@@ -8,20 +8,19 @@
 /**
  * Defines a mail class used for testing.
  */
-class MailTest extends WebTestBase implements MailInterface {
+class MailTest extends WebTestBase {
 

The idea to use the same class not only for the test but also an actual test implementation is so crazy, yay for cleaning that up :)

This looks awesome, and now the diff is very easy to understand and shows what is changing, great. This is RTBC I think :)

Also tagging as approved API change, based on alexpott's comment above.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

core-2187495-26-mail-to-plugins.patch no longer applies.

error: patch failed: core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php:846
error: core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php: patch does not apply
error: patch failed: core/modules/system/lib/Drupal/system/Tests/InstallerTest.php:75
error: core/modules/system/lib/Drupal/system/Tests/InstallerTest.php: patch does not apply

les lim’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new26.39 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 29: core-2187495-29-mail-to-plugins.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review
les lim’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC.

alexpott’s picture

Lets create a change record before commit https://groups.drupal.org/node/402688

alexpott’s picture

Issue tags: +Needs change record
les lim’s picture

There's one ready to go in the issue summary. Pasted that into a new draft change record here:

https://drupal.org/node/2191201

les lim’s picture

Issue tags: -Needs change record

After committing, I'll also update the earlier change record from when MailFactory was introduced. That one is here: https://drupal.org/node/2073215

les lim’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new25.51 KB
les lim’s picture

Status: Needs review » Reviewed & tested by the community

Resetting status.

longwave’s picture

While someone's looking at the mail system could they review #2146971: SimpleTest should override all mail system implementations with TestMailCollector? It will need rerolling after this gets in, should be simple enough though.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php
@@ -2,13 +2,21 @@
+ * @Plugin(

+++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php
@@ -2,21 +2,29 @@
+ * @Plugin(

+++ b/core/modules/system/tests/modules/system_mail_failure_test/lib/Drupal/system_mail_failure_test/Plugin/Mail/TestPhpMailFailure.php
@@ -16,16 +16,23 @@
+ * @Plugin(

Can we implement an @Mail annotation. See https://api.drupal.org/api/drupal/core%21modules%21block%21lib%21Drupal%...

longwave’s picture

les lim’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks! Updated the change notice draft at https://drupal.org/node/2191201 as well.

tim.plunkett’s picture

I'm not

+++ b/core/lib/Drupal/Core/Mail/MailManager.php
@@ -23,104 +28,115 @@ class MailFactory {
+    parent::__construct('Plugin/Mail', $namespaces);

I'm not sure how this passes, all of the other managers using custom annotations have to specify it here.

Also, why are we not providing an alter hook? The rest of the managers do.

les lim’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new27.13 KB
new1.53 KB

Fixes for #43. Setting back for review.

les lim’s picture

StatusFileSize
new27.11 KB

Re-rolled #44.

alexpott’s picture

Issue tags: +Needs tests

Considering https://drupal.org/node/2187495#comment-8471327 did not fail we must be missing test coverage. No? Or put anyway way how did it pass?

alexpott’s picture

Issue tags: -Needs tests

From an IRC conversation with @Les Lim

16:54 Les_Lim alexpott: well, to recap, we didn't specify an annotation class to use for plugin discovery, so DefaultPluginManager assumed 'Drupal\Component\Annotation\Plugin'
16:55 alexpott Les_Lim: but then how did it discover the @Mail annotations?
16:55 Les_Lim alexpott: all annotation classes inherit from 'Drupal\Component\Annotation\Plugin'
16:55 Les_Lim i think it just does an instanceof to check
16:55 Les_Lim alexpott: but I'm not sure that's actually a bug
16:56 alexpott Les_Lim: me neither - it is interesting :)
16:57 Les_Lim alexpott: it got all the proper plugins, because they were in the right subdir

longwave’s picture

The mail plugins define a label and description, but nothing uses them, and there is no test coverage for them - maybe that would have picked up the incorrect annotation config?

berdir’s picture

I don't think so, you can put anything on an annotation, the classes are just for documentation.

That said, it would probably be useful to have some explicit test coverage of the plugin manager, and get the definitions and verify the label in there?

les lim’s picture

Re: #49, there's already test coverage for getting definitions from DefaultPluginManager in \Drupal\Core\Plugin\DefaultPluginManagerTest->testDefaultPluginManager().

Do you mean we should test this again for MailManager specifically? Seems unnecessary to me.

tim.plunkett’s picture

Overriding getInstance() is not very common, and at least having a unit test for that would be useful.

berdir’s picture

What I was suggesting wouldn't be a unit test as we currently can not unit test annotation based plugin discovery due to @Translation which calls t(). But yes, unit tests for the getInstance() would possibly be useful.

les lim’s picture

StatusFileSize
new32.09 KB
new4.98 KB

Added unit tests -- thanks to Berdir and tim.plunkett for the IRC advice.

sun’s picture

Please note that we have two plugin concepts baked into our current Mail API right now:

  1. Mail formatting

    The gist of format(). Typically implemented by Mimemail module and others, which only care about formatting (and headers), but do NOT care for how the mail is sent in the end.

  2. Mail sending

    The gist of send(). Typically implemented by SMTP module and PHPMailer module, which only (or mostly) care about mail sending, but do not care for how the mail is formatted (as long as mail headers are reflecting the chosen encoding).

I originally assumed that a proper separation of the two concepts was still an unresolved issue for D8, but after grepping core issues, I was only able to find #331180: fix pluggable smtp/mail framework, which is fixed since D7 already.

In any case, a plugin-ification of the mail system should take this separation of concerns into account. — That is, because there is hardly a use-case for a mail plugin in the wild that implements both. - Above mentioned (prime) examples are just a testament to that.

Unless I missed something, the clean separation should exist in core already. It is merely possible that the default PhpMail implementation happens to be a provider for both plugin types, because Drupal core does not support any other format than plain-text. However, that coincidence does not and should not mean that a separation of concerns was not foreseen. :-)

Status: Needs review » Needs work

The last submitted patch, 53: core-2187495-53-mail-to-plugins.patch, failed testing.

les lim’s picture

I originally assumed that a proper separation of the two concepts was still an unresolved issue for D8

It is still unresolved; you might be thinking of #1135262: drupal_mail() should support using different MailSystemInterface classes for format() and mail(). In any case, D8 has MailInterface, which is pretty much identical to D7's MailSystemInterface, both of which mandate implementing both format() and mail() methods in your mail backend.

I would love love looove it if we could do what you're saying, and break this into MailFormatterInterface and MailDeliveryInterface or some such. I'd be more than willing to own the development of that. This is just the patch I thought had a shot of going in, and it does at least unblock contrib from being better able to work around these constraints.

les lim’s picture

Status: Needs work » Needs review
StatusFileSize
new32.3 KB
new1.04 KB

Fixes tests.

les lim’s picture

StatusFileSize
new32.24 KB
new875 bytes

Tweaked #57 to mock LanguageManagerInterface instead of LanguageManager. (HT tim.plunkett)

berdir’s picture

I would really prefer to not complicate this issue further by splitting that up, as much as I agree it would be nicer.

This is already so much better than what we had in 7.x, we already have an initial 8.x port of mailsystem that extends the MailManager and uses an adapter class to make it possible to select two different classes for format() and send(). No longer required to generate code for that as in 7.x :)

andypost’s picture

No reason to make split here. Better to file follow-up for formatting questions, including pointed in #1856562-11: Convert "Subject" and "Message" into Message base fields (2,3)

  1. +++ b/core/lib/Drupal/Core/Annotation/Mail.php
    @@ -0,0 +1,44 @@
    +  public $description;
    
    +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php
    @@ -2,13 +2,21 @@
    + *   description = @Translation("Sends the message as plain text, using PHP's native mail() function.")
    
    +++ b/core/modules/system/tests/modules/system_mail_failure_test/lib/Drupal/system_mail_failure_test/Plugin/Mail/TestPhpMailFailure.php
    @@ -16,16 +16,23 @@
    + *   description = @Translation("An intentionally broken mail backend, used for tests.")
    

    I think description is useless, This should be placed in class description.
    Also "name" could be more informative

  2. +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php
    @@ -2,13 +2,21 @@
    - * Definition of Drupal\Core\Mail\PhpMail.
    + * Definition of Drupal\Core\Mail\Plugin\Mail\PhpMail.
    

    Contains

  3. +++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php
    @@ -2,21 +2,29 @@
    -   * Overrides \Drupal\Core\Mail\PhpMail::mail().
    +   * Overrides \Drupal\Core\Mail\Plugin\Mail\PhpMail::mail().
    
    +++ b/core/modules/system/tests/modules/system_mail_failure_test/lib/Drupal/system_mail_failure_test/Plugin/Mail/TestPhpMailFailure.php
    @@ -16,16 +16,23 @@
    -   * Overrides Drupal\Core\Mail\PhpMail::mail().
    +   * Overrides Drupal\Core\Mail\Plugin\Mail\PhpMail::mail().
    

    @inheritdoc

berdir’s picture

1. Description isn't useless when the plugins are exposed in the UI, e.g. in mailsystem.

3. This adds additional comments. Per our current coding standards, it is not allowed to use @inheritdoc there. That said, it would IMHO be perfectly fine to keep the inline comment there instead. I would say that we don't override the parent class but implement the method defined in the interface and @inheritdoc points to that. Then the inline comment explains that our implementation is simply "always fail".

longwave’s picture

StatusFileSize
new32.5 KB
new3.22 KB

This patch improves some of the comments and labelling. I agree that "description" may be useful in contrib.

longwave’s picture

StatusFileSize
new3.22 KB

Wrong interdiff.

berdir’s picture

@longwave: Those two fails are identical?

Pro-tip: Do not name your interdiff's interdiff.txt. As you can see, they get renamed to interdiff_xxxx.txt, and the way drupal.org figures out what number to use, it has to loop from 1 to (currently) 2386, checking if the file already exists on every loop. That's not nice.

  1. +++ b/core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php
    @@ -0,0 +1,163 @@
    +
    +    // Mock a CachedDiscovery object to replace AnnotationClassDiscovery.
    +    $this->discovery = $this->getMock('Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface');
    +    foreach ($this->definitions as $id => $definition) {
    +      $definitions_map[] = array($id, $definition);
    +    }
    +    $this->discovery->expects($this->any())
    +      ->method('getDefinition')
    +      ->will($this->returnValueMap($definitions_map));
    +    $this->discovery->expects($this->any())
    +      ->method('getDefinitions')
    +      ->will($this->returnValue($this->definitions));
    

    I assume you copied that from the entity manager test, but we have a default plugin manager here, so..

    a) We should just use DiscoveryInterface, not Cached.
    b) getDefinition() on the discovery should *not* be called, so remove that.

  2. +++ b/core/tests/Drupal/Tests/Core/Mail/MailManagerTest.php
    @@ -0,0 +1,163 @@
    +    $interface = array(
    +      'default' => 'php_mail',
    +      'mailmanagertest_getinstance' => 'test_mail_collector',
    +    );
    ...
    +    $options = array('module' => 'mailmanagertest', 'key' => 'getinstance');
    

    Super-minor: module/key seems a bit strange, can we use something like example_testkey instead?

les lim’s picture

StatusFileSize
new42.8 KB
new2.28 KB

Updated for #64.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, this looks good I think!

longwave’s picture

Pro-tip: Do not name your interdiff's interdiff.txt. As you can see, they get renamed to interdiff_xxxx.txt, and the way drupal.org figures out what number to use, it has to loop from 1 to (currently) 2386, checking if the file already exists on every loop. That's not nice.

So isn't this a bug in Drupal/drupal.org that we should consider fixing? :)

les lim’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new32.35 KB

Needed reroll.

les lim’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Was about to commit...

git ac https://drupal.org/files/issues/core-2187495-68-mail-to-plugins.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 33125  100 33125    0     0  18239      0  0:00:01  0:00:01 --:--:-- 28506
error: core/modules/system/lib/Drupal/system/Tests/InstallerTest.php: does not exist in index

:(

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new32.37 KB

core/modules/system/lib/Drupal/system/Tests/InstallerTest.php => core/modules/simpletest/lib/Drupal/simpletest/InstallerTestBase.php

Status: Needs review » Needs work

The last submitted patch, 71: 2187495-mail-plugins-71.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review

71: 2187495-mail-plugins-71.patch queued for re-testing.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the re-roll, back to RTBC then.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 438494d and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.