src/Codeception/Module/WPDb.php
public function havePostInDatabase(array $data = [])
    {
        $postTableName = $this->grabPostsTableName();
        $idColumn = 'ID';
        $id = $this->grabLatestEntryByFromDatabase($postTableName, $idColumn) + 1;
        $post = Post::makePost($id, $this->config['url'], $data);
        $hasMeta = !empty($data['meta']) || !empty($data['meta_input']);
        $hasTerms = !empty($data['terms']) || !empty($data['tax_input']);

        $meta = [];
        if ($hasMeta) {
            $meta = !empty($data['meta']) ? $data['meta'] : $data['meta_input'];
            unset($post['meta']);
            unset($post['meta_input']);
        }

        $terms = [];
        if ($hasTerms) {
            $terms = !empty($data['terms']) ? $data['terms'] : $data['tax_input'];
            unset($post['terms']);
            unset($post['tax_input']);
        }

        $postId = $this->haveInDatabase($postTableName, $post);

        if ($hasMeta) {
            foreach ($meta as $meta_key => $meta_value) {
                $this->havePostmetaInDatabase($postId, $meta_key, $meta_value);
            }
        }

        if ($hasTerms) {
            foreach ($terms as $taxonomy => $termNames) {
                foreach ($termNames as $termName) {
                    $termId = $this->grabTermIdFromDatabase(['name' => $termName]);

                    if (empty($termId)) {
                        $termId = $this->grabTermIdFromDatabase(['slug' => $termName]);
                    }

                    if (empty($termId)) {
                        $termIds = $this->haveTermInDatabase($termName, $taxonomy);
                        $termId = reset($termIds);
                    }

                    $termTaxonomyId = $this->grabTermTaxonomyIdFromDatabase([
                        'term_id' => $termId,
                        'taxonomy' => $taxonomy,
                    ]);

                    $this->haveTermRelationshipInDatabase($postId, $termTaxonomyId);
                    $this->increaseTermCountBy($termTaxonomyId, 1);
                }
            }
        }

        return $postId;
    }
public function havePostInDatabase(array $data = [])
    {
        $postTableName = $this->grabPostsTableName();
        $idColumn = 'ID';
        $id = $this->grabLatestEntryByFromDatabase($postTableName, $idColumn) + 1;
        $post = Post::makePost($id, $this->config['url'], $data);
        $hasMeta = !empty($data['meta']) || !empty($data['meta_input']);
        $hasTerms = !empty($data['terms']) || !empty($data['tax_input']);

        $meta = [];
        if ($hasMeta) {
            $meta = !empty($data['meta']) ? $data['meta'] : $data['meta_input'];
            unset($post['meta']);
            unset($post['meta_input']);
        }

        $terms = [];
        if ($hasTerms) {
            $terms = !empty($data['terms']) ? $data['terms'] : $data['tax_input'];
            unset($post['terms']);
            unset($post['tax_input']);
        }

        $postId = $this->haveInDatabase($postTableName, $post);

        if ($hasMeta) {
            foreach ($meta as $meta_key => $meta_value) {
                $this->havePostmetaInDatabase($postId, $meta_key, $meta_value);
            }
        }

        if ($hasTerms) {
            foreach ($terms as $taxonomy => $termNames) {
                foreach ($termNames as $termName) {
                    $termId = $this->grabTermIdFromDatabase(['name' => $termName]);

                    if (empty($termId)) {
                        $termId = $this->grabTermIdFromDatabase(['slug' => $termName]);
                    }

                    if (empty($termId)) {
                        $termIds = $this->haveTermInDatabase($termName, $taxonomy);
                        $termId = reset($termIds);
                    }

                    $termTaxonomyId = $this->grabTermTaxonomyIdFromDatabase([
                        'term_id' => $termId,
                        'taxonomy' => $taxonomy,
                    ]);

                    $this->haveTermRelationshipInDatabase($postId, $termTaxonomyId);
                    $this->increaseTermCountBy($termTaxonomyId, 1);
                }
            }
        }

        return $postId;
    }
public function havePostInDatabase ( array $ data = [ ] ) { $ postTableName = $ this -> grabPostsTableName ( ) ; $ idColumn = 'ID' ; $ id = $ this -> grabLatestEntryByFromDatabase ( $ postTableName , $ idColumn ) + 1 ; $ post = Post :: makePost ( $ id , $ this -> config [ 'url' ] , $ data ) ; $ hasMeta = ! empty ( $ data [ 'meta' ] ) || ! empty ( $ data [ 'meta_input' ] ) ; $ hasTerms = ! empty ( $ data [ 'terms' ] ) || ! empty ( $ data [ 'tax_input' ] ) ; $ meta = [ ] ; if ( $ hasMeta ) { $ meta = ! empty ( $ data [ 'meta' ] ) ? $ data [ 'meta' ] : $ data [ 'meta_input' ] ; unset ( $ post [ 'meta' ] ) ; unset ( $ post [ 'meta_input' ] ) ; } $ terms = [ ] ; if ( $ hasTerms ) { $ terms = ! empty ( $ data [ 'terms' ] ) ? $ data [ 'terms' ] : $ data [ 'tax_input' ] ; unset ( $ post [ 'terms' ] ) ; unset ( $ post [ 'tax_input' ] ) ; } $ postId = $ this -> haveInDatabase ( $ postTableName , $ post ) ; if ( $ hasMeta ) { foreach ( $ meta as $ meta_key => $ meta_value ) { $ this -> havePostmetaInDatabase ( $ postId , $ meta_key , $ meta_value ) ; } } if ( $ hasTerms ) { foreach ( $ terms as $ taxonomy => $ termNames ) { foreach ( $ termNames as $ termName ) { $ termId = $ this -> grabTermIdFromDatabase ( [ 'name' => $ termName ] ) ; if ( empty ( $ termId ) ) { $ termId = $ this -> grabTermIdFromDatabase ( [ 'slug' => $ termName ] ) ; } if ( empty ( $ termId ) ) { $ termIds = $ this -> haveTermInDatabase ( $ termName , $ taxonomy ) ; $ termId = reset ( $ termIds ) ; } $ termTaxonomyId = $ this -> grabTermTaxonomyIdFromDatabase ( [ 'term_id' => $ termId , 'taxonomy' => $ taxonomy , ] ) ; $ this -> haveTermRelationshipInDatabase ( $ postId , $ termTaxonomyId ) ; $ this -> increaseTermCountBy ( $ termTaxonomyId , 1 ) ; } } } return $ postId ; }
Inserts a post in the database.

@example
```php
// Insert a post with random values in the database.
$randomPostId = $I->havePostInDatabase();
// Insert a post with specific values in the database.
$I->dontSeeOptionInDatabase([
'post_type' => 'book',
'post_title' => 'Alice in Wonderland',
'meta_input' => [
'readers_count' => 23
],
'tax_input' => [
'genre' => 'fiction'
]
]);
```

@param  array $data An associative array of post data to override default and random generated values.

@return int post_id The inserted post ID.
Inserts a post in the database .