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 19fcbfbf..c7ccfe4a 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -67,9 +67,8 @@ class ContentProxy
67 67
68 // In one case (at least in tests), url is empty here 68 // In one case (at least in tests), url is empty here
69 // so we set it using $url provided in the updateEntry call. 69 // so we set it using $url provided in the updateEntry call.
70 // Not sure what are the other possible cases where this property is empty 70 // Not sure what are the other possible cases where this property is empty
71 if (empty($entry->getUrl()) && !empty($url)) 71 if (empty($entry->getUrl()) && !empty($url)) {
72 {
73 $entry->setUrl($url); 72 $entry->setUrl($url);
74 } 73 }
75 74
@@ -193,7 +192,15 @@ class ContentProxy
193 */ 192 */
194 private function stockEntry(Entry $entry, array $content) 193 private function stockEntry(Entry $entry, array $content)
195 { 194 {
196 $entry->setUrl($content['url']); 195 // When a redirection occurs while fetching an entry
196 // we move the original url in origin_url property if empty
197 // and set the entry url with the final value
198 if (!empty($content['url']) && $entry->getUrl() !== $content['url']) {
199 if (empty($entry->getOriginUrl())) {
200 $entry->setOriginUrl($entry->getUrl());
201 }
202 $entry->setUrl($content['url']);
203 }
197 204
198 $this->setEntryDomainName($entry); 205 $this->setEntryDomainName($entry);
199 206
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 398592e1..c1a56b89 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -532,6 +532,32 @@ class ContentProxyTest extends TestCase
532 $this->assertSame('1.1.1.1', $entry->getDomainName()); 532 $this->assertSame('1.1.1.1', $entry->getDomainName());
533 } 533 }
534 534
535 public function testWithChangedUrl()
536 {
537 $tagger = $this->getTaggerMock();
538 $tagger->expects($this->once())
539 ->method('tag');
540
541 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true);
542 $entry = new Entry(new User());
543 $proxy->updateEntry(
544 $entry,
545 'http://0.0.0.0',
546 [
547 'html' => false,
548 'title' => '',
549 'url' => 'http://1.1.1.1',
550 'content_type' => '',
551 'language' => '',
552 ],
553 true
554 );
555
556 $this->assertSame('http://1.1.1.1', $entry->getUrl());
557 $this->assertSame('1.1.1.1', $entry->getDomainName());
558 $this->assertSame('http://0.0.0.0', $entry->getOriginUrl());
559 }
560
535 private function getTaggerMock() 561 private function getTaggerMock()
536 { 562 {
537 return $this->getMockBuilder(RuleBasedTagger::class) 563 return $this->getMockBuilder(RuleBasedTagger::class)