From 7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7 Mon Sep 17 00:00:00 2001 From: Bertrand Dunogier Date: Thu, 29 Sep 2016 10:14:43 +0200 Subject: Added authentication for restricted access articles Fix #438. Thank you so much @bdunogier --- .../GrabySiteConfigBuilderTest.php | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php (limited to 'tests') 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 @@ +getMockBuilder('\Graby\SiteConfig\ConfigBuilder') + ->disableOriginalConstructor() + ->getMock(); + + $grabySiteConfig = new GrabySiteConfig(); + $grabySiteConfig->requires_login = true; + $grabySiteConfig->login_uri = 'http://example.com/login'; + $grabySiteConfig->login_username_field = 'login'; + $grabySiteConfig->login_password_field = 'password'; + $grabySiteConfig->login_extra_fields = ['field' => 'value']; + $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; + + $grabyConfigBuilderMock + ->method('buildForHost') + ->with('example.com') + ->will($this->returnValue($grabySiteConfig)); + + $this->builder = new GrabySiteConfigBuilder( + $grabyConfigBuilderMock, + ['example.com' => ['username' => 'foo', 'password' => 'bar']] + ); + + $config = $this->builder->buildForHost('example.com'); + + self::assertEquals( + new SiteConfig([ + 'host' => 'example.com', + 'requiresLogin' => true, + 'loginUri' => 'http://example.com/login', + 'usernameField' => 'login', + 'passwordField' => 'password', + 'extraFields' => ['field' => 'value'], + 'notLoggedInXpath' => '//div[@class="need-login"]', + 'username' => 'foo', + 'password' => 'bar', + ]), + $config + ); + } + + public function testBuildConfigDoesntExist() + { + /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ + $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') + ->disableOriginalConstructor() + ->getMock(); + + $grabyConfigBuilderMock + ->method('buildForHost') + ->with('unknown.com') + ->will($this->returnValue(new GrabySiteConfig())); + + $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []); + + $config = $this->builder->buildForHost('unknown.com'); + + self::assertEquals( + new SiteConfig([ + 'host' => 'unknown.com', + 'requiresLogin' => false, + 'username' => null, + 'password' => null, + 'extraFields' => [], + ]), + $config + ); + } +} -- cgit v1.2.3