]>
Commit | Line | Data |
---|---|---|
7aab0ecf BD |
1 | <?php |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; | |
4 | ||
5 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; | |
6 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; | |
7 | use PHPUnit_Framework_TestCase; | |
8 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; | |
9 | ||
10 | class 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 | } |