diff --git a/framework/core/tests/integration/extenders/ModelTest.php b/framework/core/tests/integration/extenders/ModelTest.php index 1884e1594..f06a0ad34 100644 --- a/framework/core/tests/integration/extenders/ModelTest.php +++ b/framework/core/tests/integration/extenders/ModelTest.php @@ -13,6 +13,7 @@ use Carbon\Carbon; use Flarum\Discussion\Discussion; use Flarum\Extend; use Flarum\Group\Group; +use Flarum\Post\CommentPost; use Flarum\Post\Post; use Flarum\Tests\integration\RetrievesAuthorizedUsers; use Flarum\Tests\integration\TestCase; @@ -141,6 +142,31 @@ class ModelTest extends TestCase $this->assertContains(json_encode(__CLASS__), json_encode($user->customRelation()->get())); } + /** + * @test + */ + public function custom_relationship_is_inherited_to_child_classes() + { + $this->extend( + (new Extend\Model(Post::class)) + ->belongsTo('ancestor', Discussion::class, 'discussion_id') + ); + + $this->prepareDatabase([ + 'discussions' => [ + ['id' => 1, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0], + ], + 'posts' => [ + ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

can i haz relationz?

'], + ], + ]); + + $post = CommentPost::find(1); + + $this->assertInstanceOf(Discussion::class, $post->ancestor); + $this->assertEquals(1, $post->ancestor->id); + } + /** * @test */ @@ -218,6 +244,23 @@ class ModelTest extends TestCase $this->assertEquals(2, $group2->counter); } + /** + * @test + */ + public function custom_default_attribute_is_inherited_to_child_classes() + { + $this->extend( + (new Extend\Model(Post::class)) + ->default('answer', 42) + ); + + $this->app(); + + $post = new CommentPost; + + $this->assertEquals(42, $post->answer); + } + /** * @test */ @@ -264,6 +307,23 @@ class ModelTest extends TestCase $this->assertContains('custom', $post->getDates()); } + /** + * @test + */ + public function custom_date_attribute_is_inherited_to_child_classes() + { + $this->extend( + (new Extend\Model(Post::class)) + ->dateAttribute('custom') + ); + + $this->app(); + + $post = new CommentPost; + + $this->assertContains('custom', $post->getDates()); + } + /** * @test */