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 16, 2021
1 parent cb5accb commit 7f25d3a
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 66 deletions.
8 changes: 4 additions & 4 deletions src/Infrastructure/Resources/views/_styles.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
--terms-module-error: #DF4551;
--terms-module-success: #A1C225;
--terms-module-form-field-border-color: #999999;
--terms-module-form-field-color: #333333;
--terms-module-form-field-placeholder: #999999;
--terms-module-form-field-color: var(--terms-module-dark);
--terms-module-form-field-border-radius: 4px;
--terms-module-button-border-radius: 4px;
Expand Down Expand Up @@ -231,7 +231,7 @@
.terms-module-form-field-input {
border-radius: var(--terms-module-form-field-border-radius);
border: 1px solid var(--terms-module-form-field-border-color);
border: 1px solid var(--terms-module-form-field-placeholder);
box-sizing: border-box;
color: var(--terms-module-form-field-color);
font-family: var(--terms-module-font-family);
Expand All @@ -250,7 +250,7 @@
.terms-module-form-field #cke_terms_version_form_content {
border: 1px solid var(--terms-module-form-field-border-color);
border: 1px solid var(--terms-module-form-field-placeholder);
border-radius: var(--terms-module-form-field-border-radius);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@
<div class="terms-module-admin-edition-add-version-container">
<div id="terms-module-admin-edition-terms-version-tags" class="terms-module-admin-edition-terms-version-tags">
{% for termsVersion in terms.versions|sort((a, b) => b.version <=> a.version) %}
<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>
{% include '@RichIdTermsModule/admin/edit/_partial/_terms_version_card.html.twig' %}
{% endfor %}

<div class="terms-version-tag terms-version-tag-next" onclick="openOtherVersion()">
...
</div>
<div class="terms-version-tag terms-version-tag-next" onclick="openOtherVersion()">...</div>
</div>

<div class="terms-module-admin-edition-version-management">
Expand All @@ -50,7 +35,7 @@

{% if currentTermsVersion.id != lastTermsVersion.id %}
<button type="button" class="terms-module-button-secondary terms-module-button-secondary-small" onclick="createNewVersion({{ currentTermsVersion.version }})" {% if not lastTermsVersion.isEnabled() %}disabled{% endif %}>
<i class="icon-plus-circle-light"></i>
<i class="icon-layer-plus-light"></i>
{{ 'terms_module.admin.edit.duplicate'|trans({}, 'terms_module') }}
</button>
{% endif %}
Expand Down
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 src/Infrastructure/Resources/views/sign/_partial/_body.html.twig
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>
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,11 @@
{% include '@RichIdTermsModule/_loader.html.twig' %}

<div class="terms-module-style">
<div class="terms-module-sign-header">
<div class="terms-module-container">
<div>{{ terms.name }}</div>
</div>
</div>
{% include '@RichIdTermsModule/sign/_partial/_header.html.twig' %}

<div class="terms-module-sign-body">
<div class="terms-module-container">
<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>
{% include '@RichIdTermsModule/sign/_partial/_body.html.twig' %}
</div>
</div>
</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>
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>
216 changes: 216 additions & 0 deletions tests/UserInterface/Controller/EditAdminRouteTest.php
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);
}
}

0 comments on commit 7f25d3a

Please sign in to comment.