Files
piratepoet/tests/integration/Form/FormsRepositoryTest.php
Rodrigo Primo 5ceb084c64 Refactor Forms::delete() to use Doctrine
[MAILPOET-3039]
2021-04-12 13:35:14 +02:00

49 lines
1.3 KiB
PHP

<?php
namespace MailPoet\Form;
use MailPoet\Entities\FormEntity;
class FormsRepositoryTest extends \MailPoetTest {
/** @var FormsRepository */
private $repository;
public function _before() {
parent::_before();
$this->repository = $this->diContainer->get(FormsRepository::class);
}
public function testItCanDeleteForm() {
$form = $this->createForm('Form 1');
expect($this->repository->findOneById($form->getId()))->isInstanceOf(FormEntity::class);
$this->repository->delete($form);
expect($form->getId())->null();
}
public function testItCanTrashForm() {
$form = $this->createForm('Form 1');
expect($form->getDeletedAt())->null();
$this->repository->trash($form);
expect($form->getDeletedAt())->notNull();
}
public function testItCanRestoreForm() {
$form = $this->createForm('Form 1');
$this->repository->trash($form);
expect($form->getDeletedAt())->notNull();
$this->repository->restore($form);
expect($form->getDeletedAt())->null();
}
public function _after() {
$this->truncateEntity(FormEntity::class);
}
private function createForm(string $name): FormEntity {
$form = new FormEntity($name);
$this->repository->persist($form);
$this->repository->flush();
return $form;
}
}