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,14 +44,13 @@ 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);
$stati = ['future', 'draft', 'publish', 'pending', 'private'];
$types = ['posts', 'products'];
foreach ($types as $type) {
foreach ($stati as $status) {
$title = "testItGetsTransformedPosts test $status"; $title = "testItGetsTransformedPosts test $status";
$id = wp_insert_post([ $id = wp_insert_post([
'post_title' => $title, 'post_title' => $title,
@@ -76,12 +75,25 @@ class AutomatedLatestContentTest extends \MailPoetTest {
'featuredImagePosition' => 'belowTitle', '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->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."); $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;
} }
} }