From 18fdfd1ed551bbc698218b754175de29c6d0b380 Mon Sep 17 00:00:00 2001 From: BeezyT <timo@ezdesign.de> Date: Mon, 12 Nov 2012 09:52:57 +0000 Subject: [PATCH] refs #2465 * adding url normalizer tests to tests/javascript * note: two of the other test cases are failing (JSLint and tracking:"ecommerce view multiple categories") git-svn-id: http://dev.piwik.org/svn/trunk@7447 59fd770c-687e-43c8-a1e3-f5a4ff64c105 --- plugins/Overlay/client/urlnormalizer.js | 84 +------------------------ tests/javascript/index.php | 70 +++++++++++++++++++++ 2 files changed, 71 insertions(+), 83 deletions(-) diff --git a/plugins/Overlay/client/urlnormalizer.js b/plugins/Overlay/client/urlnormalizer.js index 24d0924023..38423bab60 100644 --- a/plugins/Overlay/client/urlnormalizer.js +++ b/plugins/Overlay/client/urlnormalizer.js @@ -196,86 +196,4 @@ var Piwik_Overlay_UrlNormalizer = (function() { }; -})(); - - -/* TESTS FOR URL NORMALIZER * - -(function() { - - var success = true; - - function test(testCases) { - for (var i = 0; i < testCases.length; i++) { - var observed = Piwik_Overlay_UrlNormalizer.normalize(testCases[i][0]); - var expected = testCases[i][1]; - if (observed != expected) { - alert("TEST FAIL!\nOriginal: " + testCases[i][0] + - "\nObserved: " + observed + "\nExpected: " + expected); - success = false; - } - } - } - - - Piwik_Overlay_UrlNormalizer.initialize(); - Piwik_Overlay_UrlNormalizer.setExcludedParameters(['excluded1', 'excluded2', 'excluded3']); - - Piwik_Overlay_UrlNormalizer.setBaseHref(false); - - Piwik_Overlay_UrlNormalizer.setCurrentDomain('example.com'); - Piwik_Overlay_UrlNormalizer.setCurrentUrl('https://www.example.com/current/test.html?asdfasdf'); - - test([ - [ - 'relative/path/', - 'example.com/current/relative/path/' - ], [ - 'http://www.example2.com/path/foo.html', - 'example2.com/path/foo.html' - ] - ]); - - - Piwik_Overlay_UrlNormalizer.setCurrentDomain('www.example3.com'); - Piwik_Overlay_UrlNormalizer.setCurrentUrl('http://example3.com/current/folder/'); - - test([[ - 'relative.html', - 'example3.com/current/folder/relative.html' - ]]); - - - Piwik_Overlay_UrlNormalizer.setBaseHref('http://example.com/base/'); - - test([ - [ - 'http://www.example2.com/my/test/path.html?id=2&excluded2=foo#MyAnchor', - 'example2.com/my/test/path.html?id=2' - ], [ - '/my/test/foo/../path.html?excluded1=foo&excluded2=foo&excluded3=foo', - 'example3.com/my/test/path.html' - ], [ - 'path/./test//test///foo.bar?excluded2=foo&id=3', - 'example.com/base/path/test/test/foo.bar?id=3' - ], [ - 'https://example2.com//test.html?id=3&excluded1=foo&bar=baz#asdf', - 'example2.com/test.html?id=3&bar=baz' - ], [ - '#', - '' - ], [ - '#Anchor', - '' - ], [ - '/', - 'example3.com/' - ] - ]); - - - if (success) { - alert('TEST SUCCESS'); - } - -})(); // */ +})(); \ No newline at end of file diff --git a/tests/javascript/index.php b/tests/javascript/index.php index 0a1f40eec6..8a22a6d940 100644 --- a/tests/javascript/index.php +++ b/tests/javascript/index.php @@ -37,6 +37,7 @@ _paq.push(["trackPageView", "Asynchronous tracker"]);'; ?> </script> <script src="../../js/piwik.js" type="text/javascript"></script> + <script src="../../plugins/Overlay/client/urlnormalizer.js" type="text/javascript"></script> <script src="piwiktest.js" type="text/javascript"></script> <link rel="stylesheet" href="assets/qunit.css" type="text/css" media="screen" /> <link rel="stylesheet" href="jash/Jash.css" type="text/css" media="screen" /> @@ -728,6 +729,75 @@ function PiwikTest() { stopTime = new Date(); ok( (stopTime.getTime() - startTime.getTime()) >= 2000, 'setLinkTrackingTimer()' ); }); + + test("Overlay URL Normalizer", function() { + expect(11); + + var test = function(testCases) { + for (var i = 0; i < testCases.length; i++) { + var observed = Piwik_Overlay_UrlNormalizer.normalize(testCases[i][0]); + var expected = testCases[i][1]; + equal(observed, expected, testCases[i][0]); + } + }; + + Piwik_Overlay_UrlNormalizer.initialize(); + Piwik_Overlay_UrlNormalizer.setExcludedParameters(['excluded1', 'excluded2', 'excluded3']); + + Piwik_Overlay_UrlNormalizer.setBaseHref(false); + + Piwik_Overlay_UrlNormalizer.setCurrentDomain('example.com'); + Piwik_Overlay_UrlNormalizer.setCurrentUrl('https://www.example.com/current/test.html?asdfasdf'); + + test([ + [ + 'relative/path/', + 'example.com/current/relative/path/' + ], [ + 'http://www.example2.com/path/foo.html', + 'example2.com/path/foo.html' + ] + ]); + + Piwik_Overlay_UrlNormalizer.setCurrentDomain('www.example3.com'); + Piwik_Overlay_UrlNormalizer.setCurrentUrl('http://example3.com/current/folder/'); + + test([[ + 'relative.html', + 'example3.com/current/folder/relative.html' + ]]); + + + Piwik_Overlay_UrlNormalizer.setBaseHref('http://example.com/base/'); + + test([ + [ + 'http://www.example2.com/my/test/path.html?id=2&excluded2=foo#MyAnchor', + 'example2.com/my/test/path.html?id=2#MyAnchor' + ], [ + '/my/test/foo/../path.html?excluded1=foo&excluded2=foo&excluded3=foo', + 'example3.com/my/test/path.html' + ], [ + 'path/./test//test///foo.bar?excluded2=foo&id=3', + 'example.com/base/path/test/test/foo.bar?id=3' + ], [ + 'path/./test//test///foo.bar?excluded2=foo#Anchor', + 'example.com/base/path/test/test/foo.bar#Anchor' + ], [ + 'https://example2.com//test.html?id=3&excluded1=foo&bar=baz#asdf', + 'example2.com/test.html?id=3&bar=baz#asdf' + ], [ + '#', + '' + ], [ + '#Anchor', + '' + ], [ + '/', + 'example3.com/' + ] + ]); + }); <?php if ($sqlite) { -- GitLab