From eea80c74ecb19d8ad46c7384d7f5a8e13d18b0c4 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Fri, 4 Aug 2023 00:19:36 +1200 Subject: [PATCH] Add test for Ajax extension --- tests/php/Extensions/AjaxFieldTest.php | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/php/Extensions/AjaxFieldTest.php 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' + ); + } +}