Created
July 12, 2018 22:27
-
-
Save robbieaverill/0e86150ff96a89f3ec57d1eded0ddb79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
use DNADesign\Elemental\Extensions\ElementalPageExtension; | |
use DNADesign\Elemental\Models\ElementalArea; | |
use Elemental220Test\StubBlock; | |
use Elemental220Test\StubExtension; | |
use Elemental220Test\StubPage; | |
use SilverStripe\Dev\SapphireTest; | |
class Elemental220Test extends SapphireTest | |
{ | |
protected static $required_extensions = [ | |
StubPage::class => [ | |
ElementalPageExtension::class, | |
], | |
// This extension should prove the bug - comment the following 3 lines out and tests pass | |
ElementalArea::class => [ | |
StubExtension::class, | |
], | |
]; | |
protected static $extra_dataobjects = [ | |
StubPage::class, | |
StubBlock::class, | |
]; | |
protected $usesDatabase = true; | |
public function testDuplicationBug() | |
{ | |
// Create a page and elemental area | |
$page = new StubPage(); | |
$page->Title = 'Test Page'; | |
$page->write(); | |
$this->assertNotEmpty($page->ElementalAreaID, 'Page is assigned an elemental area on write'); | |
// Create two blocks and assign them to the elemental area for the page | |
$block1 = new StubBlock(); | |
$block1->ParentID = $page->ElementalAreaID; | |
$block1->write(); | |
$block2 = new StubBlock(); | |
$block2->ParentID = $page->ElementalAreaID; | |
$block2->write(); | |
$this->assertCount(2, $page->ElementalArea()->Elements(), 'Page has two blocks'); | |
// Duplicate the page | |
$page2 = $page->duplicate(); | |
$this->assertNotEmpty($page2->ElementalAreaID, 'Duplicated page has an elemental area'); | |
$this->assertNotEquals($page->ElementalAreaID, $page2->ElementalAreaID, 'Elemental areas are different'); | |
$this->assertCount(2, $page2->ElementalArea()->Elements(), 'Duplicated page has blocks'); | |
$this->assertNotEquals( | |
$page->ElementalArea()->Elements()->column('ID'), | |
$page2->ElementalArea()->Elements()->column('ID'), | |
'Blocks are different instances' | |
); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace Elemental220Test; | |
use DNADesign\Elemental\Models\BaseElement; | |
use SilverStripe\Dev\TestOnly; | |
class StubBlock extends BaseElement implements TestOnly | |
{ | |
} |
This file contains hidden or 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
<?php | |
namespace Elemental220Test; | |
use SilverStripe\ORM\DataExtension; | |
class StubExtension extends DataExtension | |
{ | |
/** | |
* This config is already defined on BaseElement - applying it with an extension as well | |
* results in duplication happening twice | |
*/ | |
private static $cascade_duplicates = ['Elements']; | |
} |
This file contains hidden or 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
<?php | |
namespace Elemental220Test; | |
use Page; | |
use SilverStripe\Dev\TestOnly; | |
class StubPage extends Page implements TestOnly | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment