Skip to content

Commit

Permalink
#48056, edit bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Jul 15, 2021
1 parent 64faaa6 commit cb5accb
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"friendsofsymfony/ckeditor-bundle": "^2.3",
"psr/log": "^1.1",
"richcongress/bundle-toolbox": "^1.0",
"sensio/framework-extra-bundle": "^5.0",
"symfony/form": "^4.0",
"symfony/http-foundation": "^4.4",
"symfony/routing": "^4.0",
Expand Down
82 changes: 81 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Infrastructure/Adapter/EntityRemoverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function testRemoveTermsVersion(): void
$this->assertCount(1, $this->entityManagerStub->getRemovedEntities());

// Skipped, waiting a correction in the test-framework
//$this->assertCount(5, $this->termsVersionRepository->findAll());
//$this->assertCount(6, $this->termsVersionRepository->findAll());
}
}
1 change: 1 addition & 0 deletions tests/Resources/Kernel/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
RichCongress\RecurrentFixturesTestBundle\RichCongressRecurrentFixturesTestBundle::class => ['all' => true],
RichId\TermsModuleBundle\Infrastructure\RichIdTermsModuleBundle::class => ['all' => true],
FOS\CKEditorBundle\FOSCKEditorBundle::class => ['all' => true],
Expand Down
211 changes: 211 additions & 0 deletions tests/UserInterface/Controller/AddTermsVersionRouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php

declare(strict_types=1);

namespace RichId\TermsModuleBundle\Tests\UserInterface\Controller;

use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestSuite\TestCase\TestCase;
use RichId\TermsModuleBundle\Domain\Entity\Terms;
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion;
use RichId\TermsModuleBundle\Domain\Event\TermsVersionCreatedEvent;
use RichId\TermsModuleBundle\Infrastructure\Repository\TermsVersionRepository;
use RichId\TermsModuleBundle\Tests\Resources\Entity\DummyUser;
use RichId\TermsModuleBundle\Tests\Resources\Fixtures\DummyUserFixtures;
use RichId\TermsModuleBundle\Tests\Resources\Stubs\EntityManagerStub;
use RichId\TermsModuleBundle\Tests\Resources\Stubs\EventDispatcherStub;
use Symfony\Component\HttpFoundation\Response;

/**
* @covers \RichId\TermsModuleBundle\UserInterface\Controller\AddTermsVersionRoute
* @TestConfig("fixtures")
*/
final class AddTermsVersionRouteTest extends TestCase
{
/** @var TermsVersionRepository */
public $termsVersionRepository;

/** @var EntityManagerStub */
public $entityManagerStub;

/** @var EventDispatcherStub */
public $eventDispatcherStub;

public function testRouteNotLogged(): void
{
$terms = $this->getReference(Terms::class, '4');

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
}

public function testRouteBadRole(): void
{
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER);
$this->authenticateUser($user);

$terms = $this->getReference(Terms::class, '4');

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_FORBIDDEN, $response->getStatusCode());
}

public function testRouteWithoutVersion(): void
{
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN);
$this->authenticateUser($user);

$terms = $this->getReference(Terms::class, '2');

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());

$content = $response->getContent() !== false ? $response->getContent() : '';
$this->assertStringContainsString('The terms has no version.', $content);
}

public function testRouteSpecificVersionNotFound(): void
{
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN);
$this->authenticateUser($user);

$terms = $this->getReference(Terms::class, '4');

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version?version=42',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode());

$content = $response->getContent() !== false ? $response->getContent() : '';
$this->assertStringContainsString('No terms version found with version 42', $content);
}

public function testRouteLastVersionIsNotActive(): void
{
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN);
$this->authenticateUser($user);

$terms = $this->getReference(Terms::class, '5');

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());

$content = $response->getContent() !== false ? $response->getContent() : '';
$this->assertStringContainsString('Cannot add new version to the terms terms-5.', $content);
}

public function testRouteSuccess(): void
{
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN);
$this->authenticateUser($user);

$terms = $this->getReference(Terms::class, '5');
$termsVersion = $this->getReference(TermsVersion::class, 'v2-terms-5');

$termsVersion->enable();
$this->getManager()->persist($termsVersion);
$this->getManager()->flush();

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_CREATED, $response->getStatusCode());

$this->assertCount(1, $this->entityManagerStub->getPersistedEntities());
$this->assertCount(1, $this->eventDispatcherStub->getEvents());

$event = $this->eventDispatcherStub->getEvents()[0];

$this->assertInstanceOf(TermsVersionCreatedEvent::class, $event);

$newTermsVersion = $event->getTermsVersion();

$this->assertInstanceOf(TermsVersion::class, $event->getTermsVersion());
$this->assertNotNull($newTermsVersion->getId());
$this->assertSame('Title Version 2', $newTermsVersion->getTitle());
$this->assertSame('Content Version 2', $newTermsVersion->getCOntent());
$this->assertSame(3, $newTermsVersion->getVersion());
$this->assertSame('terms-5', $newTermsVersion->getTerms()->getSlug());
$this->assertNull($newTermsVersion->getPublicationDate());
$this->assertFalse($newTermsVersion->isEnabled());
}

public function testRouteSuccessWithSpecificVersion(): void
{
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN);
$this->authenticateUser($user);

$terms = $this->getReference(Terms::class, '5');
$termsVersion = $this->getReference(TermsVersion::class, 'v2-terms-5');

$termsVersion->enable();
$this->getManager()->persist($termsVersion);
$this->getManager()->flush();

$response = $this->getClient()
->post(
\sprintf(
'/administration/terms/%d/new-version?version=1',
$terms->getId()
)
);

$this->assertSame(Response::HTTP_CREATED, $response->getStatusCode());

$this->assertCount(1, $this->entityManagerStub->getPersistedEntities());
$this->assertCount(1, $this->eventDispatcherStub->getEvents());

$event = $this->eventDispatcherStub->getEvents()[0];

$this->assertInstanceOf(TermsVersionCreatedEvent::class, $event);

$newTermsVersion = $event->getTermsVersion();

$this->assertInstanceOf(TermsVersion::class, $event->getTermsVersion());
$this->assertNotNull($newTermsVersion->getId());
$this->assertSame('Title Version 1', $newTermsVersion->getTitle());
$this->assertSame('Content Version 1', $newTermsVersion->getCOntent());
$this->assertSame(3, $newTermsVersion->getVersion());
$this->assertSame('terms-5', $newTermsVersion->getTerms()->getSlug());
$this->assertNull($newTermsVersion->getPublicationDate());
$this->assertFalse($newTermsVersion->isEnabled());
}
}
Loading

0 comments on commit cb5accb

Please sign in to comment.