From 5ea238c58bb1c3eaecdeb936fb4c5a0a04421054 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 14 Mar 2017 09:39:26 +1300 Subject: [PATCH] MINOR: Add a Versioned test for #6680 It turns out that cascaded query params as described in #6680 were already implemented; this test confirms that. --- tests/php/ORM/VersionedTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/php/ORM/VersionedTest.php b/tests/php/ORM/VersionedTest.php index 003e56efe..80cdbc438 100644 --- a/tests/php/ORM/VersionedTest.php +++ b/tests/php/ORM/VersionedTest.php @@ -1020,6 +1020,35 @@ class VersionedTest extends SapphireTest } } + /** + * Test that that stage a record was queried from cascades to child relations, even if the + * global stage has changed + */ + public function testStageCascadeOnRelations() + { + $origReadingMode = Versioned::get_reading_mode(); + + // Stage record - 2 children + Versioned::set_stage(Versioned::DRAFT); + $draftPage = $this->objFromFixture(VersionedTest\TestObject::class, 'page2'); + $draftPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); + $this->assertEquals(2, $draftPage->Children()->Count()); + + // Live record - no children + Versioned::set_stage(Versioned::LIVE); + $livePage = $this->objFromFixture(VersionedTest\TestObject::class, 'page2'); + $this->assertEquals(0, $livePage->Children()->Count()); + + // Validate that draft page still queries draft children even though global stage is live + $this->assertEquals(2, $draftPage->Children()->Count()); + + // Validate that live page still queries live children even though global stage is live + Versioned::set_stage(Versioned::DRAFT); + $this->assertEquals(0, $livePage->Children()->Count()); + + Versioned::set_reading_mode($origReadingMode); + } + /** * Tests that multi-table dataobjects are correctly versioned */