2016-01-28 22:22:18 +01:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\ORM\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class ManyManyListExtensionTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
|
|
|
protected static $fixture_file = 'ManyManyListExtensionTest.yml';
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
protected static $extra_dataobjects = [
|
2016-12-16 05:34:21 +01:00
|
|
|
ManyManyListTest\IndirectPrimary::class,
|
|
|
|
ManyManyListTest\Secondary::class,
|
|
|
|
ManyManyListTest\SecondarySub::class
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
// Test that when one side of a many-many relationship is added by extension, both
|
|
|
|
// sides still see the extra fields.
|
|
|
|
public function testExtraFieldsViaExtension()
|
|
|
|
{
|
|
|
|
// This extends ManyManyListTest_Secondary with the secondary extension that adds the relationship back
|
|
|
|
// to the primary. The instance from the fixture is ManyManyListTest_SecondarySub, deliberately a sub-class of
|
|
|
|
// the extended class.
|
2017-05-17 07:40:13 +02:00
|
|
|
ManyManyListTest\Secondary::add_extension(ManyManyListTest\IndirectSecondaryExtension::class);
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
// Test from the primary (not extended) to the secondary (which is extended)
|
2017-05-17 07:40:13 +02:00
|
|
|
/** @var ManyManyListTest\IndirectPrimary $primary */
|
2016-12-16 05:34:21 +01:00
|
|
|
$primary = $this->objFromFixture(ManyManyListTest\IndirectPrimary::class, 'manymany_extra_primary');
|
|
|
|
$secondaries = $primary->Secondary();
|
|
|
|
$extraFields = $secondaries->getExtraFields();
|
|
|
|
|
2022-04-14 03:12:59 +02:00
|
|
|
$this->assertTrue(count($extraFields ?? []) > 0, 'has extra fields');
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertTrue(isset($extraFields['DocumentSort']), 'has DocumentSort');
|
|
|
|
|
|
|
|
// Test from the secondary (which is extended) to the primary (not extended)
|
2017-05-17 07:40:13 +02:00
|
|
|
/** @var ManyManyListTest\SecondarySub|ManyManyListTest\IndirectSecondaryExtension $secondary */
|
2016-12-16 05:34:21 +01:00
|
|
|
$secondary = $this->objFromFixture(ManyManyListTest\SecondarySub::class, 'manymany_extra_secondary');
|
|
|
|
|
|
|
|
$primaries = $secondary->Primary();
|
|
|
|
$extraFields = $primaries->getExtraFields();
|
|
|
|
|
2022-04-14 03:12:59 +02:00
|
|
|
$this->assertTrue(count($extraFields ?? []) > 0, 'has extra fields');
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertTrue(isset($extraFields['DocumentSort']), 'has DocumentSort');
|
|
|
|
}
|
2016-01-28 22:22:18 +01:00
|
|
|
}
|