generated from rich-id/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dumazeau
committed
Jul 16, 2021
1 parent
cb5accb
commit 7f25d3a
Showing
7 changed files
with
283 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Infrastructure/Resources/views/admin/edit/_partial/_terms_version_card.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<a class="terms-version-tag {% if lastEnabledVersion != false and lastEnabledVersion.id == termsVersion.id %}enabled{% endif %} {% if currentTermsVersion.id == termsVersion.id %}current{% endif %}" | ||
{% if currentTermsVersion.id != termsVersion.id and termsVersion.id != lastTermsVersion.id %}href="{{ path('module_terms_admin_edition', {'terms': terms.id, 'version': termsVersion.version}) }}"{% endif %} | ||
{% if currentTermsVersion.id != termsVersion.id and termsVersion.id == lastTermsVersion.id %}href="{{ path('module_terms_admin_edition', {'terms': terms.id}) }}"{% endif %} | ||
> | ||
{% if termsVersion.id == lastTermsVersion.id and not termsVersion.isEnabled() %} | ||
<i class="icon-sync-alt-regular"></i> | ||
{% elseif lastEnabledVersion != false and lastEnabledVersion.id == termsVersion.id %} | ||
<i class="icon-lock"></i> | ||
{% else %} | ||
<i class="icon-versions"></i> | ||
{% endif %} | ||
|
||
{{ 'terms_module.admin.edit.version'|trans({'%version%': termsVersion.version}, 'terms_module') }} | ||
</a> |
39 changes: 39 additions & 0 deletions
39
src/Infrastructure/Resources/views/sign/_partial/_body.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<div class="terms-module-sign-content"> | ||
{% if hasSignTerms(terms.slug, subject.termsSubjectType, subject.termsSubjectIdentifier) == constant('RichId\\TermsModuleBundle\\Domain\\UseCase\\HasSignTerms::HAS_SIGN_OLD_VERSION') %} | ||
<div class="terms-module-ribon">{{ 'terms_module.sign.new_version'|trans({}, 'terms_module') }}</div> | ||
{% endif %} | ||
|
||
<div class="terms-module-sign-content-title">{{ lastTermsVersion.title }}</div> | ||
<div>{{ lastTermsVersion.content|raw }}</div> | ||
|
||
<form id="terms-module-sign-form" | ||
class="terms-module-center terms-module-sign-actions" | ||
method="post" | ||
action="{{ path('module_terms_sign', {'termsSlug': terms.slug, 'type': subject.termsSubjectType, 'identifier': subject.termsSubjectIdentifier}) }}" | ||
> | ||
<input type="hidden" name="accepted" id="terms-module-sign-accepted"> | ||
|
||
<button type="button" class="terms-module-button-secondary terms-module-action terms-module-action-space terms-module-open-loader" onclick="refuseTerms()">{{ 'terms_module.sign.refuse'|trans({}, 'terms_module') }}</button> | ||
<button type="button" class="terms-module-button-primary terms-module-action terms-module-action-space terms-module-open-loader" onclick="acceptTerms()">{{ 'terms_module.sign.accept'|trans({}, 'terms_module') }}</button> | ||
<a class="terms-module-link terms-module-action-space terms-module-open-loader" onclick="ignoreTerms()">{{ 'terms_module.sign.prefer_answer_later'|trans({}, 'terms_module') }}</a> | ||
</form> | ||
</div> | ||
|
||
<script> | ||
document.addEventListener("DOMContentLoaded", function () { | ||
window.refuseTerms = function () { | ||
document.getElementById('terms-module-sign-accepted').value = 0; | ||
document.getElementById('terms-module-sign-form').submit(); | ||
} | ||
window.acceptTerms = function () { | ||
document.getElementById('terms-module-sign-accepted').value = 1; | ||
document.getElementById('terms-module-sign-form').submit(); | ||
} | ||
window.ignoreTerms = function () { | ||
document.getElementById('terms-module-sign-accepted').value = ''; | ||
document.getElementById('terms-module-sign-form').submit(); | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/Infrastructure/Resources/views/sign/_partial/_header.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="terms-module-sign-header"> | ||
<div class="terms-module-container"> | ||
<div>{{ terms.name }}</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
<?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\Tests\Resources\Entity\DummyUser; | ||
use RichId\TermsModuleBundle\Tests\Resources\Fixtures\DummyUserFixtures; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\UserInterface\Controller\EditAdminRoute | ||
* @TestConfig("fixtures") | ||
*/ | ||
final class EditAdminRouteTest extends TestCase | ||
{ | ||
public function testRouteNotLogged(): void | ||
{ | ||
$terms = $this->getReference(Terms::class, '1'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d', | ||
$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, '1'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d', | ||
$terms->getId() | ||
) | ||
); | ||
|
||
$this->assertSame(Response::HTTP_FORBIDDEN, $response->getStatusCode()); | ||
} | ||
|
||
public function testRouteSpecificVersionNotFound(): void | ||
{ | ||
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN); | ||
$this->authenticateUser($user); | ||
|
||
$terms = $this->getReference(Terms::class, '1'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d?version=999', | ||
$terms->getId() | ||
) | ||
); | ||
|
||
$this->assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode()); | ||
|
||
$content = $response->getContent() !== false ? $response->getContent() : ''; | ||
$this->assertStringContainsString('No terms version found with version 999', $content); | ||
} | ||
|
||
public function testRouteTermsWithoutVersion(): void | ||
{ | ||
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN); | ||
$this->authenticateUser($user); | ||
|
||
$terms = $this->getReference(Terms::class, '2'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d', | ||
$terms->getId() | ||
) | ||
); | ||
|
||
$this->assertSame(Response::HTTP_OK, $response->getStatusCode()); | ||
$content = $response->getContent() !== false ? $response->getContent() : ''; | ||
|
||
$this->assertStringContainsString('Terms management', $content); | ||
$this->assertStringContainsString('Terms 2', $content); | ||
$this->assertStringContainsString('V. 1', $content); | ||
|
||
$this->assertStringNotContainsString('V. 2', $content); | ||
$this->assertStringNotContainsString('Duplicate', $content); | ||
$this->assertStringNotContainsString('New version', $content); | ||
$this->assertStringNotContainsString('icon-trash', $content); | ||
$this->assertStringNotContainsString('Active', $content); | ||
} | ||
|
||
public function testRouteTermsWithMultipleVersionLastVersionNotActive(): void | ||
{ | ||
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN); | ||
$this->authenticateUser($user); | ||
|
||
$terms = $this->getReference(Terms::class, '1'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d', | ||
$terms->getId() | ||
) | ||
); | ||
|
||
$this->assertSame(Response::HTTP_OK, $response->getStatusCode()); | ||
$content = $response->getContent() !== false ? $response->getContent() : ''; | ||
|
||
$this->assertStringContainsString('Terms management', $content); | ||
$this->assertStringContainsString('Terms 1', $content); | ||
$this->assertStringContainsString('V. 1', $content); | ||
$this->assertStringContainsString('V. 2', $content); | ||
$this->assertStringContainsString('V. 3', $content); | ||
$this->assertStringContainsString('V. 4', $content); | ||
$this->assertStringContainsString('icon-trash', $content); | ||
$this->assertStringContainsString('Active', $content); | ||
|
||
$this->assertStringContainsString('Title Version 4', $content); | ||
$this->assertStringContainsString('Content Version 4', $content); | ||
|
||
$this->assertStringNotContainsString('V. 5', $content); | ||
$this->assertStringNotContainsString('Duplicate', $content); | ||
$this->assertStringNotContainsString('New version', $content); | ||
} | ||
|
||
public function testRouteTermsLastVersionActive(): void | ||
{ | ||
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN); | ||
$this->authenticateUser($user); | ||
|
||
$termVersion = $this->getReference(TermsVersion::class, 'v2-terms-5'); | ||
$termVersion->enable(); | ||
|
||
$this->getManager()->persist($termVersion); | ||
$this->getManager()->flush(); | ||
|
||
$terms = $this->getReference(Terms::class, '5'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d', | ||
$terms->getId() | ||
) | ||
); | ||
|
||
$this->assertSame(Response::HTTP_OK, $response->getStatusCode()); | ||
$content = $response->getContent() !== false ? $response->getContent() : ''; | ||
|
||
$this->assertStringContainsString('Terms management', $content); | ||
$this->assertStringContainsString('Terms 5', $content); | ||
$this->assertStringContainsString('V. 1', $content); | ||
$this->assertStringContainsString('V. 2', $content); | ||
$this->assertStringContainsString('New version', $content); | ||
|
||
$this->assertStringContainsString('Title Version 2', $content); | ||
$this->assertStringContainsString('Content Version 2', $content); | ||
|
||
$this->assertStringNotContainsString('V. 3', $content); | ||
$this->assertStringNotContainsString('Duplicate', $content); | ||
$this->assertStringNotContainsString('icon-trash', $content); | ||
$this->assertStringNotContainsString('Active', $content); | ||
} | ||
|
||
public function testRouteTermsLastVersionActiveAndSpecificVersion(): void | ||
{ | ||
$user = $this->getReference(DummyUser::class, DummyUserFixtures::USER_ADMIN); | ||
$this->authenticateUser($user); | ||
|
||
$termVersion = $this->getReference(TermsVersion::class, 'v2-terms-5'); | ||
$termVersion->enable(); | ||
|
||
$this->getManager()->persist($termVersion); | ||
$this->getManager()->flush(); | ||
|
||
$terms = $this->getReference(Terms::class, '5'); | ||
|
||
$response = $this->getClient() | ||
->get( | ||
\sprintf( | ||
'/administration/terms/%d?version=1', | ||
$terms->getId() | ||
) | ||
); | ||
|
||
$this->assertSame(Response::HTTP_OK, $response->getStatusCode()); | ||
$content = $response->getContent() !== false ? $response->getContent() : ''; | ||
|
||
$this->assertStringContainsString('Terms management', $content); | ||
$this->assertStringContainsString('Terms 5', $content); | ||
$this->assertStringContainsString('V. 1', $content); | ||
$this->assertStringContainsString('V. 2', $content); | ||
$this->assertStringContainsString('Duplicate', $content); | ||
|
||
$this->assertStringContainsString('Title Version 1', $content); | ||
$this->assertStringContainsString('Content Version 1', $content); | ||
|
||
$this->assertStringNotContainsString('V. 3', $content); | ||
$this->assertStringNotContainsString('New version', $content); | ||
$this->assertStringNotContainsString('icon-trash', $content); | ||
$this->assertStringNotContainsString('Active', $content); | ||
} | ||
} |