-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maxime Rainville
committed
Aug 3, 2023
1 parent
1e249a4
commit eea80c7
Showing
1 changed file
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace SilverStripe\AnyField\Tests\Extensions; | ||
|
||
use SilverStripe\Admin\LeftAndMain; | ||
use SilverStripe\Forms\TreeDropdownField; | ||
use SilverStripe\CMS\Model\SiteTree; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\AnyField\Extensions\AjaxField; | ||
use SilverStripe\CMS\Forms\AnchorSelectorField; | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Control\Director; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Control\Session; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\LinkField\Models\SiteTreeLink; | ||
|
||
class AjaxFieldTest extends SapphireTest | ||
{ | ||
|
||
protected $use_database = false; | ||
|
||
public function testExtensionApplied() | ||
{ | ||
$field = TreeDropdownField::create('Name', 'Label', SiteTree::class); | ||
$this->assertTrue($field->hasExtension(AjaxField::class), 'AjaxField is applied to TreeDropdownField'); | ||
|
||
$field = AnchorSelectorField::create('Name'); | ||
$this->assertTrue($field->hasExtension(AjaxField::class), 'AjaxField is applied to TreeDropdownField'); | ||
} | ||
|
||
public function testUpdateLinkModalForm() | ||
{ | ||
$request = new HTTPRequest( | ||
'GET', | ||
'admin/methodSchema/Modals/AnyFieldForm', | ||
['key' => SiteTreeLink::class], | ||
[] | ||
); | ||
$request->setSession(new Session([])); | ||
$leftAndMain = LeftAndMain::create(); | ||
$controller = $leftAndMain->Modals(); | ||
$leftAndMain->setRequest($request); | ||
|
||
$field = TreeDropdownField::create('Name', 'Label', SiteTree::class); | ||
|
||
Form::create( | ||
$controller, | ||
'Modals/AnyFieldForm', | ||
FieldList::create($field) | ||
); | ||
|
||
$this->assertEquals( | ||
'admin/Modals/Modals/AnyFieldForm/field/Name?key=' . urlencode(SiteTreeLink::class), | ||
$field->Link(), | ||
'Link is updated with the key' | ||
); | ||
} | ||
|
||
public function testDontUpdateLinkModalForm() | ||
{ | ||
$request = new HTTPRequest( | ||
'GET', | ||
'admin', | ||
['key' => SiteTreeLink::class], | ||
[] | ||
); | ||
$request->setSession(new Session([])); | ||
$leftAndMain = LeftAndMain::create(); | ||
$leftAndMain->setRequest($request); | ||
|
||
$field = TreeDropdownField::create('Name', 'Label', SiteTree::class); | ||
|
||
Form::create( | ||
$leftAndMain, | ||
'LeftAndMain', | ||
FieldList::create($field) | ||
); | ||
|
||
$this->assertEquals( | ||
'admin/LeftAndMain/field/Name', | ||
$field->Link(), | ||
'Link is updated with the key' | ||
); | ||
} | ||
} |