1010use Terraformers \KeysForCache \Tests \Mocks \Models \CaredHasMany ;
1111use Terraformers \KeysForCache \Tests \Mocks \Models \CaredHasOne ;
1212use Terraformers \KeysForCache \Tests \Mocks \Models \CaredHasOneNonVersioned ;
13+ use Terraformers \KeysForCache \Tests \Mocks \Models \CaredHasOneVersionedNonStaged ;
1314use Terraformers \KeysForCache \Tests \Mocks \Models \CaredManyMany ;
1415use Terraformers \KeysForCache \Tests \Mocks \Models \PolymorphicCaredHasMany ;
1516use Terraformers \KeysForCache \Tests \Mocks \Models \PolymorphicCaredHasOne ;
@@ -32,6 +33,7 @@ class CaresTest extends SapphireTest
3233 CaredHasMany::class,
3334 CaredHasOne::class,
3435 CaredHasOneNonVersioned::class,
36+ CaredHasOneVersionedNonStaged::class,
3537 CaredManyMany::class,
3638 CaredThrough::class,
3739 PolymorphicCaredHasOne::class,
@@ -150,6 +152,34 @@ public function testCaresHasOneNonVersioned(): void
150152 $ this ->assertNotEquals ($ originalKey , $ newKey );
151153 }
152154
155+ public function testCaresHasOneVersionedNonStaged (): void
156+ {
157+ // Updates are processed as part of scaffold, so we need to flush before we kick off
158+ ProcessedUpdatesService::singleton ()->flush ();
159+
160+ $ page = $ this ->objFromFixture (CaresPage::class, 'page1 ' );
161+ $ model = $ this ->objFromFixture (CaredHasOneVersionedNonStaged::class, 'model1 ' );
162+
163+ // Check that we're set up correctly
164+ $ this ->assertEquals (CaredHasOneVersionedNonStaged::class, $ model ->ClassName );
165+ $ this ->assertEquals ($ page ->CaredHasOneVersionedNonStagedID , $ model ->ID );
166+
167+ $ originalKey = $ page ->getCacheKey ();
168+
169+ $ this ->assertNotNull ($ originalKey );
170+ $ this ->assertNotEmpty ($ originalKey );
171+
172+ // Begin changes
173+ $ model ->forceChange ();
174+ $ model ->write ();
175+
176+ $ newKey = $ page ->getCacheKey ();
177+
178+ $ this ->assertNotNull ($ newKey );
179+ $ this ->assertNotEmpty ($ newKey );
180+ $ this ->assertNotEquals ($ originalKey , $ newKey );
181+ }
182+
153183 public function testPolymorphicCaresHasOne (): void
154184 {
155185 // Updates are processed as part of scaffold, so we need to flush before we kick off
0 commit comments