mirror of
https://github.com/flarum/framework.git
synced 2024-11-30 05:13:37 +08:00
Model extender: Add failing test
We determined that child classes are not properly affected when extending the parent classes. Refs #2100.
This commit is contained in:
parent
4ac4af54e6
commit
74027a8421
|
@ -13,6 +13,7 @@ use Carbon\Carbon;
|
||||||
use Flarum\Discussion\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Extend;
|
use Flarum\Extend;
|
||||||
use Flarum\Group\Group;
|
use Flarum\Group\Group;
|
||||||
|
use Flarum\Post\CommentPost;
|
||||||
use Flarum\Post\Post;
|
use Flarum\Post\Post;
|
||||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||||
use Flarum\Tests\integration\TestCase;
|
use Flarum\Tests\integration\TestCase;
|
||||||
|
@ -141,6 +142,31 @@ class ModelTest extends TestCase
|
||||||
$this->assertContains(json_encode(__CLASS__), json_encode($user->customRelation()->get()));
|
$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' => '<t><p>can i haz relationz?</p></t>'],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$post = CommentPost::find(1);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Discussion::class, $post->ancestor);
|
||||||
|
$this->assertEquals(1, $post->ancestor->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
@ -218,6 +244,23 @@ class ModelTest extends TestCase
|
||||||
$this->assertEquals(2, $group2->counter);
|
$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
|
* @test
|
||||||
*/
|
*/
|
||||||
|
@ -264,6 +307,23 @@ class ModelTest extends TestCase
|
||||||
$this->assertContains('custom', $post->getDates());
|
$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
|
* @test
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user