Refactor Forms::delete() to use Doctrine
[MAILPOET-3039]
This commit is contained in:
@ -303,10 +303,10 @@ class Forms extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function delete($data = []) {
|
public function delete($data = []) {
|
||||||
$id = (isset($data['id']) ? (int)$data['id'] : false);
|
$form = $this->getForm($data);
|
||||||
$form = Form::findOne($id);
|
|
||||||
if ($form instanceof Form) {
|
if ($form instanceof FormEntity) {
|
||||||
$form->delete();
|
$this->formsRepository->delete($form);
|
||||||
|
|
||||||
return $this->successResponse(null, ['count' => 1]);
|
return $this->successResponse(null, ['count' => 1]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,6 +36,11 @@ class FormsRepository extends Repository {
|
|||||||
->getSingleScalarResult();
|
->getSingleScalarResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete(FormEntity $form) {
|
||||||
|
$this->remove($form);
|
||||||
|
$this->flush();
|
||||||
|
}
|
||||||
|
|
||||||
public function trash(FormEntity $form) {
|
public function trash(FormEntity $form) {
|
||||||
$this->updateDeletedAt($form, Carbon::now());
|
$this->updateDeletedAt($form, Carbon::now());
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,13 @@ class FormsTest extends \MailPoetTest {
|
|||||||
expect($response->meta['count'])->equals(1);
|
expect($response->meta['count'])->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testErrorWhenDeletingNonExistentForm() {
|
||||||
|
$response = $this->endpoint->delete(['id' => 'Invalid ID']);
|
||||||
|
expect($response->errors[0]['error'])->equals('not_found');
|
||||||
|
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||||
|
expect($response->meta)->isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public function testItCanDuplicateAForm() {
|
public function testItCanDuplicateAForm() {
|
||||||
$response = $this->endpoint->duplicate(['id' => $this->form1->getId()]);
|
$response = $this->endpoint->duplicate(['id' => $this->form1->getId()]);
|
||||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||||
|
@ -13,6 +13,13 @@ class FormsRepositoryTest extends \MailPoetTest {
|
|||||||
$this->repository = $this->diContainer->get(FormsRepository::class);
|
$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() {
|
public function testItCanTrashForm() {
|
||||||
$form = $this->createForm('Form 1');
|
$form = $this->createForm('Form 1');
|
||||||
expect($form->getDeletedAt())->null();
|
expect($form->getDeletedAt())->null();
|
||||||
|
Reference in New Issue
Block a user