forked from silverstripe/silverstripe-linkfield
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Add new Owner relation for handling permissions
- Loading branch information
1 parent
3c8edfd
commit 34646cf
Showing
8 changed files
with
223 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace SilverStripe\LinkField\Tests\Form; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\LinkField\Form\LinkField; | ||
use SilverStripe\LinkField\Models\Link; | ||
use SilverStripe\LinkField\Tests\Models\LinkTest\LinkOwner; | ||
|
||
class LinkFieldTest extends SapphireTest | ||
{ | ||
protected $usesDatabase = true; | ||
|
||
protected static $extra_dataobjects = [ | ||
LinkOwner::class, | ||
]; | ||
|
||
/** | ||
* When we save a link into the has_one of a record, we also need to save | ||
* the Owner has_one on the link itself. | ||
*/ | ||
public function testSaveInto() | ||
{ | ||
// Prepare fixtures (need new records for this) | ||
$field = new LinkField('Link'); | ||
$link = new Link(); | ||
$link->write(); | ||
$owner = new LinkOwner(); | ||
$owner->write(); | ||
|
||
// Save link into owner | ||
$field->setValue($link->ID); | ||
$field->saveInto($owner); | ||
// Get the link again - the new values are in the DB. | ||
$link = Link::get()->byID($link->ID); | ||
|
||
// Validate | ||
$this->assertSame($link->ID, $owner->LinkID); | ||
$this->assertSame($owner->ID, $link->OwnerID); | ||
$this->assertSame($owner->ClassName, $link->OwnerClass); | ||
$this->assertSame('Link', $link->OwnerRelation); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace SilverStripe\LinkField\Tests\Models\LinkTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\LinkField\Models\Link; | ||
use SilverStripe\ORM\DataObject; | ||
|
||
class LinkOwner extends DataObject implements TestOnly | ||
{ | ||
private static array $has_one = [ | ||
'Link' => Link::class, | ||
]; | ||
|
||
private static array $has_many = [ | ||
'LinkList' => Link::class . '.Owner', | ||
]; | ||
} |