aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-02-27 14:59:50 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-02-27 15:01:03 +0100
commit8c0ba953070dca22e9a06999cfe355ea01847c64 (patch)
tree994fc7fa9e96ef9f15ef311cbc103fab41746e0f /tests/Wallabag/CoreBundle
parentea925bb112ab99efbb29d8e7113e80357a70bd18 (diff)
downloadwallabag-8c0ba953070dca22e9a06999cfe355ea01847c64.tar.gz
wallabag-8c0ba953070dca22e9a06999cfe355ea01847c64.tar.zst
wallabag-8c0ba953070dca22e9a06999cfe355ea01847c64.zip
Adding more tests
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php68
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}