Use dataprovider and clean up early

[MAILPOET-4883]
This commit is contained in:
David Remer
2023-01-26 08:39:24 +02:00
committed by Aschepikov
parent 9e62501c30
commit 623010a644

View File

@@ -44,44 +44,56 @@ class AutomatedLatestContentTest extends \MailPoetTest {
$this->assertSame('Uncategorized', $response->data['0']->name); $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; $currentUserId = wp_get_current_user()->ID;
wp_set_current_user(1); 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']; $stati = ['future', 'draft', 'publish', 'pending', 'private'];
$types = ['posts', 'products']; $types = ['posts', 'products'];
$data = [];
foreach ($types as $type) { foreach ($types as $type) {
foreach ($stati as $status) { foreach ($stati as $status) {
$title = "testItGetsTransformedPosts test $status"; $data['status_' . $status . '_type_' . $type] = [
$id = wp_insert_post([ 'status' => $status,
'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, '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;
} }
} }