src/Codeception/Module/WPDb.php
public function haveTermInDatabase($name, $taxonomy, array $overrides = [])
    {
        $termDefaults = ['slug' => (new Slugifier())->slugify($name), 'term_group' => 0];

        $hasMeta = !empty($overrides['meta']);
        $meta = [];
        if ($hasMeta) {
            $meta = $overrides['meta'];
            unset($overrides['meta']);
        }

        $termData = array_merge($termDefaults, array_intersect_key($overrides, $termDefaults));
        $termData['name'] = $name;
        $term_id = $this->haveInDatabase($this->grabTermsTableName(), $termData);

        $termTaxonomyDefaults = ['description' => '', 'parent' => 0, 'count' => 0];
        $termTaxonomyData = array_merge($termTaxonomyDefaults, array_intersect_key($overrides, $termTaxonomyDefaults));
        $termTaxonomyData['taxonomy'] = $taxonomy;
        $termTaxonomyData['term_id'] = $term_id;
        $term_taxonomy_id = $this->haveInDatabase($this->grabTermTaxonomyTableName(), $termTaxonomyData);

        if ($hasMeta) {
            foreach ($meta as $key => $value) {
                $this->haveTermMetaInDatabase($term_id, $key, $value);
            }
        }

        return [$term_id, $term_taxonomy_id];
    }
public function haveTermInDatabase($name, $taxonomy, array $overrides = [])
    {
        $termDefaults = ['slug' => (new Slugifier())->slugify($name), 'term_group' => 0];

        $hasMeta = !empty($overrides['meta']);
        $meta = [];
        if ($hasMeta) {
            $meta = $overrides['meta'];
            unset($overrides['meta']);
        }

        $termData = array_merge($termDefaults, array_intersect_key($overrides, $termDefaults));
        $termData['name'] = $name;
        $term_id = $this->haveInDatabase($this->grabTermsTableName(), $termData);

        $termTaxonomyDefaults = ['description' => '', 'parent' => 0, 'count' => 0];
        $termTaxonomyData = array_merge($termTaxonomyDefaults, array_intersect_key($overrides, $termTaxonomyDefaults));
        $termTaxonomyData['taxonomy'] = $taxonomy;
        $termTaxonomyData['term_id'] = $term_id;
        $term_taxonomy_id = $this->haveInDatabase($this->grabTermTaxonomyTableName(), $termTaxonomyData);

        if ($hasMeta) {
            foreach ($meta as $key => $value) {
                $this->haveTermMetaInDatabase($term_id, $key, $value);
            }
        }

        return [$term_id, $term_taxonomy_id];
    }
public function haveTermInDatabase ( $ name , $ taxonomy , array $ overrides = [ ] ) { $ termDefaults = [ 'slug' => ( new Slugifier ( ) ) -> slugify ( $ name ) , 'term_group' => 0 ] ; $ hasMeta = ! empty ( $ overrides [ 'meta' ] ) ; $ meta = [ ] ; if ( $ hasMeta ) { $ meta = $ overrides [ 'meta' ] ; unset ( $ overrides [ 'meta' ] ) ; } $ termData = array_merge ( $ termDefaults , array_intersect_key ( $ overrides , $ termDefaults ) ) ; $ termData [ 'name' ] = $ name ; $ term_id = $ this -> haveInDatabase ( $ this -> grabTermsTableName ( ) , $ termData ) ; $ termTaxonomyDefaults = [ 'description' => '' , 'parent' => 0 , 'count' => 0 ] ; $ termTaxonomyData = array_merge ( $ termTaxonomyDefaults , array_intersect_key ( $ overrides , $ termTaxonomyDefaults ) ) ; $ termTaxonomyData [ 'taxonomy' ] = $ taxonomy ; $ termTaxonomyData [ 'term_id' ] = $ term_id ; $ term_taxonomy_id = $ this -> haveInDatabase ( $ this -> grabTermTaxonomyTableName ( ) , $ termTaxonomyData ) ; if ( $ hasMeta ) { foreach ( $ meta as $ key => $ value ) { $ this -> haveTermMetaInDatabase ( $ term_id , $ key , $ value ) ; } } return [ $ term_id , $ term_taxonomy_id ] ; }
Inserts a term in the database.

@example
```php
// Insert a random 'genre' term in the database.
$I->haveTermInDatabase('non-fiction', 'genre');
// Insert a term in the database with term meta.
$I->haveTermInDatabase('fiction', 'genre', [
'slug' => 'genre--fiction',
'meta' => [
'readers_count' => 23
]
]);
```

@param  string $name      The term name, e.g. "Fuzzy".
@param string  $taxonomy  The term taxonomy
@param array   $overrides An array of values to override the default ones.

@return array An array containing `term_id` and `term_taxonomy_id` of the inserted term.
Inserts a term in the database .