aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorBertrand Dunogier <bertrand.dunogier@gmail.com>2016-09-29 10:14:43 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-11-22 14:01:46 +0100
commit7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7 (patch)
treeb3e4f7875944f79e6f4fcf16fd5d1230a1467621 /tests/Wallabag
parentbb28368f6953e07dbe6747d7c1eacf1abe35817e (diff)
downloadwallabag-7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7.tar.gz
wallabag-7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7.tar.zst
wallabag-7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7.zip
Added authentication for restricted access articles
Fix #438. Thank you so much @bdunogier
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
new file mode 100644
index 00000000..aee67259
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
@@ -0,0 +1,85 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator;
4
5use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
6use Graby\SiteConfig\SiteConfig as GrabySiteConfig;
7use PHPUnit_Framework_TestCase;
8use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder;
9
10class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
11{
12 /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */
13 protected $builder;
14
15 public function testBuildConfigExists()
16 {
17 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
18 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
19 ->disableOriginalConstructor()
20 ->getMock();
21
22 $grabySiteConfig = new GrabySiteConfig();
23 $grabySiteConfig->requires_login = true;
24 $grabySiteConfig->login_uri = 'http://example.com/login';
25 $grabySiteConfig->login_username_field = 'login';
26 $grabySiteConfig->login_password_field = 'password';
27 $grabySiteConfig->login_extra_fields = ['field' => 'value'];
28 $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
29
30 $grabyConfigBuilderMock
31 ->method('buildForHost')
32 ->with('example.com')
33 ->will($this->returnValue($grabySiteConfig));
34
35 $this->builder = new GrabySiteConfigBuilder(
36 $grabyConfigBuilderMock,
37 ['example.com' => ['username' => 'foo', 'password' => 'bar']]
38 );
39
40 $config = $this->builder->buildForHost('example.com');
41
42 self::assertEquals(
43 new SiteConfig([
44 'host' => 'example.com',
45 'requiresLogin' => true,
46 'loginUri' => 'http://example.com/login',
47 'usernameField' => 'login',
48 'passwordField' => 'password',
49 'extraFields' => ['field' => 'value'],
50 'notLoggedInXpath' => '//div[@class="need-login"]',
51 'username' => 'foo',
52 'password' => 'bar',
53 ]),
54 $config
55 );
56 }
57
58 public function testBuildConfigDoesntExist()
59 {
60 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
61 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
62 ->disableOriginalConstructor()
63 ->getMock();
64
65 $grabyConfigBuilderMock
66 ->method('buildForHost')
67 ->with('unknown.com')
68 ->will($this->returnValue(new GrabySiteConfig()));
69
70 $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []);
71
72 $config = $this->builder->buildForHost('unknown.com');
73
74 self::assertEquals(
75 new SiteConfig([
76 'host' => 'unknown.com',
77 'requiresLogin' => false,
78 'username' => null,
79 'password' => null,
80 'extraFields' => [],
81 ]),
82 $config
83 );
84 }
85}