]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Adding more tests 3857/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 27 Feb 2019 13:59:50 +0000 (14:59 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 27 Feb 2019 14:01:03 +0000 (15:01 +0100)
src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
src/Wallabag/CoreBundle/Helper/DownloadImages.php
src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
src/Wallabag/CoreBundle/Helper/TagsAssigner.php
src/Wallabag/ImportBundle/Import/AbstractImport.php
src/Wallabag/ImportBundle/Import/BrowserImport.php
src/Wallabag/ImportBundle/Import/InstapaperImport.php
tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php

index 2e57aac8a891930dd05e3e63a060e028df45e9aa..90e00c62d9aaeff353e5f356ec6fcc4703e9d5db 100644 (file)
@@ -114,7 +114,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
         $extraFields = [];
         foreach ($extraFieldsStrings as $extraField) {
             if (false === strpos($extraField, '=')) {
-                break;
+                continue;
             }
 
             list($fieldName, $fieldValue) = explode('=', $extraField, 2);
index 8c1c208f57772c811abb409af2ebd75b60fb8f9a..cc3dcfceb7796ffcb457e749eb654680347f3dc8 100644 (file)
@@ -56,7 +56,7 @@ class DownloadImages
             $imagePath = $this->processSingleImage($entryId, $image, $url, $relativePath);
 
             if (false === $imagePath) {
-                break;
+                continue;
             }
 
             // if image contains "&" and we can't find it in the html it might be because it's encoded as &amp;
index d156df84ee753f852e1ef926eb285f1db0cc541c..fbdf2ac7a706bdcb0d862f8fb719ab279b5a72fb 100644 (file)
@@ -37,7 +37,7 @@ class RuleBasedTagger
 
         foreach ($rules as $rule) {
             if (!$this->rulerz->satisfies($entry, $rule->getRule())) {
-                break;
+                continue;
             }
 
             $this->logger->info('Matching rule.', [
index 519150f539f89441c88cf37740e7fd2a7bce18ae..e6b4989f8d64ba638b30e6bd7554bb96d8aa799e 100644 (file)
@@ -49,7 +49,7 @@ class TagsAssigner
 
             // avoid empty tag
             if (0 === \strlen($label)) {
-                break;
+                continue;
             }
 
             if (isset($tagsNotYetFlushed[$label])) {
index 5ae4aa8d654373843a61b0276576a800fea9fd49..d39d71b6caf1e3b7def2c0b352b4ceeccdef0840 100644 (file)
@@ -169,7 +169,7 @@ abstract class AbstractImport implements ImportInterface
             $entry = $this->parseEntry($importedEntry);
 
             if (null === $entry) {
-                break;
+                continue;
             }
 
             // store each entry to be flushed so we can trigger the entry.saved event for each of them
index 99717beb81a95d56aee18763ef6fe567b854c866..3987e80f0722856df2067fcbcc380554aea6eaf5 100644 (file)
@@ -158,13 +158,13 @@ abstract class BrowserImport extends AbstractImport
 
         foreach ($entries as $importedEntry) {
             if ((array) $importedEntry !== $importedEntry) {
-                break;
+                continue;
             }
 
             $entry = $this->parseEntry($importedEntry);
 
             if (null === $entry) {
-                break;
+                continue;
             }
 
             // @see AbstractImport
@@ -206,7 +206,7 @@ abstract class BrowserImport extends AbstractImport
     {
         foreach ($entries as $importedEntry) {
             if ((array) $importedEntry !== $importedEntry) {
-                break;
+                continue;
             }
 
             // set userId for the producer (it won't know which user is connected)
index 6b6b35afa7e5e0da548c6126a3657654a2ba4259..439c978c71f02a6d4953cf25e7475b2a9a63582a 100644 (file)
@@ -65,7 +65,7 @@ class InstapaperImport extends AbstractImport
         $handle = fopen($this->filepath, 'r');
         while (false !== ($data = fgetcsv($handle, 10240))) {
             if ('URL' === $data[0]) {
-                break;
+                continue;
             }
 
             // last element in the csv is the folder where the content belong
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');
+    }
 }