blob: 0fd1e89e8ae39fb7fed4706bfe53620fdff0e7c7 [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
Marc Kupietze387a172023-08-30 17:41:45 +020040like($t->app->piwik_tag('as-script'), qr!<script src="/settings/assets/tracking.js"></script><script src="https://piwik\.korap\.ids-mannheim\.de/(?:matomo|piwik)\.js" async defer></script>!);
Akron0a4d36e2021-01-18 17:50:48 +010041
42$t->get_ok('/doc/faq')
43 ->status_is(200)
44 ->text_like('section[name=piwik-opt-out] h3', qr!can I opt-out!)
45 ->element_exists('section[name=piwik-opt-out] iframe')
Akron08952df2021-02-22 11:21:33 +010046 ->element_exists('script[src$="/settings/assets/tracking.js"]')
Akron0a4d36e2021-01-18 17:50:48 +010047 ->content_unlike(qr!_paq!)
48 ->header_like('Content-Security-Policy',qr!connect-src 'self' [^;]*?https://piwik\.korap\.ids-mannheim\.de/!)
49 ->header_like('Content-Security-Policy',qr!img-src 'self' [^;]*?https://piwik\.korap\.ids-mannheim\.de/!)
Akron0e983a02021-03-01 16:35:19 +010050 ->header_like('Content-Security-Policy',qr!script-src 'self' [^;]*?https://piwik\.korap\.ids-mannheim\.de/!)
51 ->header_like('Content-Security-Policy',qr!frame-src [^;]*?(?:\*|https://piwik\.korap\.ids-mannheim\.de/)!)
Akron0a4d36e2021-01-18 17:50:48 +010052 ;
53
Akron08952df2021-02-22 11:21:33 +010054$t->get_ok('/settings/assets/tracking.js')
Akron0a4d36e2021-01-18 17:50:48 +010055 ->status_is(200)
Akron4c33c622018-11-12 13:43:27 +010056 ->content_like(qr!var _paq!)
Akron0a4d36e2021-01-18 17:50:48 +010057 ->content_like(qr!;console\.log\("fun"\)!)
58 ->content_like(qr!;window\.addEventListener\('korapRequest!)
Akron4c33c622018-11-12 13:43:27 +010059 ;
60
Akron7c758412018-11-13 14:17:00 +010061# No embedding
Akron0a4d36e2021-01-18 17:50:48 +010062$t = Test::Mojo->new('Kalamar' => {
63 'Piwik' => {
64 url => 'https://piwik.korap.ids-mannheim.de/',
65 site_id => 1,
66 embed => 0
67 }
Akron7c758412018-11-13 14:17:00 +010068});
Akron0a4d36e2021-01-18 17:50:48 +010069$t->app->plugin('Kalamar::Plugin::Piwik');
Akron7c758412018-11-13 14:17:00 +010070
71$t->get_ok('/doc/faq')
72 ->status_is(200)
73 ->text_like('section[name=piwik-opt-out] h3', qr!can I opt-out!)
74 ->element_exists_not('section[name=piwik-opt-out] iframe')
Akron0a4d36e2021-01-18 17:50:48 +010075 ->content_unlike(qr!_paq!)
Akron7c758412018-11-13 14:17:00 +010076 ->content_unlike(qr!window\.addEventListener\('korapRequest!)
Akron08952df2021-02-22 11:21:33 +010077 ->element_exists_not('script[src$="/settings/assets/tracking.js"]')
Akron7c758412018-11-13 14:17:00 +010078 ;
79
Akron0a4d36e2021-01-18 17:50:48 +010080done_testing;