src/Codeception/Module/WPDb.php
public function haveCommentInDatabase($comment_post_ID, array $data = [])
    {
        if (!is_int($comment_post_ID)) {
            throw new \BadMethodCallException('Comment post ID must be int');
        }

        $has_meta = !empty($data['meta']);
        $meta = [];
        if ($has_meta) {
            $meta = $data['meta'];
            unset($data['meta']);
        }

        $comment = Comment::makeComment($comment_post_ID, $data);

        $commentsTableName = $this->grabPrefixedTableNameFor('comments');
        $commentId = $this->haveInDatabase($commentsTableName, $comment);

        if ($has_meta) {
            foreach ($meta as $key => $value) {
                $this->haveCommentMetaInDatabase($commentId, $key, $value);
            }
        }

        if ($comment['comment_approved']) {
            $commentCount = $this->countInDatabase(
                $commentsTableName,
                [
                    'comment_approved' => '1',
                    'comment_post_ID' => $comment_post_ID,
                ]
            );

            $postsTableName = $this->grabPostsTableName();
            $this->updateInDatabase(
                $postsTableName,
                ['comment_count' => $commentCount],
                ['ID' => $comment_post_ID]
            );
        }

        return $commentId;
    }
public function haveCommentInDatabase($comment_post_ID, array $data = [])
    {
        if (!is_int($comment_post_ID)) {
            throw new \BadMethodCallException('Comment post ID must be int');
        }

        $has_meta = !empty($data['meta']);
        $meta = [];
        if ($has_meta) {
            $meta = $data['meta'];
            unset($data['meta']);
        }

        $comment = Comment::makeComment($comment_post_ID, $data);

        $commentsTableName = $this->grabPrefixedTableNameFor('comments');
        $commentId = $this->haveInDatabase($commentsTableName, $comment);

        if ($has_meta) {
            foreach ($meta as $key => $value) {
                $this->haveCommentMetaInDatabase($commentId, $key, $value);
            }
        }

        if ($comment['comment_approved']) {
            $commentCount = $this->countInDatabase(
                $commentsTableName,
                [
                    'comment_approved' => '1',
                    'comment_post_ID' => $comment_post_ID,
                ]
            );

            $postsTableName = $this->grabPostsTableName();
            $this->updateInDatabase(
                $postsTableName,
                ['comment_count' => $commentCount],
                ['ID' => $comment_post_ID]
            );
        }

        return $commentId;
    }
public function haveCommentInDatabase ( $ comment_post_ID , array $ data = [ ] ) { if ( ! is_int ( $ comment_post_ID ) ) { throw new \ BadMethodCallException ( 'Comment post ID must be int' ) ; } $ has_meta = ! empty ( $ data [ 'meta' ] ) ; $ meta = [ ] ; if ( $ has_meta ) { $ meta = $ data [ 'meta' ] ; unset ( $ data [ 'meta' ] ) ; } $ comment = Comment :: makeComment ( $ comment_post_ID , $ data ) ; $ commentsTableName = $ this -> grabPrefixedTableNameFor ( 'comments' ) ; $ commentId = $ this -> haveInDatabase ( $ commentsTableName , $ comment ) ; if ( $ has_meta ) { foreach ( $ meta as $ key => $ value ) { $ this -> haveCommentMetaInDatabase ( $ commentId , $ key , $ value ) ; } } if ( $ comment [ 'comment_approved' ] ) { $ commentCount = $ this -> countInDatabase ( $ commentsTableName , [ 'comment_approved' => '1' , 'comment_post_ID' => $ comment_post_ID , ] ) ; $ postsTableName = $ this -> grabPostsTableName ( ) ; $ this -> updateInDatabase ( $ postsTableName , [ 'comment_count' => $ commentCount ] , [ 'ID' => $ comment_post_ID ] ) ; } return $ commentId ; }
Inserts a comment in the database.

@example
```php
$I->haveCommentInDatabase($postId, ['comment_content' => 'Test Comment', 'comment_karma' => 23]);
```

@param  int   $comment_post_ID The id of the post the comment refers to.
@param  array $data            The comment data overriding default and random generated values.

@return int The inserted comment `comment_id`.
Inserts a comment in the database .