3 namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator
;
5 use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig
;
6 use Graby\SiteConfig\SiteConfig
as GrabySiteConfig
;
7 use PHPUnit_Framework_TestCase
;
8 use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder
;
10 class GrabySiteConfigBuilderTest
extends PHPUnit_Framework_TestCase
12 /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */
15 public function testBuildConfigExists()
17 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
18 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
19 ->disableOriginalConstructor()
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"]';
30 $grabyConfigBuilderMock
31 ->method('buildForHost')
33 ->will($this->returnValue($grabySiteConfig));
35 $this->builder
= new GrabySiteConfigBuilder(
36 $grabyConfigBuilderMock,
37 ['example.com' => ['username' => 'foo', 'password' => 'bar']]
40 $config = $this->builder
->buildForHost('example.com');
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"]',
58 public function testBuildConfigDoesntExist()
60 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
61 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
62 ->disableOriginalConstructor()
65 $grabyConfigBuilderMock
66 ->method('buildForHost')
68 ->will($this->returnValue(new GrabySiteConfig()));
70 $this->builder
= new GrabySiteConfigBuilder($grabyConfigBuilderMock, []);
72 $config = $this->builder
->buildForHost('unknown.com');
76 'host' => 'unknown.com',
77 'requiresLogin' => false,