* * 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 * @uses App\Entity\Entry * @uses App\Service\ActiveEntry */ class TimeControllerTest extends WebTestCase { /** * @test */ public function rootCanBeOpened(): void { $client = static::createClient(); $crawler = $client->request('GET', '/'); $this->assertResponseIsSuccessful(); $this->assertSelectorTextContains('h1', 'Time entries'); } /** * @test */ public function newEntryCanBeStarted(): void { $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 { $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 { $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'); } }