-
Notifications
You must be signed in to change notification settings - Fork 13
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
MNT Behat test LinkField page and LinkField block #162
MNT Behat test LinkField page and LinkField block #162
Conversation
Both of these should be able to be added as |
8307847
to
04f6755
Compare
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.
Convert the block to an extension that's applied to ElementContent (not BaseElement) and move these classes to the LinkField PR
Also add relevant namespaces to classes after you've done this
use SilverStripe\ORM\DataExtension; | ||
|
||
class LinkPageExtension extends DataExtension |
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.
use SilverStripe\ORM\DataExtension; | |
class LinkPageExtension extends DataExtension | |
use SilverStripe\ORM\Extension; | |
use SilverStripe\Dev\TestOnly; | |
class LinkPageExtension extends Extension implements TestOnly |
DataExtension will be removed in a future version
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.
Updated
<?php | ||
|
||
namespace SilverStripe\FrameworkTest\LinkField\Blocks; | ||
|
||
use DNADesign\Elemental\Models\BaseElement; | ||
use SilverStripe\LinkField\Form\LinkField; | ||
use SilverStripe\LinkField\Form\MultiLinkField; | ||
use SilverStripe\LinkField\Models\Link; | ||
use SilverStripe\LinkField\Models\EmailLink; | ||
use SilverStripe\LinkField\Models\PhoneLink; | ||
use SilverStripe\LinkField\Models\SiteTreeLink; | ||
|
||
class LinksListBlock extends BaseElement | ||
{ | ||
private static string $icon = 'font-icon-block-file-list'; | ||
|
||
private static string $table_name = 'LinksListBlock'; | ||
|
||
private static string $singular_name = 'Links List Block'; | ||
|
||
private static string $plural_name = 'Links List Blocks'; | ||
|
||
private static string $description = 'Displays a set of links which can be internal page links, external urls or ' | ||
. 'file links.'; | ||
|
||
private static bool $inline_editable = true; | ||
|
||
private static array $has_one = [ | ||
'OneLink' => Link::class, | ||
]; | ||
|
||
private static $has_many = [ | ||
'ManyLinks' => Link::class . '.Owner', | ||
]; | ||
|
||
private static array $owns = [ | ||
'OneLink', | ||
'ManyLinks', | ||
]; | ||
|
||
private static array $cascade_deletes = [ | ||
'OneLink', | ||
'ManyLinks', | ||
]; | ||
|
||
private static array $cascade_duplicates = [ | ||
'OneLink', | ||
'ManyLinks', | ||
]; | ||
|
||
public function getType(): string | ||
{ | ||
return _t(self::class . '.BlockType', 'Links List'); | ||
} | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
|
||
$fields->removeByName(['OneLinkID', 'ManyLinks']); | ||
|
||
$fields->addFieldsToTab( | ||
'Root.Main', | ||
[ | ||
LinkField::create('OneLink') | ||
->setAllowedTypes([ | ||
SiteTreeLink::class, | ||
EmailLink::class, | ||
PhoneLink::class | ||
]), | ||
MultiLinkField::create('ManyLinks'), | ||
], | ||
); | ||
|
||
return $fields; | ||
} | ||
} |
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.
<?php | |
namespace SilverStripe\FrameworkTest\LinkField\Blocks; | |
use DNADesign\Elemental\Models\BaseElement; | |
use SilverStripe\LinkField\Form\LinkField; | |
use SilverStripe\LinkField\Form\MultiLinkField; | |
use SilverStripe\LinkField\Models\Link; | |
use SilverStripe\LinkField\Models\EmailLink; | |
use SilverStripe\LinkField\Models\PhoneLink; | |
use SilverStripe\LinkField\Models\SiteTreeLink; | |
class LinksListBlock extends BaseElement | |
{ | |
private static string $icon = 'font-icon-block-file-list'; | |
private static string $table_name = 'LinksListBlock'; | |
private static string $singular_name = 'Links List Block'; | |
private static string $plural_name = 'Links List Blocks'; | |
private static string $description = 'Displays a set of links which can be internal page links, external urls or ' | |
. 'file links.'; | |
private static bool $inline_editable = true; | |
private static array $has_one = [ | |
'OneLink' => Link::class, | |
]; | |
private static $has_many = [ | |
'ManyLinks' => Link::class . '.Owner', | |
]; | |
private static array $owns = [ | |
'OneLink', | |
'ManyLinks', | |
]; | |
private static array $cascade_deletes = [ | |
'OneLink', | |
'ManyLinks', | |
]; | |
private static array $cascade_duplicates = [ | |
'OneLink', | |
'ManyLinks', | |
]; | |
public function getType(): string | |
{ | |
return _t(self::class . '.BlockType', 'Links List'); | |
} | |
public function getCMSFields() | |
{ | |
$fields = parent::getCMSFields(); | |
$fields->removeByName(['OneLinkID', 'ManyLinks']); | |
$fields->addFieldsToTab( | |
'Root.Main', | |
[ | |
LinkField::create('OneLink') | |
->setAllowedTypes([ | |
SiteTreeLink::class, | |
EmailLink::class, | |
PhoneLink::class | |
]), | |
MultiLinkField::create('ManyLinks'), | |
], | |
); | |
return $fields; | |
} | |
} | |
<?php | |
use SilverStripe\Core\Extension; | |
use SilverStripe\Dev\TestOnly; | |
use SilverStripe\LinkField\Models\SiteTreeLink; | |
use SilverStripe\LinkField\Models\EmailLink; | |
use SilverStripe\LinkField\Models\PhoneLink; | |
use SilverStripe\LinkField\Form\MultiLinkField; | |
use SilverStripe\LinkField\Form\LinkField; | |
use SilverStripe\LinkField\Models\Link; | |
class ElementContentExtension extends Extension implements TestOnly | |
{ | |
private static bool $inline_editable = true; | |
private static array $has_one = [ | |
'OneLink' => Link::class, | |
]; | |
private static $has_many = [ | |
'ManyLinks' => Link::class . '.Owner', | |
]; | |
private static array $owns = [ | |
'OneLink', | |
'ManyLinks', | |
]; | |
private static array $cascade_deletes = [ | |
'OneLink', | |
'ManyLinks', | |
]; | |
private static array $cascade_duplicates = [ | |
'OneLink', | |
'ManyLinks', | |
]; | |
public function updateCMSFields($fields) | |
{ | |
$fields->removeByName(['OneLinkID', 'ManyLinks']); | |
$fields->addFieldsToTab( | |
'Root.Main', | |
[ | |
LinkField::create('OneLink') | |
->setAllowedTypes([ | |
SiteTreeLink::class, | |
EmailLink::class, | |
PhoneLink::class | |
]), | |
MultiLinkField::create('ManyLinks'), | |
], | |
); | |
} | |
} | |
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.
Updated. Unfortunately, we cannot use TestOnly
. Please see this comment. I created new issue for this.
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.
@emteknetnz, for using Extension
in these test classes I need to rebuild db, since I need to add new relations between classes. For doing this I need to update this block of code, that can be the potential problem for another behat tests in another modules. Do you want me to update FixtureContext
as part of this PR? Or if we are planning to get rid of DataExtension
in the future then we will make required updates and all test classes will extend DataExtension
for now?
Note: As temporary solution I can enforce execution of dev/build
as additional step. What would you prefer?
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.
Don't worry about refactoring other things right now. For now simply make this a regular Extension and add a step to manually run dev/build
Does this work even with TestOnly though? If it doesn't could you double check with Guy who seems pretty certain that shouldn't need to use non-TestOnly in frameworktest
04f6755
to
7d21d8c
Compare
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.
Ideally we don't need this PR, and all the code here should be in linkfield as TestOnly extensions.
If you're having trouble getting that to work please double check with Guy about the specifics of getting this to work
We have already discussed this issue last week and I added new ticket silverstripe/silverstripe-behat-extension#260 to fix this issue. Unfortunately, there are some problems with getting |
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.
These files need to be in the LinkField PR, and this PR should be closed
I tested this locally, while it's true you cannot use TestOnly classes within framework test, if you added them into LinkField they will work
For instance add LinkPageExtension to vendor/silverstripe/linkfield/tests/php/Extensions/LinkFieldExtension.php and change the namespace to SilverStripe\LinkField\Tests\Extensions\LinkPageExtension and make it implement TestOnly, and update the behat test to add this extension. The behat test will work correctly.
use SilverStripe\LinkField\Models\EmailLink; | ||
use SilverStripe\LinkField\Models\PhoneLink; | ||
use SilverStripe\LinkField\Models\SiteTreeLink; | ||
use SilverStripe\ORM\DataExtension; |
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.
use SilverStripe\ORM\DataExtension; |
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.
Updated
LinkField::create('HasOneLink') | ||
->setAllowedTypes([ | ||
SiteTreeLink::class, | ||
EmailLink::class, | ||
PhoneLink::class | ||
]), |
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.
LinkField::create('HasOneLink') | |
->setAllowedTypes([ | |
SiteTreeLink::class, | |
EmailLink::class, | |
PhoneLink::class | |
]), | |
LinkField::create('HasOneLink') | |
->setAllowedTypes([ | |
SiteTreeLink::class, | |
EmailLink::class, | |
PhoneLink::class | |
]), |
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.
Updated
@emteknetnz, Did all tests run successfully? I still have the same problem with |
@sabina-talipova OK don't worry about trying to get these into linkfield module, it really is technically just too hard There's still a couple of remaining minor changes on this PR |
7d21d8c
to
7318985
Compare
7318985
to
60230da
Compare
Parent issue