Exclude deleted form from display below post/page check
[MAILPOET-2710]
This commit is contained in:
committed by
Jack Kitterhing
parent
c396d74d90
commit
ede14fc661
@ -84,7 +84,7 @@ class DisplayFormInWPContent {
|
|||||||
* @return FormEntity[]
|
* @return FormEntity[]
|
||||||
*/
|
*/
|
||||||
private function getForms(): array {
|
private function getForms(): array {
|
||||||
$forms = $this->formsRepository->findAll();
|
$forms = $this->formsRepository->findBy(['deletedAt' => null]);
|
||||||
return array_filter($forms, function($form) {
|
return array_filter($forms, function($form) {
|
||||||
return $this->shouldDisplayFormBellowContent($form);
|
return $this->shouldDisplayFormBellowContent($form);
|
||||||
});
|
});
|
||||||
|
@ -60,7 +60,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
'name' => 'Submit',
|
'name' => 'Submit',
|
||||||
]]);
|
]]);
|
||||||
$this->repository->expects($this->once())->method('findAll')->willReturn([$form]);
|
$this->repository->expects($this->once())->method('findBy')->willReturn([$form]);
|
||||||
$result = $this->hook->display('content');
|
$result = $this->hook->display('content');
|
||||||
expect($result)->notEquals('content');
|
expect($result)->notEquals('content');
|
||||||
expect($result)->endsWith($renderedForm);
|
expect($result)->endsWith($renderedForm);
|
||||||
@ -93,8 +93,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
'name' => 'Submit',
|
'name' => 'Submit',
|
||||||
]]);
|
]]);
|
||||||
$this->repository->expects($this->once())->method('findAll')->willReturn([$form]);
|
$this->repository->expects($this->once())->method('findBy')->willReturn([$form]);
|
||||||
|
|
||||||
$result = $this->hook->display('content');
|
$result = $this->hook->display('content');
|
||||||
expect($result)->equals('content');
|
expect($result)->equals('content');
|
||||||
}
|
}
|
||||||
@ -129,11 +128,10 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
'name' => 'Submit',
|
'name' => 'Submit',
|
||||||
]]);
|
]]);
|
||||||
$this->repository->expects($this->once())->method('findAll')->willReturn([$form1, $form2]);
|
$this->repository->expects($this->once())->method('findBy')->willReturn([$form1, $form2]);
|
||||||
$formHtml1 = '<form id="test-form-1"></form>';
|
$formHtml1 = '<form id="test-form-1"></form>';
|
||||||
$formHtml2 = '<form id="test-form-2"></form>';
|
$formHtml2 = '<form id="test-form-2"></form>';
|
||||||
$this->templateRenderer->expects($this->exactly(2))->method('render')->willReturnOnConsecutiveCalls($formHtml1, $formHtml2);
|
$this->templateRenderer->expects($this->exactly(2))->method('render')->willReturnOnConsecutiveCalls($formHtml1, $formHtml2);
|
||||||
|
|
||||||
$result = $this->hook->display('content');
|
$result = $this->hook->display('content');
|
||||||
expect($result)->notEquals('content');
|
expect($result)->notEquals('content');
|
||||||
expect($result)->endsWith($formHtml1 . $formHtml2);
|
expect($result)->endsWith($formHtml1 . $formHtml2);
|
||||||
@ -141,8 +139,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
|
|
||||||
public function testDoesNotAppendFormIfNotOnSinglePage() {
|
public function testDoesNotAppendFormIfNotOnSinglePage() {
|
||||||
$this->wp->expects($this->once())->method('isSingle')->willReturn(false);
|
$this->wp->expects($this->once())->method('isSingle')->willReturn(false);
|
||||||
$this->repository->expects($this->never())->method('findAll');
|
$this->repository->expects($this->never())->method('findBy');
|
||||||
|
|
||||||
$result = $this->hook->display('content');
|
$result = $this->hook->display('content');
|
||||||
expect($result)->equals('content');
|
expect($result)->equals('content');
|
||||||
}
|
}
|
||||||
@ -164,7 +161,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
'name' => 'Submit',
|
'name' => 'Submit',
|
||||||
]]);
|
]]);
|
||||||
$this->repository->expects($this->once())->method('findAll')->willReturn([$form]);
|
$this->repository->expects($this->once())->method('findBy')->willReturn([$form]);
|
||||||
|
|
||||||
$result = $this->hook->display('content');
|
$result = $this->hook->display('content');
|
||||||
expect($result)->equals('content');
|
expect($result)->equals('content');
|
||||||
@ -192,7 +189,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
'name' => 'Submit',
|
'name' => 'Submit',
|
||||||
]]);
|
]]);
|
||||||
$this->repository->expects($this->once())->method('findAll')->willReturn([$form]);
|
$this->repository->expects($this->once())->method('findBy')->willReturn([$form]);
|
||||||
|
|
||||||
$result = $this->hook->display('content');
|
$result = $this->hook->display('content');
|
||||||
expect($result)->notEquals('content');
|
expect($result)->notEquals('content');
|
||||||
@ -208,7 +205,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
$form1 = new FormEntity('My Form');
|
$form1 = new FormEntity('My Form');
|
||||||
$form2 = new FormEntity('My Form');
|
$form2 = new FormEntity('My Form');
|
||||||
|
|
||||||
$this->repository->expects($this->once())->method('findAll')->willReturn([$form1, $form2]);
|
$this->repository->expects($this->once())->method('findBy')->willReturn([$form1, $form2]);
|
||||||
|
|
||||||
$this->hook->display('content');
|
$this->hook->display('content');
|
||||||
}
|
}
|
||||||
@ -221,7 +218,7 @@ class DisplayFormInWPContentTest extends \MailPoetUnitTest {
|
|||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getTransient')
|
->method('getTransient')
|
||||||
->willReturn(['post' => true]);
|
->willReturn(['post' => true]);
|
||||||
$this->repository->expects($this->never())->method('findAll');
|
$this->repository->expects($this->never())->method('findBy');
|
||||||
|
|
||||||
$this->hook->display('content');
|
$this->hook->display('content');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user