Merge branch '5.5' into 5

This commit is contained in:
Steve Boyd 2020-05-27 13:41:51 +12:00
commit e54a825ea3
6 changed files with 90 additions and 14 deletions

View File

@ -4,6 +4,7 @@ dist: xenial
services:
- mysql
- postgresql
env:
global:
@ -12,17 +13,15 @@ env:
matrix:
include:
- php: 5.6
env: DB=MYSQL RECIPE_VERSION=4.3.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0
env: DB=MYSQL RECIPE_VERSION=4.3.x-dev PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL RECIPE_VERSION=4.4.x-dev PHPUNIT_COVERAGE_TEST=1
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1 PHPCS_TEST=1
- php: 7.2
env: DB=PGSQL RECIPE_VERSION=4.4.x-dev PHPUNIT_TEST=1 NPM_TEST=1
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1 NPM_TEST=1
- php: 7.3
env: DB=MYSQL RECIPE_VERSION=4.5.x-dev PHPUNIT_TEST=1
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1 PHPUNIT_COVERAGE_TEST=1
- php: 7.3
env: DB=PGSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1
- php: 7.4
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1
before_script:
@ -34,7 +33,7 @@ before_script:
# Install composer dependencies
- composer validate
- composer require --no-update silverstripe/recipe-cms:$RECIPE_VERSION
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.2.x-dev; fi
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev --prefer-dist; fi
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- if [[ $NPM_TEST ]]; then nvm install $TRAVIS_NODE_VERSION && nvm use $TRAVIS_NODE_VERSION && npm install -g yarn && yarn install --network-concurrency 1 && yarn run build; fi

View File

@ -5,6 +5,7 @@ namespace SilverStripe\UserForms\Control;
use Exception;
use PageController;
use Psr\Log\LoggerInterface;
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Upload;
use SilverStripe\Control\Controller;
@ -200,7 +201,7 @@ class UserDefinedFormController extends PageController
});
})(jQuery);
JS
, 'UserFormsConditional-' . $form->ID);
, 'UserFormsConditional-' . $form->ID);
}
}
@ -255,10 +256,8 @@ JS
// create the file from post data
$upload = Upload::create();
$file = File::create();
$file->ShowInSearch = 0;
try {
$upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
$upload->loadIntoFile($_FILES[$field->Name], null, $foldername);
} catch (ValidationException $e) {
$validationResult = $e->getResult();
foreach ($validationResult->getMessages() as $message) {
@ -267,6 +266,16 @@ JS
Controller::curr()->redirectBack();
return;
}
/** @var AssetContainer|File $file */
$file = $upload->getFile();
$file->ShowInSearch = 0;
$file->write();
// generate image thumbnail to show in asset-admin
// you can run userforms without asset-admin, so need to ensure asset-admin is installed
if (class_exists(AssetAdmin::class)) {
AssetAdmin::singleton()->generateThumbnails($file);
}
// write file to form field
$submittedField->UploadedFileID = $file->ID;

View File

@ -2,14 +2,21 @@
namespace SilverStripe\UserForms\Tests\Control;
use SilverStripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Upload_Validator;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction;
use SilverStripe\ORM\DataObject;
use SilverStripe\UserForms\Control\UserDefinedFormController;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
@ -32,9 +39,18 @@ class UserDefinedFormControllerTest extends FunctionalTest
{
parent::setUp();
// Set backend and base url
TestAssetStore::activate('AssetStoreTest');
Config::modify()->merge(SSViewer::class, 'themes', ['simple', '$default']);
}
public function tearDown()
{
TestAssetStore::reset();
parent::tearDown();
}
public function testProcess()
{
$form = $this->setupFormFrontend();
@ -367,4 +383,40 @@ class UserDefinedFormControllerTest extends FunctionalTest
// check emails
$this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject: Basic Value');
}
public function testImageThumbnailCreated()
{
Config::modify()->set(Upload_Validator::class, 'use_is_uploaded_file', false);
$userForm = $this->setupFormFrontend('upload-form');
$controller = UserDefinedFormController::create($userForm);
$field = $this->objFromFixture(EditableFileField::class, 'file-field-1');
$path = realpath(__DIR__ . '/fixtures/testfile.jpg');
$data = [
$field->Name => [
'name' => 'testfile.jpg',
'type' => 'image/jpeg',
'tmp_name' => $path,
'error' => 0,
'size' => filesize($path),
]
];
$_FILES[$field->Name] = $data[$field->Name];
$controller->getRequest()->setSession(new Session([]));
$controller->process($data, $controller->Form());
/** @var File $image */
// Getting File instead of Image so that we still delete the physical file in case it was
// created with the wrong ClassName
// Using StartsWith in-case of existing file so was created as testfile-v2.jpg
$image = File::get()->filter(['Name:StartsWith' => 'testfile'])->last();
$this->assertNotNull($image);
// Assert thumbnail variant created
/** @var AssetStore $store */
$store = Injector::inst()->get(AssetStore::class);
$this->assertTrue($store->exists($image->getFilename(), $image->getHash(), 'FitMaxWzM1MiwyNjRd'));
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -176,8 +176,14 @@ class UserDefinedFormTest extends FunctionalTest
$result = $recipient->getEmailTemplateDropdownValues();
// Installation path can be as a project when testing in Travis, so check partial match
$this->assertContains('email' . DIRECTORY_SEPARATOR . 'SubmittedFormEmail', key($result));
$this->assertSame('SubmittedFormEmail', current($result));
$foundKey = false;
foreach (array_keys($result) as $key) {
if (strpos($key, 'email' . DIRECTORY_SEPARATOR . 'SubmittedFormEmail') !== false) {
$foundKey = true;
}
}
$this->assertTrue($foundKey);
$this->assertTrue(in_array('SubmittedFormEmail', array_values($result)));
}
public function testEmailTemplateExists()

View File

@ -247,6 +247,11 @@ SilverStripe\UserForms\Model\EditableFormField\EditableRadioField:
- =>SilverStripe\UserForms\Model\EditableFormField\EditableOption.option-y-2
- =>SilverStripe\UserForms\Model\EditableFormField\EditableOption.option-n-2
SilverStripe\UserForms\Model\EditableFormField\EditableFileField:
file-field-1:
Name: 'file_field_name'
Title: 'File field title'
SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd:
group1end:
Name: group1end
@ -437,6 +442,11 @@ SilverStripe\UserForms\Model\UserDefinedForm:
Fields:
- =>SilverStripe\UserForms\Model\EditableFormField\EditableDropdown.basic-dropdown
upload-form:
Title: 'Form with upload field'
Fields:
- =>SilverStripe\UserForms\Model\EditableFormField\EditableFileField.file-field-1
SilverStripe\UserForms\Model\EditableCustomRule:
rule1:
Display: Show