ForumPostTest.php 2.33 KB
<?php

namespace FootyRoom\Tests\Unit\ForumPost;

use FootyRoom\Tests\TestCase;
use FootyRoom\Core\ForumPost\ForumPost;

class ForumPostTest extends TestCase
{
    /**
     * @expectedException        \FootyRoom\Core\CoreException
     */
    public function testTitleCanNotBeEmpty()
    {
        $post = new ForumPost(
            '',
            61,
            41301
        );
    }

    public function testConstructor()
    {
        $title = 'title';
        $categoryId = 61;
        $userId = 41301;

        $post = new ForumPost(
            $title,
            $categoryId,
            $userId
        );

        $this->assertEquals($title, $post->getTitle());
        $this->assertEquals($categoryId, $post->getCategoryId());
        $this->assertEquals($userId, $post->getUserId());
        $this->assertTrue($post->isPublished());
        $this->assertTrue($post->isDiscussionOpen());

        return $post;
    }

    /**
     * @depends testConstructor
     */
    public function testPublish($post)
    {
        $post->publish();
        $this->assertTrue($post->isPublished());
    }

    /**
     * @depends testConstructor
     */
    public function testUnpublish($post)
    {
        $post->unpublish();
        $this->assertFalse($post->isPublished());
    }

    /**
     * @depends testConstructor
     */
    public function testOpenDiscussion($post)
    {
        $post->openDiscussion();
        $this->assertTrue($post->isDiscussionOpen());
    }

    /**
     * @depends testConstructor
     */
    public function testCloseDiscussion($post)
    {
        $post->closeDiscussion();
        $this->assertFalse($post->isDiscussionOpen());
    }

    /**
     * @depends testConstructor
     */
    public function testChangeAuthor($post)
    {
        $userId = 5555;

        $post->changeAuthor($userId);
        $this->assertEquals($userId, $post->getUserId());
    }

    /**
     * @depends testConstructor
     */
    public function testEditTitle($post)
    {
        $newTitle = 'Who is the best?';

        $post->editTitle($newTitle);
        $this->assertEquals($newTitle, $post->getTitle());
    }

    /**
     * @depends testConstructor
     */
    public function testSlug($post)
    {
        $newTitle = 'Who is the best?';

        $post->editTitle($newTitle);
        $this->assertEquals('who-is-the-best', $post->getSlug());
    }
}