Refactor Forms::duplicate() to use Doctrine instead of Paris

[MAILPOET-3038]
This commit is contained in:
Rodrigo Primo
2021-04-01 13:43:45 -03:00
committed by Veljko V
parent 3d2c62fc16
commit b3f82cccc5
5 changed files with 111 additions and 23 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace MailPoet\Form;
use Codeception\Util\Fixtures;
use MailPoet\Entities\FormEntity;
class FormSaveControllerTest extends \MailPoetTest {
/** @var FormSaveController */
private $saveController;
public function _before() {
parent::_before();
$this->saveController = $this->diContainer->get(FormSaveController::class);
}
public function testItDuplicatesForms() {
$form = $this->createForm();
$duplicate = $this->saveController->duplicate($form);
expect($duplicate->getName())->equals('Copy of ' . $form->getName());
expect($duplicate->getDeletedAt())->equals(null);
expect($duplicate->getBody())->equals($form->getBody());
expect($duplicate->getStatus())->equals($form->getStatus());
}
public function _after() {
$this->cleanup();
}
private function createForm(): FormEntity {
$form = new FormEntity('My Form');
$form->setBody(Fixtures::get('form_body_template'));
$this->entityManager->persist($form);
$this->entityManager->flush();
return $form;
}
private function cleanup() {
$this->truncateEntity(FormEntity::class);
}
}