aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php15
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php26
2 files changed, 37 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index f0d8c1b4..da0ec5a3 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -68,9 +68,8 @@ class ContentProxy
68 68
69 // In one case (at least in tests), url is empty here 69 // In one case (at least in tests), url is empty here
70 // so we set it using $url provided in the updateEntry call. 70 // so we set it using $url provided in the updateEntry call.
71 // Not sure what are the other possible cases where this property is empty 71 // Not sure what are the other possible cases where this property is empty
72 if (empty($entry->getUrl()) && !empty($url)) 72 if (empty($entry->getUrl()) && !empty($url)) {
73 {
74 $entry->setUrl($url); 73 $entry->setUrl($url);
75 } 74 }
76 75
@@ -247,7 +246,15 @@ class ContentProxy
247 */ 246 */
248 private function stockEntry(Entry $entry, array $content) 247 private function stockEntry(Entry $entry, array $content)
249 { 248 {
250 $entry->setUrl($content['url']); 249 // When a redirection occurs while fetching an entry
250 // we move the original url in origin_url property if empty
251 // and set the entry url with the final value
252 if (!empty($content['url']) && $entry->getUrl() !== $content['url']) {
253 if (empty($entry->getOriginUrl())) {
254 $entry->setOriginUrl($entry->getUrl());
255 }
256 $entry->setUrl($content['url']);
257 }
251 258
252 $this->setEntryDomainName($entry); 259 $this->setEntryDomainName($entry);
253 260
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 3f3c60d0..84b38f02 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -775,6 +775,32 @@ class ContentProxyTest extends TestCase
775 return $string; 775 return $string;
776 } 776 }
777 777
778 public function testWithChangedUrl()
779 {
780 $tagger = $this->getTaggerMock();
781 $tagger->expects($this->once())
782 ->method('tag');
783
784 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true);
785 $entry = new Entry(new User());
786 $proxy->updateEntry(
787 $entry,
788 'http://0.0.0.0',
789 [
790 'html' => false,
791 'title' => '',
792 'url' => 'http://1.1.1.1',
793 'content_type' => '',
794 'language' => '',
795 ],
796 true
797 );
798
799 $this->assertSame('http://1.1.1.1', $entry->getUrl());
800 $this->assertSame('1.1.1.1', $entry->getDomainName());
801 $this->assertSame('http://0.0.0.0', $entry->getOriginUrl());
802 }
803
778 private function getTaggerMock() 804 private function getTaggerMock()
779 { 805 {
780 return $this->getMockBuilder(RuleBasedTagger::class) 806 return $this->getMockBuilder(RuleBasedTagger::class)