Skip to content

Commit

Permalink
Enable and disable are now POST operations.
Browse files Browse the repository at this point in the history
Fixes #16.
  • Loading branch information
manuelkiessling committed Jan 25, 2016
1 parent dfd2065 commit 71ffae2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/AppBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ testcases.edit:
testcases.disable:
path: /testcases/{testcaseId}/disable
defaults: { _controller: AppBundle:Testcases:disable }
methods: [GET]
methods: [POST]

testcases.enable:
path: /testcases/{testcaseId}/enable
defaults: { _controller: AppBundle:Testcases:enable }
methods: [GET]
methods: [POST]

testresults.show:
path: /testresults/{testresultId}
Expand Down
53 changes: 35 additions & 18 deletions src/AppBundle/Resources/views/testcases/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<table class="table testcases">
{% for testcase in testcases %}
<a name="testcase-{{ testcase.id }}" />
<tr class="testcase-entry-row">
<td class="testcase-entry-cell">
<h4 class="pull-left">
Expand Down Expand Up @@ -147,27 +148,43 @@
{% endif %}
</div>
<div class="pull-right">
<a class="btn btn-primary btn-sm"
{% if (not isDemoMode) %}
href="{{ path('testcases.edit', {'testcaseId': testcase.id}) }}"
{% else %}
data-toggle="tooltip" data-placement="top" title="Not available in demo mode"
{% endif %}>Edit</a>
<a class="btn btn-primary btn-sm"
{% if (not isDemoMode) %}
href="{{ path('testcases.edit', {'testcaseId': testcase.id}) }}"
{% else %}
data-toggle="tooltip" data-placement="top" title="Not available in demo mode"
{% endif %}>Edit</a>

{% if (testcase.enabled) %}
<a class="btn btn-default btn-sm"
{% if (not isDemoMode) %}
href="{{ path('testcases.disable', {'testcaseId': testcase.id}) }}"
{% else %}
data-toggle="tooltip" data-placement="top" title="Not available in demo mode"
{% endif %}>Disable</a>

{% if (isDemoMode) %}
<a
class="btn btn-default btn-sm"
data-toggle="tooltip"
data-placement="top"
title="Not available in demo mode">Disable</a>
{% else %}
<form method="post" action="{{ path('testcases.disable', {'testcaseId': testcase.id}) }}">
<button class="btn btn-default btn-sm" type="submit">Disable</button>
</form>
{% endif %}

{% else %}
<a class="btn btn-default btn-sm"
{% if (not isDemoMode) %}
href="{{ path('testcases.enable', {'testcaseId': testcase.id}) }}"
{% else %}
data-toggle="tooltip" data-placement="top" title="Not available in demo mode"
{% endif %}>Enable</a>

{% if (isDemoMode) %}
<a
class="btn btn-default btn-sm"
data-toggle="tooltip"
data-placement="top"
title="Not available in demo mode">Enable</a>
{% else %}
<form method="post" action="{{ path('testcases.enable', {'testcaseId': testcase.id}) }}">
<button class="btn btn-default btn-sm" type="submit">Enable</button>
</form>
{% endif %}

{% endif %}

</div>
</td>
</tr>
Expand Down
28 changes: 12 additions & 16 deletions tests/AppBundle/Controller/TestcasesControllerWebTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public function testThatEnabledTestcasesAreListedFirst()
$crawler = $client->followRedirect();

// Disable the second testcase
$link = $crawler->filter('td.testcase-entry-cell div.pull-right a.btn.btn-default.btn-sm:contains("Disable")')->eq(1)->link();
$client->click($link);
$buttonNode = $crawler->selectButton('Disable')->eq(1);
$form = $buttonNode->form();
$client->submit($form);

$crawler = $client->request('GET', '/testcases/');
$crawler = $client->followRedirect();

$this->assertSame('Demo User Testcase One', trim($crawler->filter('.testcase-entry-cell h4')->eq(0)->text()));
$this->assertSame('Third, enabled Testcase', trim($crawler->filter('.testcase-entry-cell h4')->eq(1)->text()));
Expand Down Expand Up @@ -212,28 +213,23 @@ public function testIndexDisableAndEnableTestcase()
{
$this->resetDatabase();
$client = $this->createAndActivateDemoUser();

$crawler = $client->request('GET', '/testcases/');

$link = $crawler->filter('a:contains("Disable")')->first()->link();
$buttonNode = $crawler->selectButton('Disable');
$form = $buttonNode->form();
$client->submit($form);

$client->click($link);
$crawler = $client->followRedirect();

$this->assertSame(
1,
count($crawler->filter('table.testcases span.label-default:contains("Disabled")'))
);
$this->assertSame('Disabled', trim($crawler->filter('td.testcase-entry-cell span.label')->eq(1)->text()));

$link = $crawler->filter('a:contains("Enable")')->first()->link();
$buttonNode = $crawler->selectButton('Enable');
$form = $buttonNode->form();
$client->submit($form);

$client->click($link);
$crawler = $client->followRedirect();

$this->assertSame(
1,
count($crawler->filter('table.testcases span.label-success:contains("Enabled")'))
);
$this->assertSame('Enabled', trim($crawler->filter('td.testcase-entry-cell span.label')->eq(1)->text()));
}

public function testEdit()
Expand Down

0 comments on commit 71ffae2

Please sign in to comment.