-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust ImageForm logic to support new behaviour to be introduce in si…
…lverstripe/assets 1.6
- Loading branch information
Maxime Rainville
committed
Mar 2, 2020
1 parent
847f479
commit 1e72d2d
Showing
3 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
tests/Extensions/FocusPointAssetFormFactoryExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace JonoM\FocusPoint\Tests\Extensions; | ||
|
||
|
||
use JonoM\FocusPoint\Extensions\FocusPointAssetFormFactoryExtension; | ||
use SilverStripe\Assets\Folder; | ||
use SilverStripe\Assets\Image; | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\Tab; | ||
use SilverStripe\Forms\TabSet; | ||
use SilverStripe\Forms\TextField; | ||
|
||
class FocusPointAssetFormFactoryExtensionTest extends SapphireTest | ||
{ | ||
|
||
protected static $fixture_file = '../ImageManipulationTest.yml'; | ||
|
||
public function testUpdateFormFieldsOnImageEditForm() | ||
{ | ||
$ext = new FocusPointAssetFormFactoryExtension(); | ||
|
||
$fields = FieldList::create( | ||
TabSet::create( | ||
'Editor', | ||
Tab::create( | ||
'Details', | ||
TextField::create('Title') | ||
) | ||
) | ||
); | ||
$controller = new Controller(); | ||
$formName = 'fileEditForm'; | ||
$context = [ | ||
'Record' => $this->objFromFixture(Image::class, 'pngLeftTop') | ||
]; | ||
|
||
|
||
$ext->updateFormFields($fields, $controller, $formName, $context); | ||
|
||
$focusField = $fields->fieldByName('Editor.Details.FocusPoint'); | ||
$this->assertNotEmpty($focusField, 'Focus field has been added to image edit form.'); | ||
} | ||
|
||
public function testUpdateFormFieldsOnPlacementForm() | ||
{ | ||
$ext = new FocusPointAssetFormFactoryExtension(); | ||
|
||
$fields = FieldList::create( | ||
TextField::create('Title') | ||
); | ||
$controller = new Controller(); | ||
$formName = 'fileEditForm'; | ||
$context = [ | ||
'Record' => $this->objFromFixture(Image::class, 'pngLeftTop') | ||
]; | ||
|
||
|
||
$ext->updateFormFields($fields, $controller, $formName, $context); | ||
|
||
$focusField = $fields->fieldByName('Editor.Details.FocusPoint'); | ||
$this->assertEmpty($focusField, 'Focus field has NOT been added to the form.'); | ||
} | ||
|
||
public function testUpdateFormFieldsOnNonImageForm() | ||
{ | ||
$ext = new FocusPointAssetFormFactoryExtension(); | ||
|
||
$fields = FieldList::create( | ||
TabSet::create( | ||
'Editor', | ||
Tab::create( | ||
'Details', | ||
TextField::create('Title') | ||
) | ||
) | ||
); | ||
$controller = new Controller(); | ||
$formName = 'fileEditForm'; | ||
$context = [ | ||
'Record' => $this->objFromFixture(Folder::class, 'folder1') | ||
]; | ||
|
||
$ext->updateFormFields($fields, $controller, $formName, $context); | ||
|
||
$focusField = $fields->fieldByName('Editor.Details.FocusPoint'); | ||
$this->assertEmpty($focusField, 'Focus field has NOT been added to the form.'); | ||
} | ||
} |