From faf04bff4384bc2998f73ecd675f78f11696ad2d Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 24 Aug 2017 15:29:27 +1200 Subject: [PATCH] FIX Tests for email templates and whether they exist or not --- code/Model/Recipient/EmailRecipient.php | 13 ++++++++----- tests/Model/UserDefinedFormTest.php | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/code/Model/Recipient/EmailRecipient.php b/code/Model/Recipient/EmailRecipient.php index e3b5b2c..21365dd 100644 --- a/code/Model/Recipient/EmailRecipient.php +++ b/code/Model/Recipient/EmailRecipient.php @@ -499,7 +499,7 @@ class EmailRecipient extends DataObject { $t = ($template ? $template : $this->EmailTemplate); - return in_array($t, $this->getEmailTemplateDropdownValues()); + return array_key_exists($t, $this->getEmailTemplateDropdownValues()); } /** @@ -543,10 +543,13 @@ class EmailRecipient extends DataObject strlen(BASE_PATH) + 1 ); - $defaultPrefix = 'userforms/templates/'; - // Remove default userforms folder if it's provided - if (substr($templatePath, 0, strlen($defaultPrefix)) === $defaultPrefix) { - $templatePath = substr($templatePath, strlen($defaultPrefix)); + $defaultPrefixes = ['userforms/templates/', 'templates/']; + foreach ($defaultPrefixes as $defaultPrefix) { + // Remove default userforms folder if it's provided + if (substr($templatePath, 0, strlen($defaultPrefix)) === $defaultPrefix) { + $templatePath = substr($templatePath, strlen($defaultPrefix)); + break; + } } $templates[$templatePath] = $template['filename']; } diff --git a/tests/Model/UserDefinedFormTest.php b/tests/Model/UserDefinedFormTest.php index 0deffae..29bb359 100644 --- a/tests/Model/UserDefinedFormTest.php +++ b/tests/Model/UserDefinedFormTest.php @@ -160,7 +160,7 @@ class UserDefinedFormTest extends FunctionalTest { $recipient = new EmailRecipient(); - $defaultValues = ['SubmittedFormEmail' => 'SubmittedFormEmail']; + $defaultValues = ['email/SubmittedFormEmail' => 'SubmittedFormEmail']; $this->assertEquals($recipient->getEmailTemplateDropdownValues(), $defaultValues); }