diff options
-rw-r--r-- | src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | 28 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | 2 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 6d4129e8..1c866f17 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | |||
@@ -54,7 +54,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
54 | 'loginUri' => $config->login_uri ?: null, | 54 | 'loginUri' => $config->login_uri ?: null, |
55 | 'usernameField' => $config->login_username_field ?: null, | 55 | 'usernameField' => $config->login_username_field ?: null, |
56 | 'passwordField' => $config->login_password_field ?: null, | 56 | 'passwordField' => $config->login_password_field ?: null, |
57 | 'extraFields' => is_array($config->login_extra_fields) ? $config->login_extra_fields : [], | 57 | 'extraFields' => $this->processExtraFields($config->login_extra_fields), |
58 | 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, | 58 | 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, |
59 | ]; | 59 | ]; |
60 | 60 | ||
@@ -65,4 +65,30 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
65 | 65 | ||
66 | return new SiteConfig($parameters); | 66 | return new SiteConfig($parameters); |
67 | } | 67 | } |
68 | |||
69 | /** | ||
70 | * Processes login_extra_fields config, transforming an '=' separated array of strings | ||
71 | * into a key/value array. | ||
72 | * | ||
73 | * @param array|mixed $extraFieldsStrings | ||
74 | * | ||
75 | * @return array | ||
76 | */ | ||
77 | protected function processExtraFields($extraFieldsStrings) | ||
78 | { | ||
79 | if (!is_array($extraFieldsStrings)) { | ||
80 | return []; | ||
81 | } | ||
82 | |||
83 | $extraFields = []; | ||
84 | foreach ($extraFieldsStrings as $extraField) { | ||
85 | if (strpos($extraField, '=') === false) { | ||
86 | continue; | ||
87 | } | ||
88 | list($fieldName, $fieldValue) = explode('=', $extraField, 2); | ||
89 | $extraFields[$fieldName] = $fieldValue; | ||
90 | } | ||
91 | |||
92 | return $extraFields; | ||
93 | } | ||
68 | } | 94 | } |
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index aee67259..8341b11f 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -24,7 +24,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
24 | $grabySiteConfig->login_uri = 'http://example.com/login'; | 24 | $grabySiteConfig->login_uri = 'http://example.com/login'; |
25 | $grabySiteConfig->login_username_field = 'login'; | 25 | $grabySiteConfig->login_username_field = 'login'; |
26 | $grabySiteConfig->login_password_field = 'password'; | 26 | $grabySiteConfig->login_password_field = 'password'; |
27 | $grabySiteConfig->login_extra_fields = ['field' => 'value']; | 27 | $grabySiteConfig->login_extra_fields = ['field=value']; |
28 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | 28 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; |
29 | 29 | ||
30 | $grabyConfigBuilderMock | 30 | $grabyConfigBuilderMock |