Follow-up to #700308: Allow separate theming of each individual outgoing email instead of caching the prepared newsletter

Including, but not limited to:

- Verify that sending from a source that only implements the basic source interface works.
- Verify that source is pluggable when sending through the spool
- Verify that the caching is pluggable and can be configured through the UI when sending through the spool.
- Display build time with/without caching. Probably no actual asserts, because this is too dynamic.

Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new14.98 KB
new14.98 KB

Ok, the attached patch adds tests for the first and last point of the above list. Incremental improvements is probably the best way forward here.

The "performance test" does send a newsletter to 100 recipients and then calculates the used time. Locally, cached took around 2,5s while non-cached took around 4s. This is with a very simple body, so this is actually the base. It can be assumed that non-cached gets slower and slower, the more complex your body is, while cached stays relatively constant as it need to do the build only once.

I'll upload a second version of the patch, which prints the time as fails to see them on the testbot.

More importantly, the patch fixes a number of bugs:

- The cached source class is wrong in the hook implementation, which leads to a fatal error when trying to send the test. Fixed and confirmed through the tests
- The build:body:$format cache was not written properly, causing it to be re-generated always. Not directly tested, as this is kinda tricky.

Changes:
- Removed the $accounts argument from simplenews_add_node_to_spool(). It wasn't actually used anymore.
- There is now a SimplenewsSourceInterface::getPlainFooter() method and the getBody() and getFooter() methods are supposed to return the correct content based getFormat(). What they actually already did, it just hadn't been called like this nor documented. Fixed and tested.
- That plaintext footer is now also appended to the plaintext version, which is generated if the format is html.

Status: Needs review » Needs work

The last submitted patch, source_tests_and_bugfixes_error.patch, failed testing.

berdir’s picture

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

Looks like the test source implementation can't lie in the test file...

berdir’s picture

Just noticed another bug, the build isn't internally cached. This is bad because it's used like 4 times during a single mail.

Status: Needs review » Needs work

The last submitted patch, source_tests_and_bugfixes_error2.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new18.6 KB

- build is now properly cached (only per mail, outside of the cache handling)
- Refactored and fixed plaintext/html handling
- Removed a unused function, left-over from an earlier source implementation (poor kitten)

berdir’s picture

Status: Needs review » Active

Commited, back to active for the remaining test cases.

berdir’s picture

Issue summary: View changes

Updated issue summary.

miro_dietiker’s picture

Issue tags: +test candidate

Tagging as test candidate.

berdir’s picture

Assigned: Unassigned » corvus_ch
Issue tags: -test candidate +Needs tests
corvus_ch’s picture

Status: Active » Needs review
StatusFileSize
new5.51 KB
berdir’s picture

Status: Needs review » Needs work
+++ b/tests/simplenews.testundefined
@@ -2794,4 +2794,58 @@ class SimplenewsSourceTestCase extends SimplenewsTestCase {
+    $this->setUpSubscribers(100);

Its enough if we add 3 subscribers, we don't need more.

+++ b/tests/simplenews.testundefined
@@ -2794,4 +2794,58 @@ class SimplenewsSourceTestCase extends SimplenewsTestCase {
+    $edit = array(
+        'title' => $this->randomName(),
+        'body[und][0][value]' => "Mail token: <strong>[simplenews-subscriber:mail]</strong>",

Incorrect indentation.

+++ b/tests/simplenews.testundefined
@@ -2794,4 +2794,58 @@ class SimplenewsSourceTestCase extends SimplenewsTestCase {
+    catch (Exception $e) {
+      // Intentionaly left blank.

You can add a $this->pass('Exception thrown when invalid source implementation is configured').

+++ b/tests/simplenews.testundefined
@@ -2794,4 +2794,58 @@ class SimplenewsSourceTestCase extends SimplenewsTestCase {
+      // Make sure that the same mail was used in the body token as it has been
+      // sent to. Also verify that the mail is plaintext.
+      $this->assertTrue(strpos($mail['subject'], 'the subject') !== FALSE);

The comment should probably be updated say what we are actually testing: that the test source was used and not the default one.

+++ b/includes/simplenews.source.incundefined
@@ -299,6 +307,10 @@ class SimplenewsSpool implements SimplenewsSpoolInterface {
+    if ($interfaces && !in_array('SimplenewsSourceNodeInterface', $interfaces)) {
+      throw new Exception("Source must implement SimplenewsSouceNodeInterface");

Should actually be !$interfaces || ... .

Because if it does not implement any interfaces at all, it is wrong as well.

berdir’s picture

Oh, and the as discussed, a bit of documentation would be nice of the spool and source defgroups.

berdir’s picture

Issue summary: View changes

Updated issue summary.

  • Berdir committed 4b0ffb5 on 8.x-1.x
    Issue #1374930 by Berdir: Fixed various source bugs and added tests.
    
    
corvus_ch’s picture

Assigned: corvus_ch » Unassigned
Issue summary: View changes