<commit_before><?php

namespace Backend\Modules\Blog\Tests\Engine;

use Backend\Modules\Blog\Engine\Model;
use Common\Doctrine\Entity\Meta;
use Common\WebTestCase;

class ModelTest extends WebTestCase
{
    public function setUp()
    {
        parent::setUp();

        if (!defined('APPLICATION')) {
            define('APPLICATION', 'Backend');
        }
    }

    public function testInsertingComment(): void
    {
        $client = self::createClient();
        $this->loadFixtures($client);
        $this->insertBlogpost();

        $commentData = $this->getCommentData();

        Model::insertComment($commentData);

        $addedComment = Model::getComment(1);

        self::assertEquals(1, $addedComment['id']);
        self::assertEquals($commentData['post_id'], $addedComment['post_id']);
        self::assertEquals($commentData['language'], $addedComment['language']);
        self::assertEquals($commentData['author'], $addedComment['author']);
        self::assertEquals($commentData['email'], $addedComment['email']);
        self::assertEquals($commentData['website'], $addedComment['website']);
        self::assertEquals($commentData['text'], $addedComment['text']);
        self::assertEquals($commentData['type'], $addedComment['type']);
        self::assertEquals($commentData['status'], $addedComment['status']);
        self::assertEquals($commentData['data'], $addedComment['data']);
        self::assertEquals(
            $this->getBlogpostData()['title'],
            $addedComment['post_title']
        );
    }

    public function testCommentExists(): void
    {
        self::assertEquals(true, Model::existsComment(1));
        self::assertEquals(false, Model::existsComment(2));
    }

    public function testEditingComment(): void
    {
        $commentData = $this->getUpdatedCommentData();

        Model::updateComment($commentData);

        $editedComment = Model::getComment(1);

        self::assertEquals(1, $editedComment['id']);
        self::assertEquals($commentData['post_id'], $editedComment['post_id']);
        self::assertEquals(
            $commentData['language'],
            $editedComment['language']
        );
        self::assertEquals($commentData['author'], $editedComment['author']);
        self::assertEquals($commentData['email'], $editedComment['email']);
        self::assertEquals($commentData['website'], $editedComment['website']);
        self::assertEquals($commentData['text'], $editedComment['text']);
        self::assertEquals($commentData['type'], $editedComment['type']);
        self::assertEquals($commentData['status'], $editedComment['status']);
        self::assertEquals($commentData['data'], $editedComment['data']);
        self::assertEquals(
            $this->getBlogpostData()['title'],
            $editedComment['post_title']
        );
    }

    public function testDeletingComment(): void
    {
        self::assertTrue(Model::existsComment(1));
        Model::deleteComments([1]);
        self::assertFalse(Model::existsComment(1));
    }

    private function getCommentData(): array
    {
        return [
            'post_id' => $this->getBlogpostData()['id'],
            'language' => 'en',
            'created_on' => '2017-01-01 13:37:00',
            'author' => '<NAME>',
            'email' => '<EMAIL>',
            'website' => 'http://example.org',
            'text' => 'Lorem Ipsum',
            'type' => 'comment',
            'status' => 'published',
            'data' => serialize(['server' => ['foo' => 'bar']]),<commit_msg>Use the non static variants<commit_after><?php

namespace Backend\Modules\Blog\Tests\Engine;

use Backend\Modules\Blog\Engine\Model;
use Common\Doctrine\Entity\Meta;
use Common\WebTestCase;

class ModelTest extends WebTestCase
{
    public function setUp()
    {
        parent::setUp();

        if (!defined('APPLICATION')) {
            define('APPLICATION', 'Backend');
        }
    }

    // comments
    public function testCreateComment(): void
    {
        $client = self::createClient();
        $this->loadFixtures($client);
        $this->insertBlogpost();

        $commentData = $this->getCommentData();

        Model::insertComment($commentData);

        $addedComment = Model::getComment(1);

        $this->assertEquals(1, $addedComment['id']);
        $this->assertEquals($commentData['post_id'], $addedComment['post_id']);
        $this->assertEquals(
            $commentData['language'],
            $addedComment['language']
        );
        $this->assertEquals($commentData['author'], $addedComment['author']);
        $this->assertEquals($commentData['email'], $addedComment['email']);
        $this->assertEquals($commentData['website'], $addedComment['website']);
        $this->assertEquals($commentData['text'], $addedComment['text']);
        $this->assertEquals($commentData['type'], $addedComment['type']);
        $this->assertEquals($commentData['status'], $addedComment['status']);
        $this->assertEquals($commentData['data'], $addedComment['data']);
        $this->assertEquals(
            $this->getBlogpostData()['title'],
            $addedComment['post_title']
        );
    }

    public function testIfCommentExists(): void
    {
        $this->assertTrue(Model::existsComment(1));
        $this->assertFalse(Model::existsComment(2));
    }

    public function testUpdateComment(): void
    {
        $commentData = $this->getUpdatedCommentData();

        Model::updateComment($commentData);

        $editedComment = Model::getComment(1);

        $this->assertEquals(1, $editedComment['id']);
        $this->assertEquals($commentData['post_id'], $editedComment['post_id']);
        $this->assertEquals(
            $commentData['language'],
            $editedComment['language']
        );
        $this->assertEquals($commentData['author'], $editedComment['author']);
        $this->assertEquals($commentData['email'], $editedComment['email']);
        $this->assertEquals($commentData['website'], $editedComment['website']);
        $this->assertEquals($commentData['text'], $editedComment['text']);
        $this->assertEquals($commentData['type'], $editedComment['type']);
        $this->assertEquals($commentData['status'], $editedComment['status']);
        $this->assertEquals($commentData['data'], $editedComment['data']);
        $this->assertEquals(
            $this->getBlogpostData()['title'],
            $editedComment['post_title']
        );
    }

    public function testDeleteComment(): void
    {
        $this->assertTrue(Model::existsComment(1));
        Model::deleteComments([1]);
        $this->assertFalse(Model::existsComment(1));
    }

    private function getCommentData(): array
    {
        return [
            'post_id' => $this->getBlogpostData()['id'],
            'language' => 'en',
            'created_on' => '2017-01-01 13:37:00',
            'author' => '<NAME>',
            'email' => '<EMAIL>',
            'website' => 'http://example.org',
            'text' => 'Lorem Ipsum',
            'type' => 'comment',
            'status' => 'published',
            'data' => serialize(['server' => ['foo' => 'bar']]),
{'fraction_non_alphanumeric': 0.18029584147362546, 'fraction_numerical': 0.006419201786212671, 'mean_word_length': 3.169284467713787, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6015472', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1857, 'n_words': 271}