Allow but ignore not string content in MailPoet\Form\DisplayFormInWPContent

[MAILPOET-2699]
This commit is contained in:
Rostislav Wolny
2020-02-12 17:00:46 +01:00
committed by Jack Kitterhing
parent 57d480c6e4
commit 490a72aed3
2 changed files with 18 additions and 2 deletions

View File

@@ -24,8 +24,14 @@ class DisplayFormInWPContent {
$this->formRenderer = $formRenderer;
}
public function display(string $content): string {
if(!$this->shouldDisplay()) return $content;
/**
* This takes input from an action and any plugin or theme can pass anything.
* We return string for regular content otherwise we just pass thru what comes.
* @param mixed $content
* @return string|mixed
*/
public function display($content = null) {
if (!is_string($content) || !$this->shouldDisplay()) return $content;
$forms = $this->getForms();
if (count($forms) === 0) {

View File

@@ -59,6 +59,16 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
expect($result)->endsWith($renderedFormStyles . $renderedForm);
}
public function testItPassThruNonStringPostContent() {
$this->wp->expects($this->never())->method('isSingle');
$this->wp->expects($this->never())->method('isSingular');
$this->repository->expects($this->never())->method('findAll');
expect($this->hook->display(null))->null();
expect($this->hook->display([1,2,3]))->equals([1,2,3]);
expect($this->hook->display(1))->equals(1);
expect($this->hook->display(1.1))->equals(1.1);
}
public function testDoesNotAppendFormIfDisabled() {
$this->wp->expects($this->once())->method('isSingle')->willReturn(true);
$this->wp->expects($this->any())->method('isPage')->willReturn(false);