Migrate tests/_support folder to WordPress Coding Standard

[MAILPOET-6240]
This commit is contained in:
Jan Lysý
2024-11-04 11:27:07 +01:00
committed by Jan Lysý
parent 113dbaae2d
commit be63af8102
5 changed files with 59 additions and 20 deletions

View File

@@ -1,5 +1,11 @@
<?php declare(strict_types=1);
<?php
/**
* This file is part of the MailPoet plugin tests.
*
* @package MailPoet\EmailEditor
*/
declare(strict_types=1);
/**
* Inherited Methods
@@ -21,18 +27,40 @@ class IntegrationTester extends \Codeception\Actor {
use _generated\IntegrationTesterActions;
private $wpTermIds = array();
/**
* WP term ids.
*
* @var array
*/
private $wp_term_ids = array();
private $createdCommentIds = array();
/**
* List of created comment ids.
*
* @var array
*/
private $created_comment_ids = array();
/**
* List of created posts.
*
* @var array
*/
private $posts = array();
public function createPost( array $params ): \WP_Post {
$postId = wp_insert_post( $params );
if ( $postId instanceof WP_Error ) {
/**
* Method for creating a post.
*
* @param array $params - Post parameters.
* @return \WP_Post
* @throws \Exception - If the post creation fails.
*/
public function create_post( array $params ): \WP_Post {
$post_id = wp_insert_post( $params );
if ( $post_id instanceof WP_Error ) {
throw new \Exception( 'Failed to create post' );
}
$post = get_post( $postId );
$post = get_post( $post_id );
if ( ! $post instanceof WP_Post ) {
throw new \Exception( 'Failed to fetch the post' );
}
@@ -40,11 +68,17 @@ class IntegrationTester extends \Codeception\Actor {
return $post;
}
public function cleanup() {
$this->deletePosts();
/**
* Method for cleaning up after the test.
*/
public function cleanup(): void {
$this->delete_posts();
}
private function deletePosts() {
/**
* Delete created posts.
*/
private function delete_posts(): void {
foreach ( $this->posts as $post ) {
wp_delete_post( $post->ID, true );
}

View File

@@ -1,4 +1,9 @@
<?php
/**
* This file is part of the MailPoet plugin.
*
* @package MailPoet\EmailEditor
*/
use _generated\UnitTesterActions;

View File

@@ -17,7 +17,7 @@ class Content_Renderer_Test extends \MailPoetTest {
$this->diContainer->get( Email_Editor::class )->initialize();
$this->diContainer->get( BlockTypesController::class )->initialize();
$this->renderer = $this->diContainer->get( Content_Renderer::class );
$this->emailPost = $this->tester->createPost(
$this->emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->',
)

View File

@@ -51,7 +51,7 @@ class Renderer_Test extends \MailPoetTest {
'themeController' => $themeControllerMock,
)
);
$this->emailPost = $this->tester->createPost(
$this->emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:paragraph --><p>Hello!</p><!-- /wp:paragraph -->',
)

View File

@@ -18,7 +18,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesButtonDefaultStyles() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
)
@@ -34,7 +34,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testButtonDefaultStylesDontOverwriteUserSetStyles() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:button {"backgroundColor":"white","textColor":"vivid-cyan-blue"} --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
)
@@ -46,7 +46,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesHeadingFontSize() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:heading {"level":1,"style":{"typography":{"fontSize":"large"}}} --><h1 class="wp-block-heading">Hello</h1><!-- /wp:heading -->',
)
@@ -57,7 +57,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesHeadingColors() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:heading {"level":1, "backgroundColor":"black", "textColor":"luminous-vivid-orange"} --><h1 class="wp-block-heading has-luminous-vivid-orange-color has-black-background-color">Hello</h1><!-- /wp:heading -->',
)
@@ -69,7 +69,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesParagraphColors() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:paragraph {style":{"color":{"background":"black", "text":"luminous-vivid-orange"}}} --><p class="has-luminous-vivid-orange-color has-black-background-color">Hello</p><!-- /wp:paragraph -->',
)
@@ -81,7 +81,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesListColors() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:list {"backgroundColor":"black","textColor":"luminous-vivid-orange","style":{"elements":{"link":{"color":{"text":"var:preset|color|vivid-red"}}}}} -->
<ul class="has-black-background-color has-luminous-vivid-orange-color has-text-color has-background has-link-color"><!-- wp:list-item -->
@@ -101,7 +101,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesColumnsColors() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '<!-- wp:columns {"backgroundColor":"vivid-green-cyan", "textColor":"black"} -->
<div class="wp-block-columns has-black-background-color has-luminous-vivid-orange-color"><!-- wp:column --><!-- /wp:column --></div>
@@ -115,7 +115,7 @@ class Renderer_Test extends \MailPoetTest {
}
public function testItInlinesColumnColors() {
$emailPost = $this->tester->createPost(
$emailPost = $this->tester->create_post(
array(
'post_content' => '
<!-- wp:column {"verticalAlignment":"stretch","backgroundColor":"black","textColor":"luminous-vivid-orange"} -->