]>
Commit | Line | Data |
---|---|---|
b8427f22 JB |
1 | <?php |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | ||
7 | class SiteCredentialControllerTest extends WallabagCoreTestCase | |
8 | { | |
9 | public function testListSiteCredential() | |
10 | { | |
11 | $this->logInAs('admin'); | |
12 | $client = $this->getClient(); | |
13 | ||
14 | $crawler = $client->request('GET', '/site-credentials/'); | |
15 | ||
16 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
17 | ||
18 | $body = $crawler->filter('body')->extract(['_text'])[0]; | |
19 | ||
20 | $this->assertContains('site_credential.description', $body); | |
21 | $this->assertContains('site_credential.list.create_new_one', $body); | |
22 | } | |
23 | ||
24 | public function testNewSiteCredential() | |
25 | { | |
26 | $this->logInAs('admin'); | |
27 | $client = $this->getClient(); | |
28 | ||
29 | $crawler = $client->request('GET', '/site-credentials/new'); | |
30 | ||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
32 | ||
33 | $body = $crawler->filter('body')->extract(['_text'])[0]; | |
34 | ||
35 | $this->assertContains('site_credential.new_site_credential', $body); | |
36 | $this->assertContains('site_credential.form.back_to_list', $body); | |
37 | ||
38 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | |
39 | ||
40 | $data = [ | |
41 | 'site_credential[host]' => 'google.io', | |
42 | 'site_credential[username]' => 'sergei', | |
43 | 'site_credential[password]' => 'microsoft', | |
44 | ]; | |
45 | ||
46 | $client->submit($form, $data); | |
47 | ||
48 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
49 | ||
50 | $crawler = $client->followRedirect(); | |
51 | ||
52 | $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); | |
53 | } | |
54 | ||
55 | /** | |
56 | * @depends testNewSiteCredential | |
57 | */ | |
58 | public function testEditSiteCredential() | |
59 | { | |
60 | $this->logInAs('admin'); | |
61 | $client = $this->getClient(); | |
62 | ||
63 | $credential = $client->getContainer() | |
64 | ->get('doctrine.orm.entity_manager') | |
65 | ->getRepository('WallabagCoreBundle:SiteCredential') | |
66 | ->findOneByHost('google.io'); | |
67 | ||
68 | $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | |
69 | ||
70 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
71 | ||
72 | $body = $crawler->filter('body')->extract(['_text'])[0]; | |
73 | ||
74 | $this->assertContains('site_credential.edit_site_credential', $body); | |
75 | $this->assertContains('site_credential.form.back_to_list', $body); | |
76 | ||
77 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | |
78 | ||
79 | $data = [ | |
80 | 'site_credential[host]' => 'google.io', | |
81 | 'site_credential[username]' => 'larry', | |
82 | 'site_credential[password]' => 'microsoft', | |
83 | ]; | |
84 | ||
85 | $client->submit($form, $data); | |
86 | ||
87 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
88 | ||
89 | $crawler = $client->followRedirect(); | |
90 | ||
91 | $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); | |
92 | $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value')); | |
93 | } | |
94 | ||
95 | /** | |
96 | * @depends testNewSiteCredential | |
97 | */ | |
98 | public function testEditFromADifferentUserSiteCredential() | |
99 | { | |
100 | $this->logInAs('bob'); | |
101 | $client = $this->getClient(); | |
102 | ||
103 | $credential = $client->getContainer() | |
104 | ->get('doctrine.orm.entity_manager') | |
105 | ->getRepository('WallabagCoreBundle:SiteCredential') | |
106 | ->findOneByHost('google.io'); | |
107 | ||
108 | $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | |
109 | ||
110 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
111 | } | |
112 | ||
113 | /** | |
114 | * @depends testNewSiteCredential | |
115 | */ | |
116 | public function testDeleteSiteCredential() | |
117 | { | |
118 | $this->logInAs('admin'); | |
119 | $client = $this->getClient(); | |
120 | ||
121 | $credential = $client->getContainer() | |
122 | ->get('doctrine.orm.entity_manager') | |
123 | ->getRepository('WallabagCoreBundle:SiteCredential') | |
124 | ->findOneByHost('google.io'); | |
125 | ||
126 | $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | |
127 | ||
128 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
129 | ||
130 | $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form(); | |
131 | ||
132 | $client->submit($deleteForm, []); | |
133 | ||
134 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
135 | ||
136 | $crawler = $client->followRedirect(); | |
137 | ||
138 | $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); | |
139 | } | |
140 | } |