diff --git a/tests/php/Extensions/AjaxFieldTest.php b/tests/php/Extensions/AjaxFieldTest.php new file mode 100644 index 0000000..74cf75e --- /dev/null +++ b/tests/php/Extensions/AjaxFieldTest.php @@ -0,0 +1,88 @@ +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' + ); + } +}