diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2018-01-07 17:28:04 +0100 |
---|---|---|
committer | Kevin Decherf <kevin@kdecherf.com> | 2018-01-14 16:41:56 +0100 |
commit | c801d03e46ae036d8b1898f884769e361c51ed58 (patch) | |
tree | 5392b0669d0320582d4df621f607fd64f07a1490 | |
parent | 3362b3e3d340e6e24d703b38010870479ab0f67c (diff) | |
download | wallabag-c801d03e46ae036d8b1898f884769e361c51ed58.tar.gz wallabag-c801d03e46ae036d8b1898f884769e361c51ed58.tar.zst wallabag-c801d03e46ae036d8b1898f884769e361c51ed58.zip |
ContentProxy: swap entry url to origin_url and set new url according to graby contenturl-3529
Closes #3529
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 15 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 26 |
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) |