diff options
Diffstat (limited to 'tests/Wallabag')
-rw-r--r-- | tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 1173fc3d..7beccd30 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -134,4 +134,72 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
134 | 134 | ||
135 | $this->assertCount(1, $records, 'One log was recorded'); | 135 | $this->assertCount(1, $records, 'One log was recorded'); |
136 | } | 136 | } |
137 | |||
138 | public function testBuildConfigWithBadExtraFields() | ||
139 | { | ||
140 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
141 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | ||
142 | ->disableOriginalConstructor() | ||
143 | ->getMock(); | ||
144 | |||
145 | $grabySiteConfig = new GrabySiteConfig(); | ||
146 | $grabySiteConfig->requires_login = true; | ||
147 | $grabySiteConfig->login_uri = 'http://www.example.com/login'; | ||
148 | $grabySiteConfig->login_username_field = 'login'; | ||
149 | $grabySiteConfig->login_password_field = 'password'; | ||
150 | $grabySiteConfig->login_extra_fields = ['field']; | ||
151 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | ||
152 | |||
153 | $grabyConfigBuilderMock | ||
154 | ->method('buildForHost') | ||
155 | ->with('example.com') | ||
156 | ->will($this->returnValue($grabySiteConfig)); | ||
157 | |||
158 | $logger = new Logger('foo'); | ||
159 | $handler = new TestHandler(); | ||
160 | $logger->pushHandler($handler); | ||
161 | |||
162 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
163 | ->disableOriginalConstructor() | ||
164 | ->getMock(); | ||
165 | $siteCrentialRepo->expects($this->once()) | ||
166 | ->method('findOneByHostAndUser') | ||
167 | ->with('example.com', 1) | ||
168 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | ||
169 | |||
170 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
171 | ->disableOriginalConstructor() | ||
172 | ->getMock(); | ||
173 | $user->expects($this->once()) | ||
174 | ->method('getId') | ||
175 | ->willReturn(1); | ||
176 | |||
177 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
178 | |||
179 | $tokenStorage = new TokenStorage(); | ||
180 | $tokenStorage->setToken($token); | ||
181 | |||
182 | $this->builder = new GrabySiteConfigBuilder( | ||
183 | $grabyConfigBuilderMock, | ||
184 | $tokenStorage, | ||
185 | $siteCrentialRepo, | ||
186 | $logger | ||
187 | ); | ||
188 | |||
189 | $config = $this->builder->buildForHost('www.example.com'); | ||
190 | |||
191 | $this->assertSame('example.com', $config->getHost()); | ||
192 | $this->assertTrue($config->requiresLogin()); | ||
193 | $this->assertSame('http://www.example.com/login', $config->getLoginUri()); | ||
194 | $this->assertSame('login', $config->getUsernameField()); | ||
195 | $this->assertSame('password', $config->getPasswordField()); | ||
196 | $this->assertSame([], $config->getExtraFields()); | ||
197 | $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); | ||
198 | $this->assertSame('foo', $config->getUsername()); | ||
199 | $this->assertSame('bar', $config->getPassword()); | ||
200 | |||
201 | $records = $handler->getRecords(); | ||
202 | |||
203 | $this->assertCount(1, $records, 'One log was recorded'); | ||
204 | } | ||
137 | } | 205 | } |