diff options
7 files changed, 78 insertions, 10 deletions
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 702c7f7a..37d0640a 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | |||
@@ -108,7 +108,7 @@ class EntryFilterType extends AbstractType | |||
108 | ->add('httpStatus', TextFilterType::class, [ | 108 | ->add('httpStatus', TextFilterType::class, [ |
109 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | 109 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { |
110 | $value = $values['value']; | 110 | $value = $values['value']; |
111 | if (false === array_key_exists($value, Response::$statusTexts)) { | 111 | if (false === \array_key_exists($value, Response::$statusTexts)) { |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | 114 | ||
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 804bc6cd..3987e80f 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php | |||
@@ -77,7 +77,7 @@ abstract class BrowserImport extends AbstractImport | |||
77 | */ | 77 | */ |
78 | public function parseEntry(array $importedEntry) | 78 | public function parseEntry(array $importedEntry) |
79 | { | 79 | { |
80 | if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && \is_array(reset($importedEntry))) { | 80 | if ((!\array_key_exists('guid', $importedEntry) || (!\array_key_exists('id', $importedEntry))) && \is_array(reset($importedEntry))) { |
81 | if ($this->producer) { | 81 | if ($this->producer) { |
82 | $this->parseEntriesForProducer($importedEntry); | 82 | $this->parseEntriesForProducer($importedEntry); |
83 | 83 | ||
@@ -89,7 +89,7 @@ abstract class BrowserImport extends AbstractImport | |||
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | 91 | ||
92 | if (array_key_exists('children', $importedEntry)) { | 92 | if (\array_key_exists('children', $importedEntry)) { |
93 | if ($this->producer) { | 93 | if ($this->producer) { |
94 | $this->parseEntriesForProducer($importedEntry['children']); | 94 | $this->parseEntriesForProducer($importedEntry['children']); |
95 | 95 | ||
@@ -101,11 +101,11 @@ abstract class BrowserImport extends AbstractImport | |||
101 | return; | 101 | return; |
102 | } | 102 | } |
103 | 103 | ||
104 | if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { | 104 | if (!\array_key_exists('uri', $importedEntry) && !\array_key_exists('url', $importedEntry)) { |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; | 108 | $url = \array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; |
109 | 109 | ||
110 | $existingEntry = $this->em | 110 | $existingEntry = $this->em |
111 | ->getRepository('WallabagCoreBundle:Entry') | 111 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -126,7 +126,7 @@ abstract class BrowserImport extends AbstractImport | |||
126 | // update entry with content (in case fetching failed, the given entry will be return) | 126 | // update entry with content (in case fetching failed, the given entry will be return) |
127 | $this->fetchContent($entry, $data['url'], $data); | 127 | $this->fetchContent($entry, $data['url'], $data); |
128 | 128 | ||
129 | if (array_key_exists('tags', $data)) { | 129 | if (\array_key_exists('tags', $data)) { |
130 | $this->tagsAssigner->assignTagsToEntry( | 130 | $this->tagsAssigner->assignTagsToEntry( |
131 | $entry, | 131 | $entry, |
132 | $data['tags'] | 132 | $data['tags'] |
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index eccee698..4ae82ade 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php | |||
@@ -57,7 +57,7 @@ class ChromeImport extends BrowserImport | |||
57 | 'created_at' => substr($entry['date_added'], 0, 10), | 57 | 'created_at' => substr($entry['date_added'], 0, 10), |
58 | ]; | 58 | ]; |
59 | 59 | ||
60 | if (array_key_exists('tags', $entry) && '' !== $entry['tags']) { | 60 | if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) { |
61 | $data['tags'] = $entry['tags']; | 61 | $data['tags'] = $entry['tags']; |
62 | } | 62 | } |
63 | 63 | ||
diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index 8999e3f3..b3558f21 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php | |||
@@ -57,7 +57,7 @@ class FirefoxImport extends BrowserImport | |||
57 | 'created_at' => substr($entry['dateAdded'], 0, 10), | 57 | 'created_at' => substr($entry['dateAdded'], 0, 10), |
58 | ]; | 58 | ]; |
59 | 59 | ||
60 | if (array_key_exists('tags', $entry) && '' !== $entry['tags']) { | 60 | if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) { |
61 | $data['tags'] = $entry['tags']; | 61 | $data['tags'] = $entry['tags']; |
62 | } | 62 | } |
63 | 63 | ||
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php index c3a142b9..75a28fbf 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagImport.php +++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php | |||
@@ -122,7 +122,7 @@ abstract class WallabagImport extends AbstractImport | |||
122 | // update entry with content (in case fetching failed, the given entry will be return) | 122 | // update entry with content (in case fetching failed, the given entry will be return) |
123 | $this->fetchContent($entry, $data['url'], $data); | 123 | $this->fetchContent($entry, $data['url'], $data); |
124 | 124 | ||
125 | if (array_key_exists('tags', $data)) { | 125 | if (\array_key_exists('tags', $data)) { |
126 | $this->tagsAssigner->assignTagsToEntry( | 126 | $this->tagsAssigner->assignTagsToEntry( |
127 | $entry, | 127 | $entry, |
128 | $data['tags'], | 128 | $data['tags'], |
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index b9bb525a..e0562611 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php | |||
@@ -61,7 +61,7 @@ class WallabagV1Import extends WallabagImport | |||
61 | $data['html'] = $this->fetchingErrorMessage; | 61 | $data['html'] = $this->fetchingErrorMessage; |
62 | } | 62 | } |
63 | 63 | ||
64 | if (array_key_exists('tags', $entry) && '' !== $entry['tags']) { | 64 | if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) { |
65 | $data['tags'] = $entry['tags']; | 65 | $data['tags'] = $entry['tags']; |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 1173fc3d..7beccd30 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -134,4 +134,72 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
134 | 134 | ||
135 | $this->assertCount(1, $records, 'One log was recorded'); | 135 | $this->assertCount(1, $records, 'One log was recorded'); |
136 | } | 136 | } |
137 | |||
138 | public function testBuildConfigWithBadExtraFields() | ||
139 | { | ||
140 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
141 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | ||
142 | ->disableOriginalConstructor() | ||
143 | ->getMock(); | ||
144 | |||
145 | $grabySiteConfig = new GrabySiteConfig(); | ||
146 | $grabySiteConfig->requires_login = true; | ||
147 | $grabySiteConfig->login_uri = 'http://www.example.com/login'; | ||
148 | $grabySiteConfig->login_username_field = 'login'; | ||
149 | $grabySiteConfig->login_password_field = 'password'; | ||
150 | $grabySiteConfig->login_extra_fields = ['field']; | ||
151 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | ||
152 | |||
153 | $grabyConfigBuilderMock | ||
154 | ->method('buildForHost') | ||
155 | ->with('example.com') | ||
156 | ->will($this->returnValue($grabySiteConfig)); | ||
157 | |||
158 | $logger = new Logger('foo'); | ||
159 | $handler = new TestHandler(); | ||
160 | $logger->pushHandler($handler); | ||
161 | |||
162 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
163 | ->disableOriginalConstructor() | ||
164 | ->getMock(); | ||
165 | $siteCrentialRepo->expects($this->once()) | ||
166 | ->method('findOneByHostAndUser') | ||
167 | ->with('example.com', 1) | ||
168 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | ||
169 | |||
170 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
171 | ->disableOriginalConstructor() | ||
172 | ->getMock(); | ||
173 | $user->expects($this->once()) | ||
174 | ->method('getId') | ||
175 | ->willReturn(1); | ||
176 | |||
177 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
178 | |||
179 | $tokenStorage = new TokenStorage(); | ||
180 | $tokenStorage->setToken($token); | ||
181 | |||
182 | $this->builder = new GrabySiteConfigBuilder( | ||
183 | $grabyConfigBuilderMock, | ||
184 | $tokenStorage, | ||
185 | $siteCrentialRepo, | ||
186 | $logger | ||
187 | ); | ||
188 | |||
189 | $config = $this->builder->buildForHost('www.example.com'); | ||
190 | |||
191 | $this->assertSame('example.com', $config->getHost()); | ||
192 | $this->assertTrue($config->requiresLogin()); | ||
193 | $this->assertSame('http://www.example.com/login', $config->getLoginUri()); | ||
194 | $this->assertSame('login', $config->getUsernameField()); | ||
195 | $this->assertSame('password', $config->getPasswordField()); | ||
196 | $this->assertSame([], $config->getExtraFields()); | ||
197 | $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); | ||
198 | $this->assertSame('foo', $config->getUsername()); | ||
199 | $this->assertSame('bar', $config->getPassword()); | ||
200 | |||
201 | $records = $handler->getRecords(); | ||
202 | |||
203 | $this->assertCount(1, $records, 'One log was recorded'); | ||
204 | } | ||
137 | } | 205 | } |