3
3
[clojure.test :refer :all ]
4
4
[wp2static-test.test :as test]))
5
5
6
- (defn get-crawled-file [path]
7
- (slurp (str " wordpress/wp-content/uploads/wp2static-crawled-site/" path)))
6
+ (defn get-crawled-file [wp path]
7
+ (slurp (str (get-in wp [:paths :uploads ]) " /wp2static-crawled-site/" path)))
8
+
9
+ (defmacro with-robots-txt [wp s & body]
10
+ `(let [path# (str (get-in ~wp [:paths :doc-root ]) " /robots.txt" )]
11
+ (try
12
+ (spit path# ~s)
13
+ (do ~@body)
14
+ (finally
15
+ (test/sh! {} " rm" " -f" path#)))))
8
16
9
17
(def robots-sitemap-404
10
18
" User-agent: *
@@ -20,16 +28,21 @@ Sitemap: http://localhost:7000/does-not-exist.xml")
20
28
<sitemapindex xmlns=\" http://www.sitemaps.org/schemas/sitemap/0.9\" ><sitemap><loc>http://localhost:7000/does-not-exist.xml</loc></sitemap></sitemapindex>" )
21
29
22
30
(deftest test-robots-404
23
- (testing " robots.txt sitemap URLs that return 404s are ignored"
24
- (test/with-test-system [_]
25
- (try
26
- (spit " wordpress/robots.txt" robots-sitemap-404)
27
- (spit " wordpress/wp-content/sitemap.xml" sitemap-with-404)
28
- (is (zero? (:exit (test/wp-cli!
29
- {:expect-warnings {#".*Got 404 for sitemap.*" 1 }}
30
- " wp2static" " detect" ))))
31
- (finally
32
- (test/sh! {} " rm" " wordpress/robots.txt" " wordpress/wp-content/sitemap.xml" ))))))
31
+ (test/with-test-system [system {}]
32
+ (doseq [wp (vals (:wordpresses system))
33
+ :let [wp-cli! #(apply test/wp-cli! {:path (get-in wp [:paths :cli ])} %&)]]
34
+ (when (get-in wp [:features :sitemaps? ])
35
+ (test/testing [wp " robots.txt sitemap URLs that return 404s are ignored" ]
36
+ (with-robots-txt wp robots-sitemap-404
37
+ (let [sitemap-path (str (get-in wp [:paths :wp-content ]) " /sitemap.xml" )]
38
+ (try
39
+ (spit sitemap-path sitemap-with-404)
40
+ (is (zero? (:exit (test/wp-cli!
41
+ {:expect-warnings {#".*Got 404 for sitemap.*" 1 }
42
+ :path (get-in wp [:paths :cli ])}
43
+ " wp2static" " detect" ))))
44
+ (finally
45
+ (test/sh! {} " rm" " -f" sitemap-path))))))))))
33
46
34
47
(def robots-sitemap-slashes
35
48
" User-agent: *
@@ -39,12 +52,13 @@ Allow: /wp-admin/admin-ajax.php
39
52
Sitemap: http://localhost:7000//wp-sitemap.xml" )
40
53
41
54
(deftest test-robots-sitemap-slashes
42
- (testing " robots.txt sitemap URLs with double slashes are processed"
43
- (test/with-test-system [_]
44
- (try
45
- (spit " wordpress/robots.txt" robots-sitemap-slashes)
46
- (test/wp-cli! {} " wp2static" " detect" )
47
- (test/wp-cli! {} " wp2static" " crawl" )
48
- (is (str/includes? (get-crawled-file " wp-sitemap-posts-post-1.xml" ) " http://localhost:7000/hello-world/" ))
49
- (finally
50
- (test/sh! {} " rm" " wordpress/robots.txt" ))))))
55
+ (test/with-test-system [system {}]
56
+ (doseq [wp (vals (:wordpresses system))
57
+ :let [wp-cli! #(apply test/wp-cli! {:path (get-in wp [:paths :cli ])} %&)]]
58
+ (when (get-in wp [:features :sitemaps? ])
59
+ (test/testing [wp " robots.txt sitemap URLs with double slashes are processed" ]
60
+ (with-robots-txt wp robots-sitemap-slashes
61
+ (wp-cli! " wp2static" " detect" )
62
+ (wp-cli! " wp2static" " crawl" )
63
+ (is (str/includes? (get-crawled-file wp " wp-sitemap-posts-post-1.xml" )
64
+ (str (get-in wp [:paths :home ] " hello-world/" ))))))))))
0 commit comments