Register email patterns directly in plugin
[MAILPOET-6243]
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
5885077838
commit
e74e1ef2a2
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Patterns;
|
||||
|
||||
/**
|
||||
* Dummy test pattern
|
||||
*/
|
||||
class Dummy_Test_Pattern extends Abstract_Pattern {
|
||||
/**
|
||||
* Name of the pattern
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'dummy-test-pattern';
|
||||
/**
|
||||
* Namespace of the pattern
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'dummy';
|
||||
/**
|
||||
* Get the pattern content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content(): string {
|
||||
return '<!-- wp:paragraph --><p>Test pattern</p><!-- /wp:paragraph -->';
|
||||
}
|
||||
/**
|
||||
* Get the pattern title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title(): string {
|
||||
return 'Test pattern title';
|
||||
}
|
||||
}
|
@@ -8,8 +8,6 @@
|
||||
declare(strict_types = 1);
|
||||
namespace MailPoet\EmailEditor\Engine\Patterns;
|
||||
|
||||
require_once 'Dummy_Test_Pattern.php';
|
||||
|
||||
/**
|
||||
* Integration test for Patterns class
|
||||
*/
|
||||
@@ -41,36 +39,10 @@ class Patterns_Test extends \MailPoetTest {
|
||||
$this->assertEquals( 'A collection of email content layouts.', $category['description'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the patterns added via filter are registered in WP_Block_Patterns_Registry
|
||||
*/
|
||||
public function testItRegistersPatterns() {
|
||||
$pattern = new Dummy_Test_Pattern();
|
||||
add_filter(
|
||||
'mailpoet_email_editor_block_patterns',
|
||||
function ( $patterns ) use ( $pattern ) {
|
||||
$patterns[] = $pattern;
|
||||
return $patterns;
|
||||
}
|
||||
);
|
||||
$this->patterns->initialize();
|
||||
$block_patterns = \WP_Block_Patterns_Registry::get_instance()->get_all_registered();
|
||||
$block_pattern = array_pop( $block_patterns );
|
||||
$this->assertEquals( 'dummy/dummy-test-pattern', $block_pattern['name'] );
|
||||
$this->assertEquals( $pattern->get_content(), $block_pattern['content'] );
|
||||
$this->assertEquals( $pattern->get_title(), $block_pattern['title'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean registered patterns and categories
|
||||
*/
|
||||
private function cleanup_patterns() {
|
||||
$registry = \WP_Block_Patterns_Registry::get_instance();
|
||||
$block_patterns = $registry->get_all_registered();
|
||||
foreach ( $block_patterns as $pattern ) {
|
||||
$registry->unregister( $pattern['name'] );
|
||||
}
|
||||
|
||||
$categories_registry = \WP_Block_Pattern_Categories_Registry::get_instance();
|
||||
$categories = $categories_registry->get_all_registered();
|
||||
foreach ( $categories as $category ) {
|
||||
|
Reference in New Issue
Block a user