Skip to content

Commit f363d27

Browse files
committed
Simplify and add test coverage
1 parent 186a426 commit f363d27

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

src/Service/FixtureService.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,6 @@ private function addDataObjectManyManyThroughFields(DataObject $dataObject): voi
570570
$relatedObjects = $dataObject->relField($relationFieldName);
571571

572572
foreach ($relatedObjects as $relatedObject) {
573-
// Check to see if this class has requested that it not be included in relationship maps
574-
$excludeClass = Config::inst()->get($relatedObject->ClassName, 'exclude_from_fixture_relationships');
575-
576-
// Yup, exclude this class
577-
if ($excludeClass) {
578-
continue;
579-
}
580-
581573
// Add the related DataObject as one of our resolved relationships
582574
$resolvedRelationships[] = sprintf('=>%s.%s', $relatedObject->ClassName, $relatedObject->ID);
583575

tests/Service/FixtureServiceTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,84 @@ public function testManyManyRelationship(): void
172172
$this->assertSame($expected, $parsed);
173173
}
174174

175+
public function testManyManyTagExcludeFromFixtureRelationships(): void
176+
{
177+
MockTag::config()->set('exclude_from_fixture_relationships', true);
178+
179+
$page = MockPage::create();
180+
$page->Title = 'Page Excluding Tags';
181+
$page->write();
182+
183+
$tag = MockTag::create();
184+
$tag->Title = 'Excluded Tag';
185+
$tag->write();
186+
187+
$page->Tags()->add($tag);
188+
189+
$service = new FixtureService();
190+
$service->addDataObject($page);
191+
192+
$expected = [
193+
MockPage::class => [
194+
$page->ID => ['Title' => 'Page Excluding Tags'],
195+
],
196+
];
197+
198+
$this->assertSame($expected, Yaml::parse($service->outputFixture()));
199+
}
200+
201+
public function testManyManyPageExcludedFromFixtureRelationships(): void
202+
{
203+
MockPage::config()->set('excluded_fixture_relationships', ['Tags']);
204+
205+
$page = MockPage::create();
206+
$page->Title = 'Page Excluding Tags Relation';
207+
$page->write();
208+
209+
$tag = MockTag::create();
210+
$tag->Title = 'Excluded Via Relation';
211+
$tag->write();
212+
213+
$page->Tags()->add($tag);
214+
215+
$service = new FixtureService();
216+
$service->addDataObject($page);
217+
218+
$expected = [
219+
MockPage::class => [
220+
$page->ID => ['Title' => 'Page Excluding Tags Relation'],
221+
],
222+
];
223+
224+
$this->assertSame($expected, Yaml::parse($service->outputFixture()));
225+
}
226+
227+
public function testManyManyThroughExcludedFixtureRelationships(): void
228+
{
229+
MockPage::config()->set('excluded_fixture_relationships', ['ThroughTargets']);
230+
231+
$page = MockPage::create();
232+
$page->Title = 'Page Excluding Through';
233+
$page->write();
234+
235+
$target = MockThroughTarget::create();
236+
$target->Title = 'Excluded Through Target';
237+
$target->write();
238+
239+
$page->ThroughTargets()->add($target);
240+
241+
$service = new FixtureService();
242+
$service->addDataObject($page);
243+
244+
$expected = [
245+
MockPage::class => [
246+
$page->ID => ['Title' => 'Page Excluding Through'],
247+
],
248+
];
249+
250+
$this->assertSame($expected, Yaml::parse($service->outputFixture()));
251+
}
252+
175253
public function testManyManyThroughRelationship(): void
176254
{
177255
$page = MockPage::create();

0 commit comments

Comments
 (0)