aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-02-27 15:31:57 +0100
committerGitHub <noreply@github.com>2019-02-27 15:31:57 +0100
commitfc4c1f50b41f93170bca587730193386b6c2df38 (patch)
tree994fc7fa9e96ef9f15ef311cbc103fab41746e0f
parenta86c3f1759a3c0ecbf095888789c2a08d71b5c09 (diff)
parent8c0ba953070dca22e9a06999cfe355ea01847c64 (diff)
downloadwallabag-fc4c1f50b41f93170bca587730193386b6c2df38.tar.gz
wallabag-fc4c1f50b41f93170bca587730193386b6c2df38.tar.zst
wallabag-fc4c1f50b41f93170bca587730193386b6c2df38.zip
Merge pull request #3857 from wallabag/php73
Replace continue; with break; to avoid PHP 7.3 warnings
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php10
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/FirefoxImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php2
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php68
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}