Skip to content

Commit 31177df

Browse files
committed
Include Bedrock in each integration test
1 parent c65a445 commit 31177df

File tree

6 files changed

+110
-58
lines changed

6 files changed

+110
-58
lines changed

integration-tests/clj/wp2static_test/main.clj

+23-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@
9292
(str "bedrock.sh exited with code " code)
9393
{:code code}))))
9494
bedrock)
95-
:name "Bedrock Initializer"
95+
:name "Bedrock"
9696
:join? true
97-
:open-f (fn [_] (popen ["bash" "bedrock.sh"]))}))
97+
:open-f (fn [_] (popen ["bash" "bedrock.sh"]))
98+
99+
:features {:sitemaps? false}
100+
:paths {:cli "bedrock/web/wp"
101+
:doc-root "bedrock/web"
102+
:plugins "bedrock/web/app/plugins"
103+
:site "/wp/"
104+
:uploads "bedrock/web/app/uploads"
105+
:wp-content "bedrock/web/wp/wp-content"}
106+
:urls {:home "http://localhost:7001"}}))
98107

99108
(defn wordpress []
100109
(shell-process
@@ -106,9 +115,18 @@
106115
(str "wordpress.sh exited with code " code)
107116
{:code code}))))
108117
wordpress)
109-
:name "WordPress Initializer"
118+
:name "WordPress"
110119
:join? true
111-
:open-f (fn [_] (popen ["bash" "wordpress.sh"]))}))
120+
:open-f (fn [_] (popen ["bash" "wordpress.sh"]))
121+
122+
:features {:sitemaps? true}
123+
:paths {:cli "wordpress"
124+
:doc-root "wordpress"
125+
:plugins "wordpress/wp-content/plugins"
126+
:site "/"
127+
:uploads "wordpress/wp-content/uploads"
128+
:wp-content "wordpress/wp-content"}
129+
:urls {:home "http://localhost:7000"}}))
112130

113131
(defn system-map []
114132
(component/system-map
@@ -117,6 +135,7 @@
117135
:nginx (component/using (nginx) [:wordpress])
118136
:php-fpm (component/using (php-fpm) [:mariadb])
119137
:wordpress (component/using (wordpress) [:mariadb :php-fpm])
138+
:wordpresses (component/using {} [:bedrock :wordpress])
120139
:wp2static (component/using (wp2static) [:bedrock :wordpress])))
121140

122141
(defonce system (atom nil))

integration-tests/clj/wp2static_test/test.clj

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
result))
3030

3131
(defn wp-cli! [opts & args]
32-
(apply sh! opts "wp" (concat args ["--path=wordpress"])))
32+
(apply sh! opts "wp" (concat args [(str "--path=" (:path opts "wordpress"))])))
3333

3434
(defn test [opts]
3535
;; https://clojureverse.org/t/why-doesnt-my-program-exit/3754/8
@@ -42,3 +42,8 @@
4242
`(let [~name (main/start!)]
4343
(core/clean-wp2static-cache!)
4444
~@body))
45+
46+
(defmacro testing [[wp string] & body]
47+
`(clojure.test/testing (str "[" (:name ~wp) "] " ~string)
48+
~@body))
49+

integration-tests/test/wp2static_test/crawl_test.clj

+12-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
[clojure.test :refer :all]
44
[wp2static-test.test :as test]))
55

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)))
88

99
(deftest test-crawled-site
10-
(test/with-test-system [_]
11-
(test/wp-cli! {} "wp2static" "detect")
12-
(test/wp-cli! {} "wp2static" "crawl")
13-
(is (str/includes? (get-crawled-file "index.html") "Welcome to WordPress"))
14-
(is (str/includes? (get-crawled-file "robots.txt") "Sitemap: http://localhost:7000/wp-sitemap.xml"))))
10+
(test/with-test-system [system {}]
11+
(doseq [wp (vals (:wordpresses system))
12+
:let [wp-cli! #(apply test/wp-cli! {:path (get-in wp [:paths :cli])} %&)]]
13+
(test/testing [wp "Crawling works"]
14+
(wp-cli! "wp2static" "detect")
15+
(wp-cli! "wp2static" "crawl")
16+
(is (str/includes? (get-crawled-file wp "index.html")
17+
"Welcome to WordPress"))
18+
(is (str/includes? (get-crawled-file wp "robots.txt")
19+
(str "Disallow: " (get-in wp [:paths :site]) "wp-admin/")))))))

integration-tests/test/wp2static_test/detect_test.clj

+35-21
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
[clojure.test :refer :all]
44
[wp2static-test.test :as test]))
55

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#)))))
816

