Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 410 empty target in import #31

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Import/Writer/Writer.php
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManagerInterface;
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteNotUniqueException;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;
use Symfony\Component\HttpFoundation\Response;

/**
* Write redirect-route entity to database by using the entity-manager.
@@ -112,7 +113,7 @@ private function save(RedirectRouteInterface $entity)
*/
private function validate(RedirectRouteInterface $entity)
{
if ('' === $entity->getTarget()) {
if ('' === $entity->getTarget() && Response::HTTP_GONE !== $entity->getStatusCode()) {
throw new TargetIsEmptyException($entity);
}

30 changes: 30 additions & 0 deletions Tests/Unit/Import/Writer/WriterTest.php
Original file line number Diff line number Diff line change
@@ -13,10 +13,12 @@

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Bundle\RedirectBundle\Import\Writer\DuplicatedSourceException;
use Sulu\Bundle\RedirectBundle\Import\Writer\TargetIsEmptyException;
use Sulu\Bundle\RedirectBundle\Import\Writer\Writer;
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteManagerInterface;
use Sulu\Bundle\RedirectBundle\Manager\RedirectRouteNotUniqueException;
use Sulu\Bundle\RedirectBundle\Model\RedirectRouteInterface;
use Symfony\Component\HttpFoundation\Response;

class WriterTest extends \PHPUnit_Framework_TestCase
{
@@ -154,6 +156,34 @@ public function testWriteAlreadyExisting()
$this->writer->write($entity->reveal());
}

public function testWriteEmptyTarget()
{
$this->setExpectedException(TargetIsEmptyException::class);

$entity = $this->prophesize(RedirectRouteInterface::class);
$entity->getSource()->willReturn('/source');
$entity->getTarget()->willReturn('');
$entity->getStatusCode()->willReturn(Response::HTTP_MOVED_PERMANENTLY);

$this->redirectRouteManager->save($entity->reveal())->shouldNotBeCalled();

$this->writer->write($entity->reveal());
}

public function testWriteEmptyTargetFor410()
{
$entity = $this->prophesize(RedirectRouteInterface::class);
$entity->getSource()->willReturn('/source');
$entity->getTarget()->willReturn('');
$entity->getStatusCode()->willReturn(Response::HTTP_GONE);

$this->redirectRouteManager->save($entity->reveal())->shouldBeCalled();

$this->writer->write($entity->reveal());

$this->redirectRouteManager->save($entity->reveal())->shouldBeCalled();
}

public function testFinalize()
{
$this->writer->finalize();