From 82504b90cfdc9a95b8d0d81eaf9fd5077d1eacfa Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Fri, 14 Aug 2020 16:28:27 +0200 Subject: [PATCH] feat(WPDb) add methods to add/remove thumbnail fixes #434 --- docs/modules/WPBrowser.md | 2 +- docs/modules/WPDb.md | 42 +++++++++++++++ src/Codeception/Module/WPDb.php | 43 +++++++++++++++ .../_generated/AcceptanceTesterActions.php | 54 ++++++++++++++++++- .../_generated/ClimoduleTesterActions.php | 54 ++++++++++++++++++- .../_generated/EventsTesterActions.php | 51 +++++++++++++++++- .../_generated/FunctionalTesterActions.php | 48 ++++++++++++++++- .../_generated/IsolatedTesterActions.php | 3 +- .../_generated/MuloaderTesterActions.php | 3 +- .../_generated/WebdriverTesterActions.php | 48 ++++++++++++++++- .../_generated/Wpcli_moduleTesterActions.php | 48 ++++++++++++++++- .../_generated/WpfunctionalTesterActions.php | 54 ++++++++++++++++++- .../_generated/WploaderTesterActions.php | 3 +- .../Wploader_multisiteTesterActions.php | 3 +- ...Wploader_wpdb_interactionTesterActions.php | 51 +++++++++++++++++- .../_generated/WpmoduleTesterActions.php | 51 +++++++++++++++++- tests/functional/WPDbAttachmentCest.php | 23 ++++++++ 17 files changed, 562 insertions(+), 19 deletions(-) diff --git a/docs/modules/WPBrowser.md b/docs/modules/WPBrowser.md index 8570bdcf2..e2572990a 100644 --- a/docs/modules/WPBrowser.md +++ b/docs/modules/WPBrowser.md @@ -412,6 +412,6 @@ $I->loginAs('user', 'password'); *This class extends \Codeception\Module\PhpBrowser* -*This class implements \Codeception\Lib\Interfaces\RequiresPackage, \Codeception\Lib\Interfaces\MultiSession, \Codeception\Lib\Interfaces\Remote, \Codeception\Lib\Interfaces\Web, \Codeception\Lib\Interfaces\PageSourceSaver, \Codeception\Lib\Interfaces\ElementLocator, \Codeception\Lib\Interfaces\ConflictsWithModule* +*This class implements \Codeception\Lib\Interfaces\MultiSession, \Codeception\Lib\Interfaces\Remote, \Codeception\Lib\Interfaces\Web, \Codeception\Lib\Interfaces\PageSourceSaver, \Codeception\Lib\Interfaces\ElementLocator, \Codeception\Lib\Interfaces\ConflictsWithModule* diff --git a/docs/modules/WPDb.md b/docs/modules/WPDb.md index f04159fbe..b6d39a756 100644 --- a/docs/modules/WPDb.md +++ b/docs/modules/WPDb.md @@ -209,6 +209,9 @@ This will avoid issues where the `WPLoader` module could `exit`, terminating the
  • dontHavePostMetaInDatabase
  • +
  • + dontHavePostThumbnailInDatabase +
  • dontHaveSiteOptionInDatabase
  • @@ -455,6 +458,9 @@ This will avoid issues where the `WPLoader` module could `exit`, terminating the
  • havePostInDatabase
  • +
  • + havePostThumbnailInDatabase +
  • havePostmetaInDatabase
  • @@ -751,6 +757,25 @@ $postId = $I->havePostInDatabase(['meta_input' => ['rating' => 23]]);
  • array $criteria - An array of search criteria.
  • +

    dontHavePostThumbnailInDatabase

    + +
    + +

    Remove the thumbnail (featured image) from a post, if any. Please note: the method will NOT remove the attachment post, post meta and file.

    +```php +$attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + $postId = $I->havePostInDatabase(); + // Attach the thumbnail to the post. + $I->havePostThumbnailInDatabase($postId, $attachmentId); + // Remove the thumbnail from the post. + $I->dontHavePostThumbnailInDatabase($postId); +``` + +

    Parameters

    + + +

    dontHaveSiteOptionInDatabase


    @@ -2104,6 +2129,23 @@ $I->haveOptionInDatabase('posts_per_page', 23);
  • array $data - An associative array of post data to override default and random generated values.
  • +

    havePostThumbnailInDatabase

    + +
    + +

    Assigns the specified attachment ID as thumbnail (featured image) to a post.

    +```php +$attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + $postId = $I->havePostInDatabase(); + $I->havePostThumbnailInDatabase($postId, $attachmentId); +``` + +

    Parameters

    + + +

    havePostmetaInDatabase


    diff --git a/src/Codeception/Module/WPDb.php b/src/Codeception/Module/WPDb.php index 790f46b06..4453c0b06 100644 --- a/src/Codeception/Module/WPDb.php +++ b/src/Codeception/Module/WPDb.php @@ -4141,4 +4141,47 @@ protected function prepareDb() */ $this->doAction(static::EVENT_AFTER_DB_PREPARE, $this, $this->config); } + + /** + * Assigns the specified attachment ID as thumbnail (featured image) to a post. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * + * @return int The inserted meta id. + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) + { + $this->dontHavePostThumbnailInDatabase($postId); + return $this->havePostmetaInDatabase($postId, '_thumbnail_id', (int) $thumbnailId); + } + + /** + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + */ + public function dontHavePostThumbnailInDatabase($postId) + { + $this->dontHavePostMetaInDatabase([ 'post_id' => $postId, 'meta_key' => '_thumbnail_id' ]); + } } diff --git a/tests/_support/_generated/AcceptanceTesterActions.php b/tests/_support/_generated/AcceptanceTesterActions.php index 0109efdfd..431ea0173 100644 --- a/tests/_support/_generated/AcceptanceTesterActions.php +++ b/tests/_support/_generated/AcceptanceTesterActions.php @@ -1,4 +1,4 @@ -setServerParameters([]); * ``` + * @param array $params * @see \Codeception\Lib\InnerBrowser::setServerParameters() */ public function setServerParameters($params) { @@ -2503,6 +2505,8 @@ public function setServerParameters($params) { * ```php * $I->haveServerParameter('name', 'value'); * ``` + * @param $name + * @param $value * @see \Codeception\Lib\InnerBrowser::haveServerParameter() */ public function haveServerParameter($name, $value) { @@ -6657,6 +6661,52 @@ public function cantSeePostWithTermInDatabase($post_id, $term_taxonomy_id, $term } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Assigns the specified attachment ID as thumbnail (featured image) to a post. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/ClimoduleTesterActions.php b/tests/_support/_generated/ClimoduleTesterActions.php index 99f45b555..bd820d093 100644 --- a/tests/_support/_generated/ClimoduleTesterActions.php +++ b/tests/_support/_generated/ClimoduleTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -4512,7 +4558,8 @@ public function amOnSubdomain($subdomain) { * It is not recommended to use this command on a regular basis. * If Codeception lacks important Guzzle Client methods, implement them and submit patches. * - * @param callable $function + * @param Closure $function + * @return mixed * @see \Codeception\Module\PhpBrowser::executeInGuzzle() */ public function executeInGuzzle($function) { @@ -6818,6 +6865,7 @@ public function moveBack($numberOfSteps = null) { * ```php * $I->setServerParameters([]); * ``` + * @param array $params * @see \Codeception\Lib\InnerBrowser::setServerParameters() */ public function setServerParameters($params) { @@ -6833,6 +6881,8 @@ public function setServerParameters($params) { * ```php * $I->haveServerParameter('name', 'value'); * ``` + * @param $name + * @param $value * @see \Codeception\Lib\InnerBrowser::haveServerParameter() */ public function haveServerParameter($name, $value) { diff --git a/tests/_support/_generated/EventsTesterActions.php b/tests/_support/_generated/EventsTesterActions.php index ad8827387..63a3c31aa 100644 --- a/tests/_support/_generated/EventsTesterActions.php +++ b/tests/_support/_generated/EventsTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -4054,7 +4100,8 @@ public function getPluginsFolder($path = null) { * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() diff --git a/tests/_support/_generated/FunctionalTesterActions.php b/tests/_support/_generated/FunctionalTesterActions.php index a7db0f323..9b7a2f738 100644 --- a/tests/_support/_generated/FunctionalTesterActions.php +++ b/tests/_support/_generated/FunctionalTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/IsolatedTesterActions.php b/tests/_support/_generated/IsolatedTesterActions.php index 8ad10b9e9..0ffb2e8f2 100644 --- a/tests/_support/_generated/IsolatedTesterActions.php +++ b/tests/_support/_generated/IsolatedTesterActions.php @@ -53,7 +53,8 @@ public function getPluginsFolder($path = null) { * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() diff --git a/tests/_support/_generated/MuloaderTesterActions.php b/tests/_support/_generated/MuloaderTesterActions.php index 75bcd96b0..5ddd6aa23 100644 --- a/tests/_support/_generated/MuloaderTesterActions.php +++ b/tests/_support/_generated/MuloaderTesterActions.php @@ -53,7 +53,8 @@ public function getPluginsFolder($path = null) { * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() diff --git a/tests/_support/_generated/WebdriverTesterActions.php b/tests/_support/_generated/WebdriverTesterActions.php index fee62caa9..5203a1585 100644 --- a/tests/_support/_generated/WebdriverTesterActions.php +++ b/tests/_support/_generated/WebdriverTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/Wpcli_moduleTesterActions.php b/tests/_support/_generated/Wpcli_moduleTesterActions.php index 1c377a24e..7f85d5962 100644 --- a/tests/_support/_generated/Wpcli_moduleTesterActions.php +++ b/tests/_support/_generated/Wpcli_moduleTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/WpfunctionalTesterActions.php b/tests/_support/_generated/WpfunctionalTesterActions.php index d91f3f247..c144aea1c 100644 --- a/tests/_support/_generated/WpfunctionalTesterActions.php +++ b/tests/_support/_generated/WpfunctionalTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -6466,6 +6512,7 @@ public function moveBack($numberOfSteps = null) { * ```php * $I->setServerParameters([]); * ``` + * @param array $params * @see \Codeception\Lib\InnerBrowser::setServerParameters() */ public function setServerParameters($params) { @@ -6481,6 +6528,8 @@ public function setServerParameters($params) { * ```php * $I->haveServerParameter('name', 'value'); * ``` + * @param $name + * @param $value * @see \Codeception\Lib\InnerBrowser::haveServerParameter() */ public function haveServerParameter($name, $value) { @@ -6974,7 +7023,8 @@ public function getPluginsFolder($path = null) { * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() diff --git a/tests/_support/_generated/WploaderTesterActions.php b/tests/_support/_generated/WploaderTesterActions.php index 5163f81c5..2e4f0d46a 100644 --- a/tests/_support/_generated/WploaderTesterActions.php +++ b/tests/_support/_generated/WploaderTesterActions.php @@ -64,7 +64,8 @@ public function getPluginsFolder($path = null) { * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() diff --git a/tests/_support/_generated/Wploader_multisiteTesterActions.php b/tests/_support/_generated/Wploader_multisiteTesterActions.php index 4c88d5635..7f1613de4 100644 --- a/tests/_support/_generated/Wploader_multisiteTesterActions.php +++ b/tests/_support/_generated/Wploader_multisiteTesterActions.php @@ -64,7 +64,8 @@ public function getPluginsFolder($path = null) { * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() diff --git a/tests/_support/_generated/Wploader_wpdb_interactionTesterActions.php b/tests/_support/_generated/Wploader_wpdb_interactionTesterActions.php index 84cc98779..e487c3b0e 100644 --- a/tests/_support/_generated/Wploader_wpdb_interactionTesterActions.php +++ b/tests/_support/_generated/Wploader_wpdb_interactionTesterActions.php @@ -1,4 +1,4 @@ -factory()->user->create(['role' => 'administrator']); * ``` * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object factories. + * @return \tad\WPBrowser\Module\WPLoader\FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \Codeception\Module\WPLoader::factory() @@ -3899,6 +3900,52 @@ public function cantSeePostWithTermInDatabase($post_id, $term_taxonomy_id, $term } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Assigns the specified attachment ID as thumbnail (featured image) to a post. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/WpmoduleTesterActions.php b/tests/_support/_generated/WpmoduleTesterActions.php index 86b35223f..71c5c154b 100644 --- a/tests/_support/_generated/WpmoduleTesterActions.php +++ b/tests/_support/_generated/WpmoduleTesterActions.php @@ -1,4 +1,4 @@ -haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * ``` + * + * @param int $postId The post ID to assign the thumbnail (featured image) to. + * @param int $thumbnailId The post ID of the attachment. + * @see \Codeception\Module\WPDb::havePostThumbnailInDatabase() + */ + public function havePostThumbnailInDatabase($postId, $thumbnailId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('havePostThumbnailInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Remove the thumbnail (featured image) from a post, if any. + * + * Please note: the method will NOT remove the attachment post, post meta and file. + * + * @example + * ```php + * $attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png')); + * $postId = $I->havePostInDatabase(); + * // Attach the thumbnail to the post. + * $I->havePostThumbnailInDatabase($postId, $attachmentId); + * // Remove the thumbnail from the post. + * $I->dontHavePostThumbnailInDatabase($postId); + * ``` + * + * @param int $postId The post ID to remove the thumbnail (featured image) from. + * @see \Codeception\Module\WPDb::dontHavePostThumbnailInDatabase() + */ + public function dontHavePostThumbnailInDatabase($postId) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('dontHavePostThumbnailInDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -6466,6 +6512,7 @@ public function moveBack($numberOfSteps = null) { * ```php * $I->setServerParameters([]); * ``` + * @param array $params * @see \Codeception\Lib\InnerBrowser::setServerParameters() */ public function setServerParameters($params) { @@ -6481,6 +6528,8 @@ public function setServerParameters($params) { * ```php * $I->haveServerParameter('name', 'value'); * ``` + * @param $name + * @param $value * @see \Codeception\Lib\InnerBrowser::haveServerParameter() */ public function haveServerParameter($name, $value) { diff --git a/tests/functional/WPDbAttachmentCest.php b/tests/functional/WPDbAttachmentCest.php index 7ff4040ef..f797e3eac 100644 --- a/tests/functional/WPDbAttachmentCest.php +++ b/tests/functional/WPDbAttachmentCest.php @@ -369,4 +369,27 @@ public function should_allow_removing_attachment_files_along_with_the_attachment $I->dontSeeUploadedFileFound($sizeData['file']); } } + + /** + * It should allow having a post thumbnail in the database + * + * @test + */ + public function should_allow_having_a_post_thumbnail_in_the_database(FunctionalTester $I) + { + $postId = $I->havePostInDatabase(); + $file = codecept_data_dir('attachments/kitten.jpeg'); + $thumbnailId = $I->haveAttachmentInDatabase($file); + $I->havePostThumbnailInDatabase($postId, $thumbnailId); + + $I->seeUploadedFileFound('kitten.jpeg', 'now'); + $I->seeAttachmentInDatabase(['ID' => $thumbnailId]); + $I->seePostMetaInDatabase([ 'post_id' => $postId, 'meta_key' => '_thumbnail_id', 'meta_value' => $thumbnailId ]); + + $I->dontHavePostThumbnailInDatabase($postId); + + $I->seeUploadedFileFound('kitten.jpeg', 'now'); + $I->seeAttachmentInDatabase(['ID' => $thumbnailId]); + $I->dontSeePostMetaInDatabase([ 'post_id' => $postId, 'meta_key' => '_thumbnail_id', 'meta_value' => $thumbnailId ]); + } }