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