From 1bd0b0c138e23c8324c4ff2cc5d93c25043b4968 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 16 Aug 2017 11:57:50 +1200 Subject: [PATCH] FIX Update EmailRecipient to look in root directory for templates, optionally, fix other tests --- .travis.yml | 2 +- code/Model/Recipient/EmailRecipient.php | 7 ++++++- tests/Form/UserFormTest.php | 2 +- tests/Model/UserDefinedFormControllerTest.php | 9 ++++++++- .../Model/UserDefinedFormControllerTest.ss | 0 5 files changed, 16 insertions(+), 4 deletions(-) rename tests/templates/SilverStripe/UserForms/{Test => Tests}/Model/UserDefinedFormControllerTest.ss (100%) diff --git a/.travis.yml b/.travis.yml index b2b0424..5c87d50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_script: # Install composer dependencies - composer install --prefer-dist - - composer require --prefer-dist --no-update silverstripe/framework:4.0.x-dev silverstripe/cms:4.0.x-dev silverstripe/admin:1.0.x-dev silverstripe/versioned:1.0.x-dev + - composer require --prefer-dist --no-update silverstripe/framework:4.0.x-dev silverstripe/cms:4.0.x-dev silverstripe/admin:1.0.x-dev silverstripe/versioned:1.0.x-dev silverstripe-themes/simple:~3.2 - composer update script: diff --git a/code/Model/Recipient/EmailRecipient.php b/code/Model/Recipient/EmailRecipient.php index 6437bcc..b1d4ff9 100644 --- a/code/Model/Recipient/EmailRecipient.php +++ b/code/Model/Recipient/EmailRecipient.php @@ -521,7 +521,12 @@ class EmailRecipient extends DataObject $finder = new FileFinder(); $finder->setOption('name_regex', '/^.*\.ss$/'); - $found = $finder->find(BASE_PATH . '/' . UserDefinedForm::config()->get('email_template_directory')); + $templateDirectory = UserDefinedForm::config()->get('email_template_directory'); + // Handle cases where "userforms" might not be the base module directory, e.g. in a Travis build + if (!file_exists($templateDirectory) && substr($templateDirectory, 0, 10) === 'userforms/') { + $templateDirectory = substr($templateDirectory, 10); + } + $found = $finder->find(BASE_PATH . '/' . $templateDirectory); foreach ($found as $key => $value) { $template = pathinfo($value); diff --git a/tests/Form/UserFormTest.php b/tests/Form/UserFormTest.php index 68ef1dd..650baad 100644 --- a/tests/Form/UserFormTest.php +++ b/tests/Form/UserFormTest.php @@ -9,7 +9,7 @@ use SilverStripe\UserForms\Form\UserForm; class UserFormTest extends SapphireTest { - protected static $fixture_file = 'userforms/tests/Model/UserDefinedFormTest.yml'; + protected static $fixture_file = '../Model/UserDefinedFormTest.yml'; /** * Tests that a form will not generate empty pages diff --git a/tests/Model/UserDefinedFormControllerTest.php b/tests/Model/UserDefinedFormControllerTest.php index 11856b2..d2cbbe9 100644 --- a/tests/Model/UserDefinedFormControllerTest.php +++ b/tests/Model/UserDefinedFormControllerTest.php @@ -15,17 +15,24 @@ use SilverStripe\UserForms\Model\Submission\SubmittedFormField; use SilverStripe\UserForms\Model\UserDefinedForm; use SilverStripe\UserForms\Model\UserDefinedFormController; use SilverStripe\View\ArrayData; +use SilverStripe\View\SSViewer; /** * @package userforms */ - class UserDefinedFormControllerTest extends FunctionalTest { protected static $fixture_file = 'UserDefinedFormTest.yml'; protected static $use_draft_site = true; + protected function setUp() + { + parent::setUp(); + + Config::modify()->set(SSViewer::class, 'themes', ['simple', '$default']); + } + public function testProcess() { $form = $this->setupFormFrontend(); diff --git a/tests/templates/SilverStripe/UserForms/Test/Model/UserDefinedFormControllerTest.ss b/tests/templates/SilverStripe/UserForms/Tests/Model/UserDefinedFormControllerTest.ss similarity index 100% rename from tests/templates/SilverStripe/UserForms/Test/Model/UserDefinedFormControllerTest.ss rename to tests/templates/SilverStripe/UserForms/Tests/Model/UserDefinedFormControllerTest.ss