917
(def robots-sitemap-404
1018
"User-agent: *
@@ -20,16 +28,21 @@ Sitemap: http://localhost:7000/does-not-exist.xml")
2028
<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"><sitemap><loc>http://localhost:7000/does-not-exist.xml</loc></sitemap></sitemapindex>")
2129

2230
(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))))))))))
3346

3447
(def robots-sitemap-slashes
3548
"User-agent: *
@@ -39,12 +52,13 @@ Allow: /wp-admin/admin-ajax.php
3952
Sitemap: http://localhost:7000//wp-sitemap.xml")
4053

4154
(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/"))))))))))

integration-tests/test/wp2static_test/options_test.clj

+19-14
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ function processQueueImmediately_filter ( $val ) {
2020
add_filter( 'wp2static_option_processQueueImmediately', 'processQueueImmediately_filter' );")
2121

2222
(deftest test-option-filters
23-
(test/with-test-system [_]
24-
(testing "wp2static_option_* filters work"
25-
(is (= "0" (-> (test/wp-cli! {} "wp2static" "options" "get" "processQueueImmediately")
26-
:out
27-
str/trim)))
28-
(try
29-
(test/sh! {} "mkdir" "wordpress/wp-content/plugins/options-test")
30-
(spit "wordpress/wp-content/plugins/options-test/options-test.php"
31-
options-test-filters)
32-
(test/wp-cli! {} "plugin" "activate" "options-test")
33-
(is (= "1" (-> (test/wp-cli! {} "wp2static" "options" "get" "processQueueImmediately")
23+
(test/with-test-system [system {}]
24+
(doseq [wp (vals (:wordpresses system))
25+
:let [wp-cli! #(apply test/wp-cli! {:path (get-in wp [:paths :cli])} %&)
26+
plugins-dir (get-in wp [:paths :plugins])]]
27+
(test/testing [wp "wp2static_option_* filters work"]
28+
(is (= "0" (-> (test/wp-cli! {} "wp2static" "options" "get" "processQueueImmediately")
3429
:out
3530
str/trim)))
36-
(test/wp-cli! {} "plugin" "deactivate" "options-test")
37-
(finally
38-
(test/sh! {} "rm" "-rf" "wordpress/wp-content/plugins/options-test"))))))
31+
(try
32+
(test/sh! {} "mkdir" "options-test"
33+
:dir plugins-dir)
34+
(spit (str plugins-dir "/options-test/options-test.php")
35+
options-test-filters)
36+
(wp-cli! "plugin" "activate" "options-test")
37+
(is (= "1" (-> (wp-cli! "wp2static" "options" "get" "processQueueImmediately")
38+
:out
39+
str/trim)))
40+
(wp-cli! "plugin" "deactivate" "options-test")
41+
(finally
42+
(test/sh! {} "rm" "-rf" "options-test"
43+
:dir plugins-dir)))))))

integration-tests/test/wp2static_test/post_process_test.clj

+15-11
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
[clojure.test :refer :all]
44
[wp2static-test.test :as test]))
55

6-
(defn get-processed-file [path]
7-
(slurp (str "wordpress/wp-content/uploads/wp2static-processed-site/" path)))
6+
(defn get-processed-file [wp path]
7+
(slurp (str (get-in wp [:paths :uploads]) "/wp2static-processed-site/" path)))
88

99
(deftest test-processed-site
10-
(test/with-test-system [_]
11-
(test/wp-cli! {} "wp2static" "detect")
12-
(test/wp-cli! {} "wp2static" "crawl")
13-
(test/wp-cli! {} "wp2static" "post_process")
14-
(let [index (get-processed-file "index.html")]
15-
(is (str/includes? index "Welcome to WordPress"))
16-
(testing "Rewrites work"
17-
(is (str/includes? index "<a href=\"https://example.com/hello-world/\">"))
18-
(is (str/includes? (get-processed-file "robots.txt") "Sitemap: https://example.com/wp-sitemap.xml"))))))
10+
(test/with-test-system [system {}]
11+
(doseq [wp (vals (:wordpresses system))
12+
:let [wp-cli! #(apply test/wp-cli! {:path (get-in wp [:paths :cli])} %&)]]
13+
(test/testing [wp "Post-processing works"]
14+
(wp-cli! "wp2static" "detect")
15+
(wp-cli! "wp2static" "crawl")
16+
(wp-cli! "wp2static" "post_process")
17+
(let [index (get-processed-file wp "index.html")]
18+
(is (str/includes? index "Welcome to WordPress"))
19+
(testing "& URL rewriting works"
20+
(is (str/includes? index "<a href=\"https://example.com/hello-world/\">"))
21+
(when (get-in wp [:features :sitemaps?])
22+
(is (str/includes? (get-processed-file wp "robots.txt") "Sitemap: https://example.com/wp-sitemap.xml")))))))))

0 commit comments

Comments
 (0)