diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 845762dc..9e0a9136 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -12,6 +12,8 @@ use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; | |||
12 | 12 | ||
13 | class GrabySiteConfigBuilderTest extends WallabagCoreTestCase | 13 | class GrabySiteConfigBuilderTest extends WallabagCoreTestCase |
14 | { | 14 | { |
15 | private $builder; | ||
16 | |||
15 | public function testBuildConfigExists() | 17 | public function testBuildConfigExists() |
16 | { | 18 | { |
17 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | 19 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') |
@@ -29,7 +31,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase | |||
29 | $grabyConfigBuilderMock | 31 | $grabyConfigBuilderMock |
30 | ->method('buildForHost') | 32 | ->method('buildForHost') |
31 | ->with('api.example.com') | 33 | ->with('api.example.com') |
32 | ->will($this->returnValue($grabySiteConfig)); | 34 | ->willReturn($grabySiteConfig); |
33 | 35 | ||
34 | $logger = new Logger('foo'); | 36 | $logger = new Logger('foo'); |
35 | $handler = new TestHandler(); | 37 | $handler = new TestHandler(); |
@@ -88,7 +90,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase | |||
88 | $grabyConfigBuilderMock | 90 | $grabyConfigBuilderMock |
89 | ->method('buildForHost') | 91 | ->method('buildForHost') |
90 | ->with('unknown.com') | 92 | ->with('unknown.com') |
91 | ->will($this->returnValue(new GrabySiteConfig())); | 93 | ->willReturn(new GrabySiteConfig()); |
92 | 94 | ||
93 | $logger = new Logger('foo'); | 95 | $logger = new Logger('foo'); |
94 | $handler = new TestHandler(); | 96 | $handler = new TestHandler(); |
@@ -130,6 +132,73 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase | |||
130 | $this->assertCount(1, $records, 'One log was recorded'); | 132 | $this->assertCount(1, $records, 'One log was recorded'); |
131 | } | 133 | } |
132 | 134 | ||
135 | public function testBuildConfigWithBadExtraFields() | ||
136 | { | ||
137 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | ||
138 | ->disableOriginalConstructor() | ||
139 | ->getMock(); | ||
140 | |||
141 | $grabySiteConfig = new GrabySiteConfig(); | ||
142 | $grabySiteConfig->requires_login = true; | ||
143 | $grabySiteConfig->login_uri = 'http://www.example.com/login'; | ||
144 | $grabySiteConfig->login_username_field = 'login'; | ||
145 | $grabySiteConfig->login_password_field = 'password'; | ||
146 | $grabySiteConfig->login_extra_fields = ['field']; | ||
147 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | ||
148 | |||
149 | $grabyConfigBuilderMock | ||
150 | ->method('buildForHost') | ||
151 | ->with('example.com') | ||
152 | ->willReturn($grabySiteConfig); | ||
153 | |||
154 | $logger = new Logger('foo'); | ||
155 | $handler = new TestHandler(); | ||
156 | $logger->pushHandler($handler); | ||
157 | |||
158 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
159 | ->disableOriginalConstructor() | ||
160 | ->getMock(); | ||
161 | $siteCrentialRepo->expects($this->once()) | ||
162 | ->method('findOneByHostsAndUser') | ||
163 | ->with(['example.com', '.com'], 1) | ||
164 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | ||
165 | |||
166 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
167 | ->disableOriginalConstructor() | ||
168 | ->getMock(); | ||
169 | $user->expects($this->once()) | ||
170 | ->method('getId') | ||
171 | ->willReturn(1); | ||
172 | |||
173 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
174 | |||
175 | $tokenStorage = new TokenStorage(); | ||
176 | $tokenStorage->setToken($token); | ||
177 | |||
178 | $this->builder = new GrabySiteConfigBuilder( | ||
179 | $grabyConfigBuilderMock, | ||
180 | $tokenStorage, | ||
181 | $siteCrentialRepo, | ||
182 | $logger | ||
183 | ); | ||
184 | |||
185 | $config = $this->builder->buildForHost('www.example.com'); | ||
186 | |||
187 | $this->assertSame('example.com', $config->getHost()); | ||
188 | $this->assertTrue($config->requiresLogin()); | ||
189 | $this->assertSame('http://www.example.com/login', $config->getLoginUri()); | ||
190 | $this->assertSame('login', $config->getUsernameField()); | ||
191 | $this->assertSame('password', $config->getPasswordField()); | ||
192 | $this->assertSame([], $config->getExtraFields()); | ||
193 | $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); | ||
194 | $this->assertSame('foo', $config->getUsername()); | ||
195 | $this->assertSame('bar', $config->getPassword()); | ||
196 | |||
197 | $records = $handler->getRecords(); | ||
198 | |||
199 | $this->assertCount(1, $records, 'One log was recorded'); | ||
200 | } | ||
201 | |||
133 | public function testBuildConfigUserNotDefined() | 202 | public function testBuildConfigUserNotDefined() |
134 | { | 203 | { |
135 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | 204 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') |
@@ -139,7 +208,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase | |||
139 | $grabyConfigBuilderMock | 208 | $grabyConfigBuilderMock |
140 | ->method('buildForHost') | 209 | ->method('buildForHost') |
141 | ->with('unknown.com') | 210 | ->with('unknown.com') |
142 | ->will($this->returnValue(new GrabySiteConfig())); | 211 | ->willReturn(new GrabySiteConfig()); |
143 | 212 | ||
144 | $logger = new Logger('foo'); | 213 | $logger = new Logger('foo'); |
145 | $handler = new TestHandler(); | 214 | $handler = new TestHandler(); |
@@ -210,7 +279,7 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase | |||
210 | $grabyConfigBuilderMock | 279 | $grabyConfigBuilderMock |
211 | ->method('buildForHost') | 280 | ->method('buildForHost') |
212 | ->with($host) | 281 | ->with($host) |
213 | ->will($this->returnValue($grabySiteConfig)); | 282 | ->willReturn($grabySiteConfig); |
214 | 283 | ||
215 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | 284 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') |
216 | ->disableOriginalConstructor() | 285 | ->disableOriginalConstructor() |