2020-11-03 23:43:49 +08:00
|
|
|
<?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;
|
2021-03-08 05:32:41 +08:00
|
|
|
use Flarum\Testing\integration\TestCase;
|
2020-11-03 23:43:49 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|