✅ Add test for QC filter
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Sep 2020 11:22:36 +0000 (13:22 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Sep 2020 11:22:36 +0000 (13:22 +0200)
src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/QuestionableContentFilterTest.kt [new file with mode: 0644]
src/test/resources/net/pterodactylus/rhynodge/filters/comics/questionable-content.html [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/QuestionableContentFilterTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/QuestionableContentFilterTest.kt
new file mode 100644 (file)
index 0000000..39ae500
--- /dev/null
@@ -0,0 +1,29 @@
+package net.pterodactylus.rhynodge.filters.comics
+
+import net.pterodactylus.rhynodge.filters.ResourceLoader
+import net.pterodactylus.rhynodge.states.ComicState
+import net.pterodactylus.rhynodge.states.ComicState.Comic
+import net.pterodactylus.rhynodge.states.ComicState.Strip
+import net.pterodactylus.rhynodge.states.HtmlState
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.contains
+import org.junit.Test
+
+class QuestionableContentFilterTest {
+
+       private val filter = QuestionableContentComicFilter()
+       private val htmlState: HtmlState = ResourceLoader
+                       .loadDocument(javaClass, "questionable-content.html", baseUrl)
+                       .let { HtmlState(baseUrl, it) }
+
+       @Test
+       fun `comic is extracted correctly`() {
+               val comicState = filter.filter(htmlState) as ComicState
+               assertThat(comicState.comics(), contains(
+                               Comic("").add(Strip("https://www.questionablecontent.net/comics/4355.png", ""))
+               ))
+       }
+
+}
+
+private const val baseUrl = "https://www.questionablecontent.net/"
diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/questionable-content.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/questionable-content.html
new file mode 100644 (file)
index 0000000..073015e
--- /dev/null
@@ -0,0 +1,375 @@
+<!doctype html>
+<html class="no-js" lang="en" dir="ltr">
+  <head>
+  
+  
+       <!-- PLACE AFTER OPENING HEAD TAG: Header Bidding Script -->
+       <script type="text/javascript">
+       var tyche = { mode: 'tyche', config: '//config.playwire.com/1024290/v2/websites/72744/banner.json' }
+       </script>
+       <script id="tyche" src="//cdn.intergi.com/hera/tyche.js" type="text/javascript"></script>
+               
+    <meta charset="utf-8">
+    <meta http-equiv="x-ua-compatible" content="ie=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Questionable Content</title>
+    <link rel="stylesheet" href="css/foundation.css">
+    <link rel="stylesheet" href="css/app.css">
+  
+    <link rel="icon" type="image/png" sizes="32x32" href="../favicon/favicon-32x32.png">
+       <link rel="icon" type="image/png" sizes="96x96" href="../favicon/favicon-96x96.png">
+       <link rel="icon" type="image/png" sizes="16x16" href="../favicon/favicon-16x16.png">
+       <link rel="manifest" href="../favicon/manifest.json">
+       <meta name="msapplication-TileColor" content="#ffffff">
+       <meta name="msapplication-TileImage" content="../favicon/ms-icon-144x144.png">
+       <meta name="theme-color" content="#ffffff">
+  
+  <script type="text/javascript">
+/* <![CDATA[ */
+    (function() {
+        var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
+        s.type = 'text/javascript';
+        s.async = true;
+        s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
+        t.parentNode.insertBefore(s, t);
+    })();
+/* ]]> */</script>
+
+<!-- blind ferret ad code --!>
+       
+<script type="text/javascript" src="//thor.blindferret.media/pW0f/ehfM_7xpc/jita.js?dfp=1" async defer></script>
+       
+<!-- jQuery library (served from Google) -->
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
+<!-- bxSlider Javascript file -->
+<script src="./jquery/jquery.bxslider.min.js"></script>
+<!-- bxSlider CSS file -->
+<link href="./jquery/jquery.bxslider.css" rel="stylesheet" />
+
+<script type="text/javascript">
+$('.bxslider').bxSlider({
+  auto: true,
+  autoStart: true,
+  preloadimages: 'all',
+  randomStart: true, 
+});
+</script>
+<!-- cached -->
+  <script src="js/vendor/jquery.js"></script>
+    <script src="js/vendor/what-input.js"></script>
+    <script src="js/vendor/foundation.js"></script>
+    <script src="js/app.js"></script>
+    
+    <!-- Facebook Pixel Code -->
+<script>
+!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
+n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
+n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
+t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
+document,'script','https://connect.facebook.net/en_US/fbevents.js');
+fbq('init', '560616780737475', {
+em: 'insert_email_variable'
+});
+fbq('track', 'PageView');
+</script>
+<noscript><img height="1" width="1" style="display:none"
+src="https://www.facebook.com/tr?id=560616780737475&ev=PageView&noscript=1"
+/></noscript>
+<!-- DO NOT MODIFY -->
+<!-- End Facebook Pixel Code -->
+    
+
+  
+  <script src="js/vendor/jquery.min.js"></script>
+    <script src="js/vendor/what-input.min.js"></script>
+    <script src="js/foundation.min.js"></script>
+    <script>
+      $(document).foundation();
+    </script>
+    
+    <script type="text/javascript">
+  var _gaq = _gaq || [];
+  _gaq.push(['_setAccount', 'UA-17679175-1']);
+  _gaq.push(['_setDomainName', '.questionablecontent.net']);
+  _gaq.push(['_trackPageview']);
+
+  (function() {
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+  })();
+</script>
+
+</head>
+<body>
+
+
+<div class="title-bar" data-responsive-toggle="example-menu" data-hide-for="medium">
+  <button class="menu-icon" type="button" data-toggle></button>
+  <div class="title-bar-title">Menu</div>
+</div>
+
+<div class="top-bar" id="example-menu">
+  <div class="top-bar-left">
+    <ul class="vertical medium-horizontal menu" data-dropdown-menu>
+            <li class="menu-text" id="logo16"><a href="https://www.questionablecontent.net"><img src="https://www.questionablecontent.net/images/logo16.png"></a></li>
+      <li><a href="https://www.questionablecontent.net/archive.php">Archive</a></li>
+      <li><a href="https://www.questionablecontent.net/about.php">About</a></li>
+      <li><a href="https://www.questionablecontent.net/cast.php">Cast</a></li>
+      <li><a href="https://topatoco.com/collections/jeph-jacques">Merchandise</a></li>
+      <li><a href="https://www.questionablecontent.net/contact.php">Contact</a></li>
+      <li><a href="https://www.questionablecontent.net/QCRSS.xml">RSS</a></li>
+      <li><a href="http://www.patreon.com/jephjacques">Patreon</a></li>
+    </ul>
+  </div>
+  <div class="top-bar-right">
+    <ul class="menu">
+       <li></li>
+    </ul>
+  </div>
+</div>\r
+\r
+       <div class="row align-center column" id="container">\r
+                       \r
+<center>\r
+                       \r
+                       \r
+                       <iframe src="./safe-frame.php?mode=AdSense&adunit=3675749653" frameborder="0" width="100%" scrolling="no" sandbox="allow-scripts allow-same-origin allow-top-navigation-by-user-activation"></iframe>\r
+                       \r
+                               \r
+\r
+                               \r
+                       <div class="row" align="center">\r
+                               <div class="small-12 medium-expand column">\r
+                                       <a href="http://www.patreon.com/jephjacques"><img src="https://www.questionablecontent.net/images/patlogo.gif"></a>\r
+                               </div>\r
+                       </div>\r
+                       \r
+</center>\r
+\r
+\r
+    \r
+    <div class="row">\r
+       <div class="small-12 medium-expand column">\r
+                       \r
+                       <script type="text/javascript" src='shortcuts.js'></script>
+<script type="text/javascript">
+    shortcut.add("Left",function() {
+                    window.location.href = 'view.php?comic=4354';
+            });
+    shortcut.add("Right",function() {
+                    alert("You're at the last comic.")
+            });
+</script>
+\r
+                       
+
+<ul class="menu" id="comicnav">
+<li><a href="view.php?comic=1">First</a></li>
+
+<li><a href="view.php?comic=4354">Previous</a></li>
+
+<li><a href="#">Next</a></li>
+
+<li><a href="#">Last</a></li>
+
+<li><a href="https://www.questionablecontent.net/view.php?comic=3276">Random</a></li>
+</ul>
+               \r
+\r
+                       <img src="https://www.questionablecontent.net/comics/4355.png">\r
+\r
+               <div class="row">\r
+       \r
+                       
+
+<ul class="menu" id="comicnav">
+<li><a href="view.php?comic=1">First</a></li>
+
+<li><a href="view.php?comic=4354">Previous</a></li>
+
+<li><a href="#">Next</a></li>
+
+<li><a href="#">Last</a></li>
+
+<li><a href="https://www.questionablecontent.net/view.php?comic=3248">Random</a></li>
+</ul>
+                       \r
+                       </div>\r
+               \r
+               <div class="row">\r
+                               <div class="media-object">\r
+                               <b>September 17, 2020 9:06pm</b>\r
+                               </div>\r
+               </div>\r
+               \r
+\r
+\r
+                       <div class="row" id="newspost">\r
+                               <div>\r
+                                                                                                                       <br>\r
+                                                                               <script type='text/javascript' src='https://ko-fi.com/widgets/widget_2.js'></script><script type='text/javascript'>kofiwidget2.init('Buy Me a Coffee', '#46b798', 'D1D5AKKN');kofiwidget2.draw();</script>\r
+                                                                               </br>\r
+                                                                               \r
+                                       <hr>\r
+                       </div>\r
+\r
+                       <div>\r
+                       <div class="row">\r
+                               <div class="small-12 medium-expand column">\r
+                                       <a href="https://topatoco.com/collections/jeph-jacques/products/qc-urls-print"><img src="https://www.questionablecontent.net/images/terribleurls.gif"></a>\r
+                               </div>\r
+                               <div class="small-12 medium-expand column">\r
+                                       <a href="https://topatoco.com/collections/jeph-jacques/products/qc-homking"><img src="https://www.questionablecontent.net/images/bupmer.jpg"></a>\r
+                               </div>\r
+                       </div>\r
+                       <div class="row">\r
+                               <div class="small-12 medium-expand column">\r
+                                               <script src="//ap.lijit.com/www/delivery/fpi.js?z=218211&width=300&height=250"></script>\r
+                               </div>\r
+                               <div class="small-12 medium-expand column">\r
+                                               <div data-pw-desk="med_rect_btf"></div>\r
+                               </div>\r
+                       </div>\r
+\r
+\r
+               </div>  \r
+                       \r
+                       <div class="row">\r
+                       <h5>Other Good Comics:</h5>\r
+                       </div>\r
+                       \r
+                       <div class="row">\r
+       \r
+                               • <a href="http://www.dumbingofage.com/">Dave Willis Eats Diapers</A>\r
+\r
+                                • <a href="http://www.clango.org">Diesel Sweeties</a>\r
+\r
+                                • <a href="http://www.doodleforfood.com">Doodle For Food</a>\r
+\r
+                               • <a href="http://www.gunnerkrigg.com/">Gunnerkrigg Court</a>\r
+\r
+                                • <a href="http://www.johnnywander.com">Johnny Wander</a>\r
+\r
+                               • <a href="http://www.jspowerhour.com">Junior Scientist Power Hour</a>\r
+\r
+                                • <a href="http://www.qwantz.com">Qwantz</a>\r
+\r
+                                • <a href="http://www.samandfuzzy.com">Sam & Fuzzy</a>\r
+\r
+                                • <a href="http://www.amultiverse.com">Scenes From A Multiverse</a>\r
+\r
+                               • <a href="http://somethingpositive.net/">Something Positive</a>\r
+\r
+                               • <a href="http://www.wastedtalent.ca">Wasted Talent</a>\r
+\r
+                               • <a href="http://www.wondermark.com">Wondermark</a>\r
+\r
+                               • <a href="https://www.xkcd.com">XKCD</a>\r
+                       \r
+\r
+                               <hr>\r
+                       </div>\r
+                       \r
+                       <div class="row">\r
+                                       \r
+                               <a href="https://www.questionablecontent.net/alice1.html">Alice Grove</a> • <a href="https://sednoid.bandcamp.com">Jeph's music on Bandcamp</a> • <a href="https://forums.questionablecontent.net">QC Forums</a> • <a href="https://www.paypal.com/xclick/business=jephco%40mac.com&no_note=1&tax=0&currency_code=USD">Make a donation</a>        \r
+                                                               • <a href="https://www.questionablecontent.net/privacy.php">Privacy Policy</a>\r
+                               \r
+                               • <a href="https://www.questionablecontent.net/images/dord.png">dord</a>\r
+                               \r
+                               • <a href="https://www.questionablecontent.net/urls.html">urls</a>\r
+                                               <hr>\r
+                       \r
+                       \r
+                       </div>\r
+\r
+                       \r
+               \r
+                       \r
+       </div>\r
+       \r
+                       \r
+\r
+       <div class="small-2 medium-expand column">\r
+                       \r
+                       <div class="row">\r
+                       \r
+                               <div data-pw-desk="sky_atf"></div>      \r
+                                               \r
+                       </div>\r
+                       \r
+                       <div class="row">\r
+                                       \r
+                               <iframe src="/safe-frame.php?mode=AdSense&adunit=5308843506" frameborder="0" width="100%" scrolling="no" sandbox="allow-scripts allow-top-navigation-by-user-activation allow-same-origin allow-forms"></iframe>\r
+                               \r
+                       </div>\r
+                       \r
+               </div>\r
+               \r
+                         <script src="js/vendor/jquery.min.js"></script>
+    <script src="js/vendor/what-input.min.js"></script>
+    <script src="js/foundation.min.js"></script>
+    <script>
+      $(document).foundation();
+    </script>
+<div class="clear"> </div>
+<!-- Start Quantcast tag -->
+<script type="text/javascript">
+_qoptions={
+qacct:"p-52tPwtcDlSoqU",
+labels:"Pop Culture Channel"
+};
+</script>
+
+
+   <script src="js/vendor/jquery.js"></script>
+    <script src="js/vendor/what-input.js"></script>
+    <script src="js/vendor/foundation.js"></script>
+    <script src="js/app.js"></script>
+
+<!-- BAROMETRIC FIVT -->
+<script type="text/javascript">
+ (function(){ var ord = Math.random() * 10000000000;var elem = document.createElement("script");
+ elem.src = (document.location.protocol == "https:" ? "https://" : "http://") + "trkn.us/info/request.js?sid=81395407-05ad-4188-ae6e-732b205fbcdb&ord="+ord;
+ elem.async = true;elem.type = "text/javascript";var scpt = document.getElementsByTagName("script")[0];
+ scpt.parentNode.insertBefore(elem, scpt); })();
+</script>
+<noscript><div style="display:none;"><img src="//trkn.us/info/?sid=81395407-05ad-4188-ae6e-732b205fbcdb" border="0" height="1" width="1" alt="Barometric" /></div></noscript>
+<!-- END BAROMETRIC FIVT --><p>\r
+<div class="clear"> </div>\r
+\r
+<iframe src="/safe-frame.php?mode=AdSense&adunit=6553760051" frameborder="0" width="100%" scrolling="no" sandbox="allow-scripts allow-same-origin allow-forms allow-top-navigation-by-user-activation"></iframe>\r
+\r
+</p>\r
+\r
+</div>\r
+</div>\r
+\r
+\r
+\r
+       </div>\r
+       <script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js">\r
+</script>\r
+    <script src="js/vendor/jquery.js"></script>\r
+    <script src="js/vendor/what-input.js"></script>\r
+    <script src="js/vendor/foundation.js"></script>\r
+    <script src="js/app.js"></script>\r
+    \r
+                 <script type="text/javascript">\r
+                                jQuery('iframe').on('load',function(e){\r
+                                this.height = this.contentWindow.document.body.scrollHeight + "px";\r
+                                this.width = this.contentWindow.document.body.scrollWidth + "px";\r
+                                })\r
+                                </script>\r
+                                <!-- BAROMETRIC FIVT -->\r
+<script type="text/javascript">\r
+ (function(){ var ord = Math.random() * 10000000000;var elem = document.createElement("script");\r
+ elem.src = (document.location.protocol == "https:" ? "https://" : "http://") + "trkn.us/info/request.js?sid=81395407-05ad-4188-ae6e-732b205fbcdb&ord="+ord;\r
+ elem.async = true;elem.type = "text/javascript";var scpt = document.getElementsByTagName("script")[0];\r
+ scpt.parentNode.insertBefore(elem, scpt); })();\r
+</script>\r
+<noscript><div style="display:none;"><img src="//trkn.us/info/?sid=81395407-05ad-4188-ae6e-732b205fbcdb" border="0" height="1" width="1" alt="Barometric" /></div></noscript>\r
+<!-- END BAROMETRIC FIVT -->\r
+  </body>\r
+</html>\r