]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
ContentProxy: swap entry url to origin_url and set new url according to graby content url-3529
authorKevin Decherf <kevin@kdecherf.com>
Sun, 7 Jan 2018 16:28:04 +0000 (17:28 +0100)
committerKevin Decherf <kevin@kdecherf.com>
Sun, 14 Jan 2018 15:41:56 +0000 (16:41 +0100)
Closes #3529

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
src/Wallabag/CoreBundle/Helper/ContentProxy.php
tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php

index 19fcbfbfae9c95d056476ca8bfa9d88ca30de33e..c7ccfe4a0e2f871c9daa1528b6394663e7ddfc55 100644 (file)
@@ -67,9 +67,8 @@ class ContentProxy
 
         // In one case (at least in tests), url is empty here
         // so we set it using $url provided in the updateEntry call.
-        // Not sure what are the other possible cases where this property is empty 
-        if (empty($entry->getUrl()) && !empty($url))
-        {
+        // Not sure what are the other possible cases where this property is empty
+        if (empty($entry->getUrl()) && !empty($url)) {
             $entry->setUrl($url);
         }
 
@@ -193,7 +192,15 @@ class ContentProxy
      */
     private function stockEntry(Entry $entry, array $content)
     {
-        $entry->setUrl($content['url']);
+        // When a redirection occurs while fetching an entry
+        // we move the original url in origin_url property if empty
+        // and set the entry url with the final value
+        if (!empty($content['url']) && $entry->getUrl() !== $content['url']) {
+            if (empty($entry->getOriginUrl())) {
+                $entry->setOriginUrl($entry->getUrl());
+            }
+            $entry->setUrl($content['url']);
+        }
 
         $this->setEntryDomainName($entry);
 
index 398592e1fa519577d1ff90fd4d4686c6c7d21b7d..c1a56b89b0600f03482bd2b9d28649958ab1e1d5 100644 (file)
@@ -532,6 +532,32 @@ class ContentProxyTest extends TestCase
         $this->assertSame('1.1.1.1', $entry->getDomainName());
     }
 
+    public function testWithChangedUrl()
+    {
+        $tagger = $this->getTaggerMock();
+        $tagger->expects($this->once())
+            ->method('tag');
+
+        $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true);
+        $entry = new Entry(new User());
+        $proxy->updateEntry(
+            $entry,
+            'http://0.0.0.0',
+            [
+                'html' => false,
+                'title' => '',
+                'url' => 'http://1.1.1.1',
+                'content_type' => '',
+                'language' => '',
+            ],
+            true
+        );
+
+        $this->assertSame('http://1.1.1.1', $entry->getUrl());
+        $this->assertSame('1.1.1.1', $entry->getDomainName());
+        $this->assertSame('http://0.0.0.0', $entry->getOriginUrl());
+    }
+
     private function getTaggerMock()
     {
         return $this->getMockBuilder(RuleBasedTagger::class)