99
1010class SlugBehaviorTest extends TestCase
1111{
12- public $ fixtures = [
12+ protected $ fixtures = [
1313 'plugin.Muffin/Slug.Tags ' ,
1414 'plugin.Muffin/Slug.Articles ' ,
1515 'plugin.Muffin/Slug.ArticlesTags ' ,
@@ -20,7 +20,7 @@ public function setUp(): void
2020 {
2121 parent ::setUp ();
2222
23- $ this ->Tags = TableRegistry:: get ('Muffin/Slug.Tags ' , ['table ' => 'slug_tags ' ]);
23+ $ this ->Tags = $ this -> getTableLocator ()-> get ('Muffin/Slug.Tags ' , ['table ' => 'slug_tags ' ]);
2424 $ this ->Tags ->setDisplayField ('name ' );
2525 $ this ->Tags ->addBehavior ('Muffin/Slug.Slug ' );
2626
@@ -30,7 +30,8 @@ public function setUp(): void
3030 public function tearDown (): void
3131 {
3232 parent ::tearDown ();
33- TableRegistry::clear ();
33+
34+ $ this ->getTableLocator ()->clear ();
3435 unset($ this ->Behavior , $ this ->Tags );
3536 }
3637
@@ -99,7 +100,7 @@ public function testBeforeSaveOnUpdate()
99100 $ expected = 'baz ' ;
100101 $ this ->assertEquals ($ expected , $ result );
101102
102- $ tag-> unsetProperty ( 'name ' );
103+ unset( $ tag[ 'name ' ] );
103104 $ tag ->namespace = 'foobar ' ;
104105 $ result = $ this ->Tags ->save ($ tag )->slug ;
105106 $ this ->assertEquals ($ expected , $ result );
@@ -147,6 +148,32 @@ public function testBeforeSaveDirtyField()
147148 $ this ->assertEquals ($ expected , $ result );
148149 }
149150
151+ /**
152+ * Test with onUpdate = true, onDirty = true and slug field is not dirty and
153+ * but unrelated field is dirty.
154+ *
155+ * @return void
156+ */
157+ public function testBeforeSaveOnUpdateTrueAndOnDirtyTrue ()
158+ {
159+ $ this ->Tags ->behaviors ()->Slug ->setConfig ([
160+ 'onUpdate ' => true ,
161+ 'onDirty ' => true ,
162+ ]);
163+
164+ $ data = ['name ' => 'foo ' , 'slug ' => 'bar ' , 'counter ' => 1 ];
165+ $ tag = $ this ->Tags ->newEntity ($ data );
166+
167+ $ tag = $ this ->Tags ->save ($ tag );
168+ $ this ->assertEquals ('bar ' , $ tag ->slug );
169+ $ this ->assertSame (1 , $ tag ->counter );
170+
171+ $ tag ->counter = 2 ;
172+ $ tag = $ this ->Tags ->save ($ tag );
173+ $ this ->assertEquals ('bar ' , $ tag ->slug );
174+ $ this ->assertSame (2 , $ tag ->counter );
175+ }
176+
150177 /**
151178 * Make sure no slug is generated when `displayField` is empty.
152179 */
0 commit comments