diff --git a/mirror-img.asd b/mirror-img.asd index 93051aa..d0cf441 100644 --- a/mirror-img.asd +++ b/mirror-img.asd @@ -29,12 +29,11 @@ :license "GPLv3" :author "Jaidyn Ann " :description "Tests for the the mirror-img package." - :depends-on (:mirror-img :lisp-unit2) + :depends-on (:mirror-img :hunchentoot :lisp-unit2) :components ((:file "t/mirror-img"))) -;; Following method borrowed from lisp-unit2’s documentation: +;; Following method tweaked from lisp-unit2’s documentation: ;; https://github.com/AccelerationNet/lisp-unit2/blob/master/README.md#asdf (defmethod asdf:perform ((o asdf:test-op) (c (eql (asdf:find-system :mirror-img/tests)))) (eval (read-from-string - "(lisp-unit2:with-summary () - (lisp-unit2:run-tests :package :mirror-img/tests))"))) + "(mirror-img/tests:run)"))) diff --git a/t/mirror-img.lisp b/t/mirror-img.lisp index 80076a4..1d7eb4d 100644 --- a/t/mirror-img.lisp +++ b/t/mirror-img.lisp @@ -16,15 +16,74 @@ ;; along with this program. If not, see . (defpackage :mirror-img/tests - (:use :cl :lisp-unit2)) + (:use :cl :lisp-unit2) + (:export :run)) (in-package :mirror-img/tests) +(defparameter *mirror-img-result* nil) + +(defun relative-pathname (path) + (asdf:system-relative-pathname :mirror-img/tests path)) + +(defun run () + (let* ((doc-root (relative-pathname "t/testing-website/")) + (acceptor (make-instance 'hunchentoot:easy-acceptor + :port 4242 + :document-root doc-root)) + (server (hunchentoot:start acceptor))) + (lisp-unit2:with-summary () + (run-tests :package :mirror-img/tests) + (hunchentoot:stop server)))) + +(define-test mirror-img (:tags '(mirror-img)) + (assert-eq + (stringp + (setq *mirror-img-result* + (mirror-img:mirror-img (relative-pathname "t/testing-website/index.html") + "tmp"))) + 'T)) + +(define-test mirror-img.files-mirrored (:tags '(mirror-img)) + (assert-equal + (sort (mapcar #'pathname-name + (uiop:directory-files (relative-pathname "t/tmp/localhost/"))) + #'string-lessp) + '("café" "fireplace" "merry christmas!!! ^_^" "more_calming" "style" "welcoming you"))) + +(define-test mirror-img.correct-urls (:tags '(mirror-img)) + (assert-equal + (sort (mirror-img::linked-urls + (lquery:$ (lquery:initialize *mirror-img-result*))) + #'string-lessp) + '("tmp/localhost/café.jpg" + "tmp/localhost/classy_fireplace.jpg" + "tmp/localhost/fireplace.jpg" + "tmp/localhost/merry christmas!!! ^_^.jpg" + "tmp/localhost/more_calming.jpg" + "tmp/localhost/style.css" + "tmp/localhost/welcoming you.jpg"))) + (define-test mirrored-pathname (:tags '(base)) (assert-equal - (mirror-img::mirrored-pathname "https://invalid.tld/dir/bird apple.txt" #p"base/") + (mirror-img::mirrored-pathname "https://invalid.tld/dir/bird apple.txt" + :base-dir #p"base/") #p"base/invalid.tld/bird apple.txt")) +(define-test linked-urls (:tags '(dom)) + (assert-equal + (sort (mirror-img::linked-urls + (lquery:$ (lquery:initialize + (relative-pathname "t/testing-website/index.html")))) + #'string-lessp) + '("http://localhost:4242/res/img/b/fireplace.jpg" + "http://localhost:4242/res/img/b/I’m trying hard to randomly name these directories/more_calming.jpg" + "http://localhost:4242/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas%3F!/classy_fireplace.jpg" + "http://localhost:4242/res/img/level-2/café.jpg" + "http://localhost:4242/res/img/merry christmas!!! ^_^.jpg" + "http://localhost:4242/res/style.css" + "http://localhost:4242/res/welcoming you.jpg"))) + (define-test url-encode-uri.space (:tags '(util)) (assert-equal (mirror-img::url-encode-uri "https://invalid.tld/dad alive.jpg") diff --git a/t/testing-website/index.html b/t/testing-website/index.html new file mode 100644 index 0000000..972d573 --- /dev/null +++ b/t/testing-website/index.html @@ -0,0 +1,88 @@ + + + + mirror-img’s testing site! ♥ + + + + + +
+

A sultry welcome to you

+ +
+ +
Welcome~ + + 🔗 + +
+
+ +

Take a seat over here by the fire, take a load off. Yea, just like that. Isn’t it warm, here? The fire always puts me at ease, and I feel myself drifting… somewhere… drifting… just like that. I’m going to count down from ten, and you’ll feel yourself drifting deeper, and deeper, and deeper.

+ + +

