20
20
use TractorCow \Fluent \Tests \Extension \FluentExtensionTest \UnlocalisedChild ;
21
21
use TractorCow \Fluent \Tests \Extension \Stub \FluentStubObject ;
22
22
use PHPUnit \Framework \Attributes \DataProvider ;
23
+ use TractorCow \Fluent \Tests \Extension \FluentExtensionTest \TestGeneratedColumns ;
23
24
24
25
class FluentExtensionTest extends SapphireTest
25
26
{
@@ -33,6 +34,7 @@ class FluentExtensionTest extends SapphireTest
33
34
UnlocalisedChild::class,
34
35
TestRelationPage::class,
35
36
TestModel::class,
37
+ TestGeneratedColumns::class,
36
38
];
37
39
38
40
protected static $ required_extensions = [
@@ -510,6 +512,45 @@ public static function sortRecordProvider()
510
512
];
511
513
}
512
514
515
+ public function testLocalisedGeneratedColumns (): void
516
+ {
517
+ // Setup first localisation
518
+ $ recordID = FluentState::singleton ()->withState (function (FluentState $ state ): int {
519
+ $ state ->setLocale ('en_US ' );
520
+
521
+ $ record = new TestGeneratedColumns ();
522
+ $ record ->BaseField = 'EN copy test ' ;
523
+ return $ record ->write ();
524
+ });
525
+
526
+ // Setup second localisation and make sure we have two localisations to work with
527
+ FluentState::singleton ()->withState (function (FluentState $ state ) use ($ recordID ): void {
528
+ $ state ->setLocale ('de_DE ' );
529
+
530
+ $ record = TestGeneratedColumns::get ()->byID ($ recordID );
531
+ $ record ->BaseField = 'DE copy test ' ;
532
+ $ record ->write ();
533
+ });
534
+
535
+ // Check the values of the generated columns in en_US
536
+ FluentState::singleton ()->withState (function (FluentState $ state ) use ($ recordID ): void {
537
+ $ state ->setLocale ('en_US ' );
538
+
539
+ $ record = TestGeneratedColumns::get ()->byID ($ recordID );
540
+ $ this ->assertSame ('EN copy test_virtual ' , $ record ->GeneratedField1 );
541
+ $ this ->assertSame ('EN copy test_stored ' , $ record ->GeneratedField2 );
542
+ });
543
+
544
+ // Check the values of the generated columns in de_DE
545
+ FluentState::singleton ()->withState (function (FluentState $ state ) use ($ recordID ): void {
546
+ $ state ->setLocale ('de_DE ' );
547
+
548
+ $ record = TestGeneratedColumns::get ()->byID ($ recordID );
549
+ $ this ->assertSame ('DE copy test_virtual ' , $ record ->GeneratedField1 );
550
+ $ this ->assertSame ('DE copy test_stored ' , $ record ->GeneratedField2 );
551
+ });
552
+ }
553
+
513
554
/**
514
555
* Get a Locale field value directly from a record's localised database table, skipping the ORM
515
556
*
0 commit comments