-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEW Allow developers to exclude LinkText field #215
Merged
emteknetnz
merged 1 commit into
silverstripe:4
from
creative-commoners:pulls/4/no-link-text
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ | |
|
||
namespace SilverStripe\LinkField\Tests\Controllers; | ||
|
||
use SilverStripe\CMS\Model\SiteTree; | ||
use ReflectionMethod; | ||
use SilverStripe\Dev\FunctionalTest; | ||
use SilverStripe\LinkField\Tests\Controllers\LinkFieldControllerTest\TestPhoneLink; | ||
use SilverStripe\Core\Config\Config; | ||
Comment on lines
-5
to
-8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
use SilverStripe\Security\SecurityToken; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Control\Session; | ||
use SilverStripe\LinkField\Controllers\LinkFieldController; | ||
use SilverStripe\LinkField\Tests\Models\LinkTest\LinkOwner; | ||
|
||
class LinkFieldControllerTest extends FunctionalTest | ||
|
@@ -156,6 +157,50 @@ public function provideLinkFormGetSchema(): array | |
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideExcludeLinkTextField | ||
*/ | ||
public function testExcludeLinkTextField(bool $excludeLinkTextField): void | ||
{ | ||
$owner = $this->getFixtureLinkOwner(); | ||
$itemID = $this->getID('existing'); | ||
$vars = [ | ||
'ownerID' => $owner->ID, | ||
'ownerClass' => $owner->ClassName, | ||
'ownerRelation' => 'Link', | ||
]; | ||
if ($excludeLinkTextField) { | ||
$vars['excludeLinkTextField'] = true; | ||
} | ||
// Build request and controller to get the scaffolded form | ||
$request = new HTTPRequest('GET', 'linkForm/' . $itemID, getVars: $vars); | ||
$request->setSession(new Session([])); | ||
$controller = new LinkFieldController(); | ||
$reflectionFindAction = new ReflectionMethod($controller, 'findAction'); | ||
$reflectionFindAction->setAccessible(true); | ||
$reflectionFindAction->invoke($controller, $request); | ||
$controller->setRequest($request); | ||
$form = $controller->linkForm(); | ||
// Check if the field is there or not | ||
if ($excludeLinkTextField) { | ||
$this->assertNull($form->Fields()->dataFieldByName('LinkText')); | ||
} else { | ||
$this->assertNotNull($form->Fields()->dataFieldByName('LinkText')); | ||
} | ||
} | ||
|
||
public function provideExcludeLinkTextField(): array | ||
{ | ||
return [ | ||
'exclude field' => [ | ||
'excludeLinkTextField' => true, | ||
], | ||
'dont exclude field' => [ | ||
'excludeLinkTextField' => false, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideLinkFormPost | ||
*/ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to create a whole separate trait just for this, nor did I want to duplicate code by putting it into each field.
I've added a note to #78 to consider combining the traits into an abstract class instead - assuming that is done, it doesn't matter too much where this code goes for this PR since it'll all end up in the same place anyway.