Skip to content

Commit

Permalink
Merge pull request #435 from lucatume/feat/issue-434
Browse files Browse the repository at this point in the history
feat(WPDb) add methods to add/remove thumbnail
  • Loading branch information
lucatume authored Aug 14, 2020
2 parents 4f42d00 + 82504b9 commit 044f42d
Show file tree
Hide file tree
Showing 17 changed files with 562 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/modules/WPBrowser.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

<!--/doc-->
42 changes: 42 additions & 0 deletions docs/modules/WPDb.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ This will avoid issues where the `WPLoader` module could `exit`, terminating the
<li>
<a href="#donthavepostmetaindatabase">dontHavePostMetaInDatabase</a>
</li>
<li>
<a href="#donthavepostthumbnailindatabase">dontHavePostThumbnailInDatabase</a>
</li>
<li>
<a href="#donthavesiteoptionindatabase">dontHaveSiteOptionInDatabase</a>
</li>
Expand Down Expand Up @@ -455,6 +458,9 @@ This will avoid issues where the `WPLoader` module could `exit`, terminating the
<li>
<a href="#havepostindatabase">havePostInDatabase</a>
</li>
<li>
<a href="#havepostthumbnailindatabase">havePostThumbnailInDatabase</a>
</li>
<li>
<a href="#havepostmetaindatabase">havePostmetaInDatabase</a>
</li>
Expand Down Expand Up @@ -751,6 +757,25 @@ $postId = $I->havePostInDatabase(['meta_input' => ['rating' => 23]]);
<li><code>array</code> <strong>$criteria</strong> - An array of search criteria.</li></ul>


<h3>dontHavePostThumbnailInDatabase</h3>

<hr>

<p>Remove the thumbnail (featured image) from a post, if any. Please note: the method will NOT remove the attachment post, post meta and file.</p>
```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);
```

<h4>Parameters</h4>
<ul>
<li><code>int</code> <strong>$postId</strong> - The post ID to remove the thumbnail (featured image) from.</li></ul>


<h3>dontHaveSiteOptionInDatabase</h3>

<hr>
Expand Down Expand Up @@ -2104,6 +2129,23 @@ $I->haveOptionInDatabase('posts_per_page', 23);
<li><code>array</code> <strong>$data</strong> - An associative array of post data to override default and random generated values.</li></ul>


<h3>havePostThumbnailInDatabase</h3>

<hr>

<p>Assigns the specified attachment ID as thumbnail (featured image) to a post.</p>
```php
$attachmentId = $I->haveAttachmentInDatabase(codecept_data_dir('some-image.png'));
$postId = $I->havePostInDatabase();
$I->havePostThumbnailInDatabase($postId, $attachmentId);
```

<h4>Parameters</h4>
<ul>
<li><code>int</code> <strong>$postId</strong> - The post ID to assign the thumbnail (featured image) to.</li>
<li><code>int</code> <strong>$thumbnailId</strong> - The post ID of the attachment.</li></ul>


<h3>havePostmetaInDatabase</h3>

<hr>
Expand Down
43 changes: 43 additions & 0 deletions src/Codeception/Module/WPDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]);
}
}
54 changes: 52 additions & 2 deletions tests/_support/_generated/AcceptanceTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 363241e42086f9da3df065ba58668318
<?php //[STAMP] 583277b84e7bb4ae83553c2b6e6d2a84
namespace _generated;

// This class was automatically generated by build task
Expand Down Expand Up @@ -182,7 +182,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) {
Expand Down Expand Up @@ -2488,6 +2489,7 @@ public function moveBack($numberOfSteps = null) {
* ```php
* $I->setServerParameters([]);
* ```
* @param array $params
* @see \Codeception\Lib\InnerBrowser::setServerParameters()
*/
public function setServerParameters($params) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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.
*
Expand Down
54 changes: 52 additions & 2 deletions tests/_support/_generated/ClimoduleTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] ea37de6e5f4cf505b39c005855e41cc2
<?php //[STAMP] 85e12dd37b774a2c5b4b214e0b103077
namespace _generated;

// This class was automatically generated by build task
Expand Down Expand Up @@ -3997,6 +3997,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.
*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -6818,6 +6865,7 @@ public function moveBack($numberOfSteps = null) {
* ```php
* $I->setServerParameters([]);
* ```
* @param array $params
* @see \Codeception\Lib\InnerBrowser::setServerParameters()
*/
public function setServerParameters($params) {
Expand All @@ -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) {
Expand Down
51 changes: 49 additions & 2 deletions tests/_support/_generated/EventsTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //[STAMP] 338680f88639faf1ed5837f992c8507b
<?php //[STAMP] 572c0ea8b5b160899e2dd732ce713ed6
namespace _generated;

// This class was automatically generated by build task
Expand Down Expand Up @@ -3668,6 +3668,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.
*
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 044f42d

Please sign in to comment.