Use dataprovider and clean up early
[MAILPOET-4883]
This commit is contained in:
@@ -44,44 +44,56 @@ 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);
|
||||
|
||||
$title = "testItGetsTransformedPosts test $status";
|
||||
$id = wp_insert_post([
|
||||
'post_title' => $title,
|
||||
'post_status' => $status,
|
||||
'post_author' => 1,
|
||||
'post_content' => 'This is a post to test something.',
|
||||
'post_date' => $status === 'future' ? gmdate('Y-m-d H:i:s', time() + 3600) : gmdate('Y-m-d H:i:s'),
|
||||
]);
|
||||
$this->assertIsNumeric($id);
|
||||
|
||||
$response = $this->endpoint->getTransformedPosts([
|
||||
'posts' => [$id],
|
||||
'postStatus' => $status,
|
||||
'type' => $type,
|
||||
'displayType' => 'excerpt',
|
||||
'titleFormat' => 'ul',
|
||||
'showDivider' => false,
|
||||
'imageFullWidth' => false,
|
||||
'readMoreType' => 'none',
|
||||
'titleIsLink' => false,
|
||||
'titleAlignment' => 'center',
|
||||
'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.");
|
||||
}
|
||||
|
||||
public function dataForTestItGetsTransformedPostsWithDifferentStatus() {
|
||||
$stati = ['future', 'draft', 'publish', 'pending', 'private'];
|
||||
$types = ['posts', 'products'];
|
||||
|
||||
$data = [];
|
||||
foreach ($types as $type) {
|
||||
foreach ($stati as $status) {
|
||||
$title = "testItGetsTransformedPosts test $status";
|
||||
$id = wp_insert_post([
|
||||
'post_title' => $title,
|
||||
'post_status' => $status,
|
||||
'post_author' => 1,
|
||||
'post_content' => 'This is a post to test something.',
|
||||
'post_date' => $status === 'future' ? gmdate('Y-m-d H:i:s', time() + 3600) : gmdate('Y-m-d H:i:s'),
|
||||
]);
|
||||
$this->assertIsNumeric($id);
|
||||
|
||||
$response = $this->endpoint->getTransformedPosts([
|
||||
'posts' => [$id],
|
||||
'postStatus' => $status,
|
||||
$data['status_' . $status . '_type_' . $type] = [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'displayType' => 'excerpt',
|
||||
'titleFormat' => 'ul',
|
||||
'showDivider' => false,
|
||||
'imageFullWidth' => false,
|
||||
'readMoreType' => 'none',
|
||||
'titleIsLink' => false,
|
||||
'titleAlignment' => 'center',
|
||||
'featuredImagePosition' => 'belowTitle',
|
||||
]);
|
||||
|
||||
$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);
|
||||
];
|
||||
}
|
||||
}
|
||||
wp_set_current_user($currentUserId);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user