blob: 13667d7707bbb81e201d1c0737f928f653a5e3fa [file] [log] [blame]
Akron4c33c622018-11-12 13:43:27 +01001use Mojo::Base -strict;
2use Test::More;
3use Test::Mojo;
4
5# Test the documentation
Akron0a4d36e2021-01-18 17:50:48 +01006my $t = Test::Mojo->new('Kalamar' => {
7 'Piwik' => {
8 url => 'https://piwik.korap.ids-mannheim.de/',
9 site_id => 1,
10 embed => 1
11 }
Akron4c33c622018-11-12 13:43:27 +010012});
13
14# Load piwik
15$t->app->plugin('Kalamar::Plugin::Piwik');
16
17$t->get_ok('/doc/faq')
18 ->status_is(200)
19 ->text_like('section[name=piwik-opt-out] h3', qr!can I opt-out!)
20 ->element_exists('section[name=piwik-opt-out] iframe')
Akron0a4d36e2021-01-18 17:50:48 +010021 ->content_unlike(qr!var _paq!)
22 ->content_unlike(qr!window\.addEventListener\('korapRequest!)
23 ->content_unlike(qr!setDocumentTitle!)
24 ->content_unlike(qr!setCustomUrl!)
25 ->content_unlike(qr!trackPageView!)
Akron08952df2021-02-22 11:21:33 +010026 ->element_exists('script[src$="/settings/assets/tracking.js"]')
Akron0a4d36e2021-01-18 17:50:48 +010027 ;
28
29$t = Test::Mojo->new('Kalamar' => {
30 'Piwik' => {
31 url => 'https://piwik.korap.ids-mannheim.de/',
32 site_id => 1,
33 embed => 1,
34 append => 'console.log("fun")'
35 }
36});
37
38$t->app->plugin('Kalamar::Plugin::Piwik');
39
Akron08952df2021-02-22 11:21:33 +010040is($t->app->piwik_tag('as-script'), '<script src="/settings/assets/tracking.js"></script>' .
Akron0a4d36e2021-01-18 17:50:48 +010041 '<script src="https://piwik.korap.ids-mannheim.de/piwik.js" async defer></script>');
42
43$t->get_ok('/doc/faq')
44 ->status_is(200)
45 ->text_like('section[name=piwik-opt-out] h3', qr!can I opt-out!)
46 ->element_exists('section[name=piwik-opt-out] iframe')
Akron08952df2021-02-22 11:21:33 +010047 ->element_exists('script[src$="/settings/assets/tracking.js"]')
Akron0a4d36e2021-01-18 17:50:48 +010048 ->content_unlike(qr!_paq!)
49 ->header_like('Content-Security-Policy',qr!connect-src 'self' [^;]*?https://piwik\.korap\.ids-mannheim\.de/!)
50 ->header_like('Content-Security-Policy',qr!img-src 'self' [^;]*?https://piwik\.korap\.ids-mannheim\.de/!)
Akron0e983a02021-03-01 16:35:19 +010051 ->header_like('Content-Security-Policy',qr!script-src 'self' [^;]*?https://piwik\.korap\.ids-mannheim\.de/!)
52 ->header_like('Content-Security-Policy',qr!frame-src [^;]*?(?:\*|https://piwik\.korap\.ids-mannheim\.de/)!)
Akron0a4d36e2021-01-18 17:50:48 +010053 ;
54
Akron08952df2021-02-22 11:21:33 +010055$t->get_ok('/settings/assets/tracking.js')
Akron0a4d36e2021-01-18 17:50:48 +010056 ->status_is(200)
Akron4c33c622018-11-12 13:43:27 +010057 ->content_like(qr!var _paq!)
Akron0a4d36e2021-01-18 17:50:48 +010058 ->content_like(qr!;console\.log\("fun"\)!)
59 ->content_like(qr!;window\.addEventListener\('korapRequest!)
Akron4c33c622018-11-12 13:43:27 +010060 ;
61
Akron7c758412018-11-13 14:17:00 +010062# No embedding
Akron0a4d36e2021-01-18 17:50:48 +010063$t = Test::Mojo->new('Kalamar' => {
64 'Piwik' => {
65 url => 'https://piwik.korap.ids-mannheim.de/',
66 site_id => 1,
67 embed => 0
68 }
Akron7c758412018-11-13 14:17:00 +010069});
Akron0a4d36e2021-01-18 17:50:48 +010070$t->app->plugin('Kalamar::Plugin::Piwik');
Akron7c758412018-11-13 14:17:00 +010071
72$t->get_ok('/doc/faq')
73 ->status_is(200)
74 ->text_like('section[name=piwik-opt-out] h3', qr!can I opt-out!)
75 ->element_exists_not('section[name=piwik-opt-out] iframe')
Akron0a4d36e2021-01-18 17:50:48 +010076 ->content_unlike(qr!_paq!)
Akron7c758412018-11-13 14:17:00 +010077 ->content_unlike(qr!window\.addEventListener\('korapRequest!)
Akron08952df2021-02-22 11:21:33 +010078 ->element_exists_not('script[src$="/settings/assets/tracking.js"]')
Akron7c758412018-11-13 14:17:00 +010079 ;
80
Akron0a4d36e2021-01-18 17:50:48 +010081done_testing;