Skip to content

Commit

Permalink
Fix formcontroller 404 handling and add tests (#105)
Browse files Browse the repository at this point in the history
* added functional test for form api

* fix form controller api

* add fields to formcontroller test
  • Loading branch information
alexander-schranz committed Nov 2, 2017
1 parent ca8d531 commit a6c3cf3
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 45 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
@@ -0,0 +1,9 @@
.gitattributes export-ignore
.gitignore export-ignore
.styleci.yml export-ignore
.travis.yml export-ignore
CHANGELOG.md export-ignore
Gruntfile.js export-ignore
package.json export-ignore
phpunit.xml.dist export-ignore
/Tests export-ignore
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,8 +2,9 @@

## 0.4.0 (unreleased)

- FEATURE #104 Add search to dynamic list
- FEATURE #103 Add test setup
- ENHANCEMENT #105 Add functional api tests
- FEATURE #104 Add search to dynamic list
- ENHANCEMENT #103 Add test setup

## 0.3.2

Expand Down
28 changes: 18 additions & 10 deletions Controller/FormController.php
Expand Up @@ -11,6 +11,7 @@

namespace Sulu\Bundle\FormBundle\Controller;

use Doctrine\ORM\NoResultException;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use Sulu\Bundle\FormBundle\Entity\Form;
Expand Down Expand Up @@ -243,8 +244,12 @@ public function getAction(Request $request, $id)
{
$locale = $this->getLocale($request);

// get entity
$entity = $this->getManager()->findById($id, $locale);
try {
// get entity
$entity = $this->getManager()->findById($id, $locale);
} catch (NoResultException $e) {
throw $this->createNotFoundException(sprintf('No form with id "%s" was found!', $id), $e);
}

return $this->handleView($this->view($this->getApiEntity($entity, $locale)));
}
Expand All @@ -261,7 +266,7 @@ public function postAction(Request $request)
// create entity
$entity = $this->getManager()->save($this->getData($request), $locale);

return $this->handleView($this->view($this->getApiEntity($entity, $locale)));
return $this->handleView($this->view($this->getApiEntity($entity, $locale), 201));
}

/**
Expand All @@ -275,7 +280,11 @@ public function putAction(Request $request, $id)
$locale = $this->getLocale($request);

// save entity
$entity = $this->getManager()->save($this->getData($request), $locale, $id);
try {
$entity = $this->getManager()->save($this->getData($request), $locale, $id);
} catch (NoResultException $e) {
throw $this->createNotFoundException(sprintf('No form with id "%s" was found!', $id), $e);
}

return $this->handleView($this->view($this->getApiEntity($entity, $locale)));
}
Expand All @@ -290,14 +299,13 @@ public function deleteAction(Request $request, $id)
{
$locale = $this->getLocale($request);

// delete entity
$entity = $this->getManager()->delete($id, $locale);

if (!$entity) {
return new Response('', 204);
try {
$this->getManager()->delete($id, $locale);
} catch (NoResultException $e) {
throw $this->createNotFoundException(sprintf('No form with id "%s" was found!', $id), $e);
}

return $this->handleView($this->view($this->getApiEntity($entity, $locale)));
return new Response('', 204);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Entity/FormTranslation.php
Expand Up @@ -67,22 +67,22 @@ class FormTranslation implements AuditableInterface
/**
* @var bool
*/
private $sendAttachments;
private $sendAttachments = false;

/**
* @var bool
*/
private $deactivateNotifyMails;
private $deactivateNotifyMails = false;

/**
* @var bool
*/
private $deactivateCustomerMails;
private $deactivateCustomerMails = false;

/**
* @var bool
*/
private $replyTo;
private $replyTo = false;

/**
* @var string
Expand Down
8 changes: 4 additions & 4 deletions Manager/FormManager.php
Expand Up @@ -107,10 +107,10 @@ public function save($data, $locale = null, $id = null)
$translation->setMailText(self::getValue($data, 'mailText'));
$translation->setSubmitLabel(self::getValue($data, 'submitLabel'));
$translation->setSuccessText(self::getValue($data, 'successText'));
$translation->setSendAttachments(self::getValue($data, 'sendAttachments'));
$translation->setDeactivateNotifyMails(self::getValue($data, 'deactivateNotifyMails'));
$translation->setDeactivateCustomerMails(self::getValue($data, 'deactivateCustomerMails'));
$translation->setReplyTo(self::getValue($data, 'replyTo'));
$translation->setSendAttachments(self::getValue($data, 'sendAttachments', false));
$translation->setDeactivateNotifyMails(self::getValue($data, 'deactivateNotifyMails', false));
$translation->setDeactivateCustomerMails(self::getValue($data, 'deactivateCustomerMails', false));
$translation->setReplyTo(self::getValue($data, 'replyTo', false));
$translation->setChanged(new \DateTime());

// Add Translation to Form.
Expand Down

0 comments on commit a6c3cf3

Please sign in to comment.