File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ public function registerPostModel(array $postModels): void {
5151 self ::$ postTypeModelClasses = $ postModels ;
5252 }
5353
54+ public function addPostModel (array $ postModels ): void {
55+ self ::$ postTypeModelClasses = array_merge (self ::$ postTypeModelClasses , $ postModels );
56+ }
57+
5458 /**
5559 * Use in Simply Plugin to register your term type models
5660 *
@@ -60,6 +64,10 @@ public function registerTermModel(array $termModels): void {
6064 self ::$ termTypeModelClasses = $ termModels ;
6165 }
6266
67+ public function addTermModel (array $ termModels ): void {
68+ self ::$ termTypeModelClasses = array_merge (self ::$ termTypeModelClasses , $ termModels );
69+ }
70+
6371 /**
6472 * Set key to have a clean mapping
6573 *
Original file line number Diff line number Diff line change @@ -78,4 +78,18 @@ public function testRegisterModels() {
7878 $ this ->assertSame ($ expected , $ factoryReflection ->getStaticPropertyValue ('postTypeModelClasses ' ));
7979 $ this ->assertSame ($ expected , $ factoryReflection ->getStaticPropertyValue ('termTypeModelClasses ' ));
8080 }
81+
82+ public function testRegisterMultipleModelsWithMultipleCall () {
83+ $ factory = new ModelFactory ();
84+ $ classA = 'ClassA ' ;
85+ $ classB = 'ClassB ' ;
86+ $ expected = array ($ classA , $ classB );
87+ $ factory ->registerPostModel (array ($ classA ));
88+ $ factory ->registerTermModel (array ($ classA ));
89+ $ factory ->addPostModel (array ($ classB ));
90+ $ factory ->addTermModel (array ($ classB ));
91+ $ factoryReflection = new \ReflectionClass ($ factory );
92+ $ this ->assertSame ($ expected , $ factoryReflection ->getStaticPropertyValue ('postTypeModelClasses ' ));
93+ $ this ->assertSame ($ expected , $ factoryReflection ->getStaticPropertyValue ('termTypeModelClasses ' ));
94+ }
8195}
You can’t perform that action at this time.
0 commit comments