Skip to content
Extraits de code Groupes Projets
Valider 18fdfd1e rédigé par BeezyT's avatar BeezyT
Parcourir les fichiers

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
parent 8065a7ca
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
......@@ -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) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter