]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
Use a form type for entry
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / ConfigControllerTest.php
CommitLineData
4d85d7e9
J
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagTestCase;
6
7class ConfigControllerTest extends WallabagTestCase
8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $client->request('GET', '/new');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
19 public function testIndex()
20 {
21 $this->logInAs('admin');
22 $client = $this->getClient();
23
24 $crawler = $client->request('GET', '/config');
25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27
28 $this->assertCount(1, $crawler->filter('input[type=number]'));
29 $this->assertCount(1, $crawler->filter('button[type=submit]'));
30 }
31
32 public function testUpdate()
33 {
34 $this->logInAs('admin');
35 $client = $this->getClient();
36
37 $crawler = $client->request('GET', '/config');
38
39 $this->assertEquals(200, $client->getResponse()->getStatusCode());
40
41 $form = $crawler->filter('button[type=submit]')->form();
42
43 $data = array(
44 'config[theme]' => 'baggy',
45 'config[items_per_page]' => '30',
46 'config[language]' => 'fr_FR',
47 );
48
49 $client->submit($form, $data);
50
51 $this->assertEquals(302, $client->getResponse()->getStatusCode());
52
53 $crawler = $client->followRedirect();
54
55 $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text')));
56 $this->assertContains('Config saved', $alert[0]);
57 }
58
59 public function dataForUpdateFailed()
60 {
61 return array(
62 array(array(
63 'config[theme]' => 'baggy',
64 'config[items_per_page]' => '',
65 'config[language]' => 'fr_FR',
66 )),
67 array(array(
68 'config[theme]' => 'baggy',
69 'config[items_per_page]' => '12',
70 'config[language]' => '',
71 )),
72 );
73 }
74
75 /**
76 * @dataProvider dataForUpdateFailed
77 */
78 public function testUpdateFailed($data)
79 {
80 $this->logInAs('admin');
81 $client = $this->getClient();
82
83 $crawler = $client->request('GET', '/config');
84
85 $this->assertEquals(200, $client->getResponse()->getStatusCode());
86
87 $form = $crawler->filter('button[type=submit]')->form();
88
89 $crawler = $client->submit($form, $data);
90
91 $this->assertEquals(200, $client->getResponse()->getStatusCode());
92
93 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
94 $this->assertContains('This value should not be blank', $alert[0]);
95 }
96}