mirror of
https://github.com/flarum/core.git
synced 2025-08-05 07:57:46 +02:00
Added post extender with type method, deprecated ConfigurePostTypes (#2101)
This commit is contained in:
committed by
GitHub
parent
5842dd1200
commit
cee87848fe
@@ -326,7 +326,7 @@ class ModelTest extends TestCase
|
||||
|
||||
$this->app();
|
||||
|
||||
$post = new CustomPost;
|
||||
$post = new ModelTestCustomPost;
|
||||
|
||||
$this->assertEquals(42, $post->answer);
|
||||
|
||||
@@ -416,7 +416,7 @@ class ModelTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
class CustomPost extends AbstractEventPost
|
||||
class ModelTestCustomPost extends AbstractEventPost
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
58
tests/integration/extenders/PostTest.php
Normal file
58
tests/integration/extenders/PostTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Post\AbstractEventPost;
|
||||
use Flarum\Post\MergeableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
|
||||
class PostTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_post_type_doesnt_exist_by_default()
|
||||
{
|
||||
$this->assertArrayNotHasKey('customPost', Post::getModels());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_post_type_exists_if_added()
|
||||
{
|
||||
$this->extend((new Extend\Post)->type(PostTestCustomPost::class));
|
||||
|
||||
// Needed for extenders to be booted
|
||||
$this->app();
|
||||
|
||||
$this->assertArrayHasKey('customPost', Post::getModels());
|
||||
}
|
||||
}
|
||||
|
||||
class PostTestCustomPost extends AbstractEventPost implements MergeableInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $type = 'customPost';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveAfter(Post $previous = null)
|
||||
{
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user