Akron | 4c33c62 | 2018-11-12 13:43:27 +0100 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::More; |
| 3 | use Test::Mojo; |
| 4 | |
| 5 | # Test the documentation |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 6 | my $t = Test::Mojo->new('Kalamar' => { |
| 7 | 'Piwik' => { |
| 8 | url => 'https://piwik.korap.ids-mannheim.de/', |
| 9 | site_id => 1, |
| 10 | embed => 1 |
| 11 | } |
Akron | 4c33c62 | 2018-11-12 13:43:27 +0100 | [diff] [blame] | 12 | }); |
| 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') |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 21 | ->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!) |
Akron | 08952df | 2021-02-22 11:21:33 +0100 | [diff] [blame] | 26 | ->element_exists('script[src$="/settings/assets/tracking.js"]') |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 27 | ; |
| 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 | |
Akron | 08952df | 2021-02-22 11:21:33 +0100 | [diff] [blame] | 40 | is($t->app->piwik_tag('as-script'), '<script src="/settings/assets/tracking.js"></script>' . |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 41 | '<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') |
Akron | 08952df | 2021-02-22 11:21:33 +0100 | [diff] [blame] | 47 | ->element_exists('script[src$="/settings/assets/tracking.js"]') |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 48 | ->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 | |
Akron | 08952df | 2021-02-22 11:21:33 +0100 | [diff] [blame] | 54 | $t->get_ok('/settings/assets/tracking.js') |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 55 | ->status_is(200) |
Akron | 4c33c62 | 2018-11-12 13:43:27 +0100 | [diff] [blame] | 56 | ->content_like(qr!var _paq!) |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 57 | ->content_like(qr!;console\.log\("fun"\)!) |
| 58 | ->content_like(qr!;window\.addEventListener\('korapRequest!) |
Akron | 4c33c62 | 2018-11-12 13:43:27 +0100 | [diff] [blame] | 59 | ; |
| 60 | |
Akron | 7c75841 | 2018-11-13 14:17:00 +0100 | [diff] [blame] | 61 | # No embedding |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 62 | $t = Test::Mojo->new('Kalamar' => { |
| 63 | 'Piwik' => { |
| 64 | url => 'https://piwik.korap.ids-mannheim.de/', |
| 65 | site_id => 1, |
| 66 | embed => 0 |
| 67 | } |
Akron | 7c75841 | 2018-11-13 14:17:00 +0100 | [diff] [blame] | 68 | }); |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 69 | $t->app->plugin('Kalamar::Plugin::Piwik'); |
Akron | 7c75841 | 2018-11-13 14:17:00 +0100 | [diff] [blame] | 70 | |
| 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') |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 75 | ->content_unlike(qr!_paq!) |
Akron | 7c75841 | 2018-11-13 14:17:00 +0100 | [diff] [blame] | 76 | ->content_unlike(qr!window\.addEventListener\('korapRequest!) |
Akron | 08952df | 2021-02-22 11:21:33 +0100 | [diff] [blame] | 77 | ->element_exists_not('script[src$="/settings/assets/tracking.js"]') |
Akron | 7c75841 | 2018-11-13 14:17:00 +0100 | [diff] [blame] | 78 | ; |
| 79 | |
Akron | 0a4d36e | 2021-01-18 17:50:48 +0100 | [diff] [blame] | 80 | done_testing; |