timetracking-php-web-app/tests/Functional/Controller/TimeControllerTest.php

122 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2020-10-20 21:41:19 +02:00
<?php
namespace App\Tests\Functional\Controller;
/*
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @covers App\Controller\TimeController
* @covers App\Persistence\LocalDatabase
2020-10-20 21:41:19 +02:00
* @uses App\Entity\Entry
* @uses App\Service\ActiveEntry
*/
class TimeControllerTest extends WebTestCase
{
/**
* @test
*/
public function rootCanBeOpened(): void
2020-10-20 21:41:19 +02:00
{
$client = static::createClient();
$crawler = $client->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Time entries');
}
/**
* @test
*/
public function newEntryCanBeStarted(): void
2020-10-20 21:41:19 +02:00
{
$client = static::createClient();
$client->request('GET', '/');
$client->submitForm('Start', ['title' => 'Test Entry']);
$this->assertResponseRedirects('/');
$client->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertInputValueSame('title', 'Test Entry');
}
/**
* @test
*/
public function runningEntryCanBeStopped(): void
2020-10-20 21:41:19 +02:00
{
$client = static::createClient();
$client->request('GET', '/');
$client->submitForm('Start', ['title' => 'Test Entry']);
$client->request('GET', '/');
$client->submitForm('Stop');
$this->assertResponseRedirects('/');
$client->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertInputValueSame('title', '');
$this->assertSelectorTextSame('button', 'Start');
}
/**
* @test
*/
public function noneRunningEntryCanBeStopped(): void
2020-10-20 21:41:19 +02:00
{
$client = static::createClient();
$client->request('POST', '/stop');
$this->assertResponseRedirects('/');
$client->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertInputValueSame('title', '');
$this->assertSelectorTextSame('button', 'Start');
}
/**
* @test
*/
public function previousEntriesAreShownOnIndex(): void
{
$client = static::createClient();
$client->request('GET', '/');
$client->submitForm('Start', ['title' => 'Test Entry 1']);
$client->request('GET', '/');
$client->submitForm('Stop');
$client->request('GET', '/');
$client->submitForm('Start', ['title' => 'Test Entry 2']);
$client->request('GET', '/');
$client->submitForm('Stop');
$crawler = $client->request('GET', '/');
$this->assertSelectorTextContains('article:nth-of-type(1)', 'Test Entry 2');
$this->assertSelectorTextContains('article:nth-of-type(2)', 'Test Entry 1');
}
2020-10-20 21:41:19 +02:00
}