]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
updateOriginUrl: add behavior when diff is fragment and query
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Helper / ContentProxyTest.php
index 3f3c60d0fd943436f88759853b9ee5c950b554e2..3debc4577fd793c1dd23a4919ecc453058db1e8b 100644 (file)
@@ -739,6 +739,109 @@ class ContentProxyTest extends TestCase
         $this->assertSame($expectedTitle, $this->strToHex($entry->getTitle()));
     }
 
+    /**
+     * Data provider for testWithChangedUrl.
+     *
+     * Arrays contain the following values:
+     * $entry_url
+     * $origin_url
+     * $content_url
+     * $expected_entry_url
+     * $expected_origin_url
+     * $expected_domain
+     */
+    public function dataForChangedUrl()
+    {
+        return [
+            'normal' => [
+                'http://0.0.0.0',
+                null,
+                'http://1.1.1.1',
+                'http://1.1.1.1',
+                'http://0.0.0.0',
+                '1.1.1.1',
+            ],
+            'origin already set' => [
+                'http://0.0.0.0',
+                'http://hello',
+                'http://1.1.1.1',
+                'http://1.1.1.1',
+                'http://hello',
+                '1.1.1.1',
+            ],
+            'trailing slash' => [
+                'https://example.com/hello-world',
+                null,
+                'https://example.com/hello-world/',
+                'https://example.com/hello-world/',
+                null,
+                'example.com',
+            ],
+            'no query string in fetched content' => [
+                'https://example.org/hello?world=1',
+                null,
+                'https://example.org/hello',
+                'https://example.org/hello?world=1',
+                null,
+                'example.org',
+            ],
+            'query string in fetched content' => [
+                'https://example.org/hello',
+                null,
+                'https://example.org/hello?world=1',
+                'https://example.org/hello',
+                null,
+                'example.org',
+            ],
+            'fragment in fetched content' => [
+                'https://example.org/hello',
+                null,
+                'https://example.org/hello#world',
+                'https://example.org/hello',
+                null,
+                'example.org',
+            ],
+            'fragment and query string in fetched content' => [
+                'https://example.org/hello',
+                null,
+                'https://example.org/hello?foo#world',
+                'https://example.org/hello',
+                null,
+                'example.org',
+            ]
+        ];
+    }
+
+    /**
+     * @dataProvider dataForChangedUrl
+     */
+    public function testWithChangedUrl($entry_url, $origin_url, $content_url, $expected_entry_url, $expected_origin_url, $expected_domain)
+    {
+        $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());
+        $entry->setOriginUrl($origin_url);
+        $proxy->updateEntry(
+            $entry,
+            $entry_url,
+            [
+                'html' => false,
+                'title' => '',
+                'url' => $content_url,
+                'content_type' => '',
+                'language' => '',
+            ],
+            true
+        );
+
+        $this->assertSame($expected_entry_url, $entry->getUrl());
+        $this->assertSame($expected_domain, $entry->getDomainName());
+        $this->assertSame($expected_origin_url, $entry->getOriginUrl());
+    }
+
     /**
      * https://stackoverflow.com/a/18506801.
      *