@@ -11,6 +11,16 @@ public function test_it_saves_slug_on_model_save()
11
11
$ this ->assertSame ('my-test-title ' , $ model ->slug );
12
12
}
13
13
14
+ public function test_it_does_not_overwrite_existing_slug ()
15
+ {
16
+ $ model = TestModel::create ([
17
+ 'title ' => 'My test title ' ,
18
+ 'slug ' => 'custom-slug '
19
+ ]);
20
+
21
+ $ this ->assertSame ('custom-slug ' , $ model ->slug );
22
+ }
23
+
14
24
public function test_it_saves_translated_slugs ()
15
25
{
16
26
$ model = TestModelTranslated::create ([
@@ -25,6 +35,24 @@ public function test_it_saves_translated_slugs()
25
35
$ this ->assertSame ('mon-titre-test ' , $ model ->translate ('slug ' , 'fr ' ));
26
36
}
27
37
38
+ public function test_it_only_generates_missing_translated_slugs ()
39
+ {
40
+ $ model = TestModelTranslated::create ([
41
+ 'title ' => [
42
+ 'en ' => 'My test title ' ,
43
+ 'fr ' => 'Mon titre test '
44
+ ],
45
+ 'slug ' => [
46
+ 'en ' => null ,
47
+ 'fr ' => 'custom-french-slug '
48
+ ]
49
+ ]);
50
+
51
+ $ this ->assertSame ('{"en":"my-test-title","fr":"custom-french-slug"} ' , $ model ->getAttributes ()['slug ' ]);
52
+ $ this ->assertSame ('my-test-title ' , $ model ->slug );
53
+ $ this ->assertSame ('custom-french-slug ' , $ model ->translate ('slug ' , 'fr ' ));
54
+ }
55
+
28
56
public function test_can_override_sluggable_attribute ()
29
57
{
30
58
$ model = TestModelCustomAttribute::create (['title ' => 'My test title ' ]);
0 commit comments