WPDb term methods refresh

Terms related methods got a facelift.

Terms and term tables

While some term related methods were available in previous versions of the WPDb module part of the wp-browser library those were not nearly as flexible and comfortable to use as I would have liked.
I’ve just pushed version 1.8.2 of wp-browser to GitHub addressing just those missing features.
I’ve added/reworked some new term related methods to the WPDb module:

  • dontHaveTermInDatabase
  • dontHaveTermRelationshipInDatabase
  • dontHaveTermTaxonomyInDatabase
  • dontSeeTermInDatabase
  • grabTermIdFromDatabase

  • grabTermRelationshipsTableName
  • grabTermsTableName
  • grabTermTaxonomyIdFromDatabase
  • grabTermTaxonomyTableName

  • haveTermInDatabase

  • haveTermRelationshipInDatabase

  • seeTermInDatabase

Have a flexible post

Together with the above methods I’ve extended the functions of the havePostInDatabase and haveManyPostsInDatabase methods.
In a functional or acceptance test this code can now be written to insert a couple of terms in the database and have them assigned to the post

$I->haveTermInDatabase('term_one', 'my_taxonomy');
$I->haveTermInDatabase('term_two', 'my_taxonomy');

$I->havePostInDatabase([
    'post_type' => 'post_type_one',
    'terms' => [
        'my_taxonomy' => ['term_one', 'term_two']
    ]
]);

If the terms that I’m trying to assign to the post are not defined yet then those will be inserted for me, the code above can be rewritten omitting the first two lines

$I->havePostInDatabase([
    'post_type' => 'post_type_one',
    'terms' => [
        'my_taxonomy' => ['term_one', 'term_two']
    ]
]);

The same applies to the insertion of many posts

$I->haveManyPostsInDatabase(5, [
    'post_type' => 'post_type_one',
    'terms' => [
        'my_taxonomy' => ['term_one', 'term_two']
    ]
]);

each inserted post will be assigned the same terms.
Finally, when inserting many posts, the {{n}} placeholder can be used to define the term taxonomies or terms.
Say I want to insert 5 posts and assign each a tag called tag_n I’m now able to write this

$I->haveManyPostsInDatabase(5, [
    'post_type' => 'post_type_one',
    'post_title' => 'Title {{n}}',
    'terms' => [
        'post_tag' => ['term_{{n}}']
    ]
]);

Next

I will be working on the comments to move then to the remaining tables.

Probably related

I appreciate your input