Ten…

+

Nine…

+ +
+ +
You’re safe by the fire. + + 🔗 + +
+
+ +

Eight…

+

Seven…

+ +
+ +
Slide down, further and further~ + + 🔗 + +
+
+ +

Six…

+

Five…

+ +
+ +
Let yourself steep… + + 🔗 + +
+
+ +

Four…

+

Three…

+ +
+ +
You’re surrounded by your superiors. + + 🔗 + +
+
+ +

Two…

+

One…

+ +
+ +
AAAAAAAA!!! + + 🔗 + +
+
+ +

MERRY FUCKING CHRISTMAS, MOTHERFUCKER!!!!!! YOU’VE BEEN CHRISTMAS JOKED!!!!!!!!!!!

+
+ + diff --git a/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/more_calming.jpg b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/more_calming.jpg new file mode 100644 index 0000000..d940958 Binary files /dev/null and b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/more_calming.jpg differ diff --git a/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/more_calming.txt b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/more_calming.txt new file mode 100644 index 0000000..1b092d1 --- /dev/null +++ b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/more_calming.txt @@ -0,0 +1,2 @@ +https://twitter.com/tao15102/status/1748663360105947389 +By tao15102 diff --git a/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas?!/classy_fireplace.jpg b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas?!/classy_fireplace.jpg new file mode 100644 index 0000000..8baf1a1 Binary files /dev/null and b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas?!/classy_fireplace.jpg differ diff --git a/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas?!/classy_fireplace.txt b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas?!/classy_fireplace.txt new file mode 100644 index 0000000..a3c4219 --- /dev/null +++ b/t/testing-website/res/img/b/I’m trying hard to randomly name these directories/ĉu ĉi tio sufiĉe hazardas?!/classy_fireplace.txt @@ -0,0 +1,2 @@ +https://www.pixiv.net/artworks/71223241 +By オギモトズキン diff --git a/t/testing-website/res/img/b/fireplace.jpg b/t/testing-website/res/img/b/fireplace.jpg new file mode 100644 index 0000000..4f001d9 Binary files /dev/null and b/t/testing-website/res/img/b/fireplace.jpg differ diff --git a/t/testing-website/res/img/b/fireplace.txt b/t/testing-website/res/img/b/fireplace.txt new file mode 100644 index 0000000..6bda2c7 --- /dev/null +++ b/t/testing-website/res/img/b/fireplace.txt @@ -0,0 +1,2 @@ +https://www.pixiv.net/artworks/115188449 +By フロリダちゃん diff --git a/t/testing-website/res/img/level-2/café.jpg b/t/testing-website/res/img/level-2/café.jpg new file mode 100644 index 0000000..6b198c3 Binary files /dev/null and b/t/testing-website/res/img/level-2/café.jpg differ diff --git a/t/testing-website/res/img/level-2/café.txt b/t/testing-website/res/img/level-2/café.txt new file mode 100644 index 0000000..11413ef --- /dev/null +++ b/t/testing-website/res/img/level-2/café.txt @@ -0,0 +1,2 @@ +https://twitter.com/yukichi_nya___/status/1608750624681918465 +By yukichi_nya___ diff --git a/t/testing-website/res/img/merry christmas!!! ^_^.jpg b/t/testing-website/res/img/merry christmas!!! ^_^.jpg new file mode 100644 index 0000000..6219876 Binary files /dev/null and b/t/testing-website/res/img/merry christmas!!! ^_^.jpg differ diff --git a/t/testing-website/res/img/merry christmas!!! ^_^.txt b/t/testing-website/res/img/merry christmas!!! ^_^.txt new file mode 100644 index 0000000..d94b726 --- /dev/null +++ b/t/testing-website/res/img/merry christmas!!! ^_^.txt @@ -0,0 +1,2 @@ +https://www.pixiv.net/artworks/86493795 +By Ema3 diff --git a/t/testing-website/res/style.css b/t/testing-website/res/style.css new file mode 100644 index 0000000..8cdf494 --- /dev/null +++ b/t/testing-website/res/style.css @@ -0,0 +1,22 @@ +body { + background-color: #d7d7af; +} + +main { + max-width: 800px; + margin-left: auto; + margin-right: auto; + text-align: center; + background-color: #ffffd7; + padding: 10px; + border-radius: 10px; +} + +img { + border-radius: 10px; +} + +figure { + border: 2px dotted; + padding: 5px; +} diff --git a/t/testing-website/res/welcoming you.jpg b/t/testing-website/res/welcoming you.jpg new file mode 100644 index 0000000..ccac08b Binary files /dev/null and b/t/testing-website/res/welcoming you.jpg differ diff --git a/t/testing-website/res/welcoming you.txt b/t/testing-website/res/welcoming you.txt new file mode 100644 index 0000000..1c72430 --- /dev/null +++ b/t/testing-website/res/welcoming you.txt @@ -0,0 +1,2 @@ +https://twitter.com/Distrbeachboy/status/1758538124785852426 +By Distrbeachboy