Use dataprovider and clean up early
[MAILPOET-4883]
This commit is contained in:
@@ -44,14 +44,13 @@ class AutomatedLatestContentTest extends \MailPoetTest {
|
||||
$this->assertSame('Uncategorized', $response->data['0']->name);
|
||||
}
|
||||
|
||||
public function testItGetsTransformedPostsWithDifferentStatus() {
|
||||
/**
|
||||
* @dataProvider dataForTestItGetsTransformedPostsWithDifferentStatus
|
||||
*/
|
||||
public function testItGetsTransformedPostsWithDifferentStatus(string $status, string $type) {
|
||||
$currentUserId = wp_get_current_user()->ID;
|
||||
wp_set_current_user(1);
|
||||
|
||||
$stati = ['future', 'draft', 'publish', 'pending', 'private'];
|
||||
$types = ['posts', 'products'];
|
||||
foreach ($types as $type) {
|
||||
foreach ($stati as $status) {
|
||||
$title = "testItGetsTransformedPosts test $status";
|
||||
$id = wp_insert_post([
|
||||
'post_title' => $title,
|
||||
@@ -76,12 +75,25 @@ class AutomatedLatestContentTest extends \MailPoetTest {
|
||||
'featuredImagePosition' => 'belowTitle',
|
||||
]);
|
||||
|
||||
wp_delete_post($id, true);
|
||||
wp_set_current_user($currentUserId);
|
||||
$this->assertCount(1, $response->data, "Post \"$id\" with status \"$status\" was not fetched properly.");
|
||||
$this->assertStringContainsString($title, $response->data[0]['text'], "Response for Post \"$id\" with status \"$status\" did not contain the title.");
|
||||
}
|
||||
|
||||
wp_delete_post($id, true);
|
||||
public function dataForTestItGetsTransformedPostsWithDifferentStatus() {
|
||||
$stati = ['future', 'draft', 'publish', 'pending', 'private'];
|
||||
$types = ['posts', 'products'];
|
||||
|
||||
$data = [];
|
||||
foreach ($types as $type) {
|
||||
foreach ($stati as $status) {
|
||||
$data['status_' . $status . '_type_' . $type] = [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
];
|
||||
}
|
||||
}
|
||||
wp_set_current_user($currentUserId);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user