]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #3857 from wallabag/php73
authorJérémy Benoist <j0k3r@users.noreply.github.com>
Wed, 27 Feb 2019 14:31:57 +0000 (15:31 +0100)
committerGitHub <noreply@github.com>
Wed, 27 Feb 2019 14:31:57 +0000 (15:31 +0100)
Replace continue; with break; to avoid PHP 7.3 warnings

src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
src/Wallabag/ImportBundle/Import/BrowserImport.php
src/Wallabag/ImportBundle/Import/ChromeImport.php
src/Wallabag/ImportBundle/Import/FirefoxImport.php
src/Wallabag/ImportBundle/Import/WallabagImport.php
src/Wallabag/ImportBundle/Import/WallabagV1Import.php
tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php

index 702c7f7aa03d196939d8f51cd747b803794e34fa..37d0640a63e6a36b94ec9e5034db9235e69fe6d0 100644 (file)
@@ -108,7 +108,7 @@ class EntryFilterType extends AbstractType
             ->add('httpStatus', TextFilterType::class, [
                 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                     $value = $values['value'];
-                    if (false === array_key_exists($value, Response::$statusTexts)) {
+                    if (false === \array_key_exists($value, Response::$statusTexts)) {
                         return;
                     }
 
index 804bc6cd06b4c89b3b8aff84f56f158c7711d960..3987e80f0722856df2067fcbcc380554aea6eaf5 100644 (file)
@@ -77,7 +77,7 @@ abstract class BrowserImport extends AbstractImport
      */
     public function parseEntry(array $importedEntry)
     {
-        if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && \is_array(reset($importedEntry))) {
+        if ((!\array_key_exists('guid', $importedEntry) || (!\array_key_exists('id', $importedEntry))) && \is_array(reset($importedEntry))) {
             if ($this->producer) {
                 $this->parseEntriesForProducer($importedEntry);
 
@@ -89,7 +89,7 @@ abstract class BrowserImport extends AbstractImport
             return;
         }
 
-        if (array_key_exists('children', $importedEntry)) {
+        if (\array_key_exists('children', $importedEntry)) {
             if ($this->producer) {
                 $this->parseEntriesForProducer($importedEntry['children']);
 
@@ -101,11 +101,11 @@ abstract class BrowserImport extends AbstractImport
             return;
         }
 
-        if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
+        if (!\array_key_exists('uri', $importedEntry) && !\array_key_exists('url', $importedEntry)) {
             return;
         }
 
-        $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
+        $url = \array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
 
         $existingEntry = $this->em
             ->getRepository('WallabagCoreBundle:Entry')
@@ -126,7 +126,7 @@ abstract class BrowserImport extends AbstractImport
         // update entry with content (in case fetching failed, the given entry will be return)
         $this->fetchContent($entry, $data['url'], $data);
 
-        if (array_key_exists('tags', $data)) {
+        if (\array_key_exists('tags', $data)) {
             $this->tagsAssigner->assignTagsToEntry(
                 $entry,
                 $data['tags']
index eccee69869a1197c59bdf3e500953a4c6867d424..4ae82ade86f15fb0473141e8251b3d91163dff49 100644 (file)
@@ -57,7 +57,7 @@ class ChromeImport extends BrowserImport
             'created_at' => substr($entry['date_added'], 0, 10),
         ];
 
-        if (array_key_exists('tags', $entry) && '' !== $entry['tags']) {
+        if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) {
             $data['tags'] = $entry['tags'];
         }
 
index 8999e3f3932240accb4096b519af13a31230bdbc..b3558f21e65bbbbe2f21acea81ed5b2dcef815ba 100644 (file)
@@ -57,7 +57,7 @@ class FirefoxImport extends BrowserImport
             'created_at' => substr($entry['dateAdded'], 0, 10),
         ];
 
-        if (array_key_exists('tags', $entry) && '' !== $entry['tags']) {
+        if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) {
             $data['tags'] = $entry['tags'];
         }
 
index c3a142b91c199f4333e4a4954db7fbbdf95e757f..75a28fbf58e0242ec2f0f617266954b5ef83b5ed 100644 (file)
@@ -122,7 +122,7 @@ abstract class WallabagImport extends AbstractImport
         // update entry with content (in case fetching failed, the given entry will be return)
         $this->fetchContent($entry, $data['url'], $data);
 
-        if (array_key_exists('tags', $data)) {
+        if (\array_key_exists('tags', $data)) {
             $this->tagsAssigner->assignTagsToEntry(
                 $entry,
                 $data['tags'],
index b9bb525ab5f20422f388370fe1b44b8bca9d228c..e056261177584262088313cc1403f8ef1d33c262 100644 (file)
@@ -61,7 +61,7 @@ class WallabagV1Import extends WallabagImport
             $data['html'] = $this->fetchingErrorMessage;
         }
 
-        if (array_key_exists('tags', $entry) && '' !== $entry['tags']) {
+        if (\array_key_exists('tags', $entry) && '' !== $entry['tags']) {
             $data['tags'] = $entry['tags'];
         }
 
index 1173fc3dee8f4a858ceaba71658a7281aa243ab3..7beccd3099957236d95d462cd3f428ecd11e64cb 100644 (file)
@@ -134,4 +134,72 @@ class GrabySiteConfigBuilderTest extends TestCase
 
         $this->assertCount(1, $records, 'One log was recorded');
     }
+
+    public function testBuildConfigWithBadExtraFields()
+    {
+        /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
+        $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $grabySiteConfig = new GrabySiteConfig();
+        $grabySiteConfig->requires_login = true;
+        $grabySiteConfig->login_uri = 'http://www.example.com/login';
+        $grabySiteConfig->login_username_field = 'login';
+        $grabySiteConfig->login_password_field = 'password';
+        $grabySiteConfig->login_extra_fields = ['field'];
+        $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
+
+        $grabyConfigBuilderMock
+            ->method('buildForHost')
+            ->with('example.com')
+            ->will($this->returnValue($grabySiteConfig));
+
+        $logger = new Logger('foo');
+        $handler = new TestHandler();
+        $logger->pushHandler($handler);
+
+        $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $siteCrentialRepo->expects($this->once())
+            ->method('findOneByHostAndUser')
+            ->with('example.com', 1)
+            ->willReturn(['username' => 'foo', 'password' => 'bar']);
+
+        $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $user->expects($this->once())
+            ->method('getId')
+            ->willReturn(1);
+
+        $token = new UsernamePasswordToken($user, 'pass', 'provider');
+
+        $tokenStorage = new TokenStorage();
+        $tokenStorage->setToken($token);
+
+        $this->builder = new GrabySiteConfigBuilder(
+            $grabyConfigBuilderMock,
+            $tokenStorage,
+            $siteCrentialRepo,
+            $logger
+        );
+
+        $config = $this->builder->buildForHost('www.example.com');
+
+        $this->assertSame('example.com', $config->getHost());
+        $this->assertTrue($config->requiresLogin());
+        $this->assertSame('http://www.example.com/login', $config->getLoginUri());
+        $this->assertSame('login', $config->getUsernameField());
+        $this->assertSame('password', $config->getPasswordField());
+        $this->assertSame([], $config->getExtraFields());
+        $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath());
+        $this->assertSame('foo', $config->getUsername());
+        $this->assertSame('bar', $config->getPassword());
+
+        $records = $handler->getRecords();
+
+        $this->assertCount(1, $records, 'One log was recorded');
+    }
 }