blob: cb4ba9d89cfc4ea2fbb2ec4dea47a87da3c89c34 [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/!)
51 ->header_like('Content-Security-Policy',qr!script-src 'self' [^;]*?https://piwik.korap.ids-mannheim.de/!)
52 ;
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;