wordpress_client 0.0.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +30 -0
- data/.codeclimate.yml +23 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +147 -90
- data/.yardopts +1 -0
- data/Changelog.md +16 -0
- data/Gemfile +6 -1
- data/README.md +48 -14
- data/Rakefile +37 -0
- data/lib/wordpress_client/category.rb +2 -0
- data/lib/wordpress_client/client.rb +235 -79
- data/lib/wordpress_client/connection.rb +10 -10
- data/lib/wordpress_client/errors.rb +41 -6
- data/lib/wordpress_client/media.rb +49 -1
- data/lib/wordpress_client/media_parser.rb +3 -0
- data/lib/wordpress_client/paginated_collection.rb +61 -4
- data/lib/wordpress_client/post.rb +63 -16
- data/lib/wordpress_client/post_parser.rb +12 -39
- data/lib/wordpress_client/rest_parser.rb +4 -0
- data/lib/wordpress_client/tag.rb +2 -0
- data/lib/wordpress_client/term.rb +30 -0
- data/lib/wordpress_client/version.rb +5 -1
- data/lib/wordpress_client.rb +21 -5
- data/spec/client_spec.rb +17 -181
- data/spec/connection_spec.rb +15 -14
- data/spec/docker/Dockerfile +35 -10
- data/spec/docker/README.md +53 -16
- data/spec/docker/dbdump.sql.gz +0 -0
- data/spec/docker/restore-dbdump.sh +2 -2
- data/spec/docker/yum.repos.d/CentOS-Base.repo +25 -0
- data/spec/fixtures/image-media.json +1 -1
- data/spec/fixtures/post-with-metadata.json +99 -1
- data/spec/fixtures/simple-post.json +324 -1
- data/spec/integration/attachments_crud_spec.rb +1 -1
- data/spec/integration/posts_crud_spec.rb +1 -1
- data/spec/integration/posts_finding_spec.rb +0 -69
- data/spec/integration/posts_metadata_spec.rb +11 -11
- data/spec/integration/posts_with_attachments_spec.rb +20 -6
- data/spec/media_spec.rb +14 -0
- data/spec/post_spec.rb +5 -31
- data/spec/spec_helper.rb +1 -0
- data/spec/support/docker_runner.rb +33 -13
- data/spec/support/wordpress_server.rb +112 -74
- data/wordpress_client.gemspec +17 -17
- metadata +43 -31
- data/.hound.yml +0 -2
- data/.ruby-version +0 -1
- data/circle.yml +0 -3
- data/lib/wordpress_client/replace_metadata.rb +0 -81
- data/lib/wordpress_client/replace_terms.rb +0 -62
- data/spec/fixtures/post-with-forbidden-metadata.json +0 -1
- data/spec/integration/category_assignment_spec.rb +0 -29
- data/spec/integration/tag_assignment_spec.rb +0 -29
- data/spec/replace_metadata_spec.rb +0 -56
- data/spec/replace_terms_spec.rb +0 -51
data/spec/client_spec.rb
CHANGED
@@ -22,30 +22,6 @@ module WordpressClient
|
|
22
22
|
|
23
23
|
expect(client.posts).to eq []
|
24
24
|
end
|
25
|
-
|
26
|
-
it "can filter on category slugs" do
|
27
|
-
expect(connection).to receive(:get_multiple).with(
|
28
|
-
Post, "posts", hash_including(filter: {category_name: "my-cat"})
|
29
|
-
).and_return []
|
30
|
-
|
31
|
-
expect(client.posts(category_slug: "my-cat")).to eq []
|
32
|
-
end
|
33
|
-
|
34
|
-
it "can filter on tag slugs" do
|
35
|
-
expect(connection).to receive(:get_multiple).with(
|
36
|
-
Post, "posts", hash_including(filter: {tag: "my-cat"})
|
37
|
-
).and_return []
|
38
|
-
|
39
|
-
expect(client.posts(tag_slug: "my-cat")).to eq []
|
40
|
-
end
|
41
|
-
|
42
|
-
it "can filter on tag and category slugs" do
|
43
|
-
expect(connection).to receive(:get_multiple).with(
|
44
|
-
Post, "posts", hash_including(filter: {tag: "my-cat", category_name: "my-dog"})
|
45
|
-
).and_return []
|
46
|
-
|
47
|
-
expect(client.posts(tag_slug: "my-cat", category_slug: "my-dog")).to eq []
|
48
|
-
end
|
49
25
|
end
|
50
26
|
|
51
27
|
describe "fetching a single post" do
|
@@ -53,31 +29,12 @@ module WordpressClient
|
|
53
29
|
post = instance_double(Post)
|
54
30
|
|
55
31
|
expect(connection).to receive(:get).with(
|
56
|
-
Post, "posts/5", _embed: nil
|
32
|
+
Post, "posts/5", _embed: nil
|
57
33
|
).and_return post
|
58
34
|
|
59
35
|
expect(client.find_post(5)).to eq post
|
60
36
|
end
|
61
37
|
|
62
|
-
it "can find using a slug" do
|
63
|
-
post = instance_double(Post)
|
64
|
-
|
65
|
-
expect(connection).to receive(:get_multiple).with(
|
66
|
-
Post, "posts", hash_including(filter: {name: "my-slug"})
|
67
|
-
).and_return [post]
|
68
|
-
|
69
|
-
expect(client.find_by_slug("my-slug")).to eq post
|
70
|
-
end
|
71
|
-
|
72
|
-
it "raises NotFoundError when trying to find by slug yields no posts" do
|
73
|
-
expect(connection).to receive(:get_multiple).with(
|
74
|
-
Post, "posts", hash_including(filter: {name: "my-slug"}, per_page: 1)
|
75
|
-
).and_return []
|
76
|
-
|
77
|
-
expect {
|
78
|
-
client.find_by_slug("my-slug")
|
79
|
-
}.to raise_error(NotFoundError, /my-slug/)
|
80
|
-
end
|
81
38
|
end
|
82
39
|
|
83
40
|
describe "creating a post" do
|
@@ -93,147 +50,26 @@ module WordpressClient
|
|
93
50
|
# it's also very possible that we need to fetch the post again after
|
94
51
|
# doing other things to it.
|
95
52
|
allow(connection).to receive(:get).with(
|
96
|
-
Post, "posts/5"
|
53
|
+
Post, "posts/5"
|
97
54
|
).and_return(post)
|
98
55
|
|
99
56
|
expect(client.create_post(attributes)).to eq post
|
100
57
|
end
|
101
58
|
|
102
|
-
it "adds metadata to the post" do
|
103
|
-
post = instance_double(Post, id: 5)
|
104
|
-
allow(connection).to receive(:create).and_return(post)
|
105
|
-
|
106
|
-
expect(ReplaceMetadata).to receive(:apply).with(
|
107
|
-
connection, post, {"hello" => "world"}
|
108
|
-
).and_return(0)
|
109
|
-
|
110
|
-
client.create_post(title: "Foo", meta: {"hello" => "world"})
|
111
|
-
end
|
112
|
-
|
113
|
-
it "sets categories of the post" do
|
114
|
-
post = instance_double(Post, id: 5)
|
115
|
-
allow(connection).to receive(:create).and_return(post)
|
116
|
-
|
117
|
-
expect(ReplaceTerms).to receive(:apply_categories).with(
|
118
|
-
connection, post, [1, 3, 7]
|
119
|
-
).and_return(0)
|
120
|
-
|
121
|
-
client.create_post(title: "Foo", category_ids: [1, 3, 7])
|
122
|
-
end
|
123
|
-
|
124
|
-
it "sets tags of the post" do
|
125
|
-
post = instance_double(Post, id: 5)
|
126
|
-
allow(connection).to receive(:create).and_return(post)
|
127
|
-
|
128
|
-
expect(ReplaceTerms).to receive(:apply_tags).with(
|
129
|
-
connection, post, [1, 3, 7]
|
130
|
-
).and_return(0)
|
131
|
-
|
132
|
-
client.create_post(title: "Foo", tag_ids: [1, 3, 7])
|
133
|
-
end
|
134
|
-
|
135
|
-
it "refreshes the post if terms or categories changed" do
|
136
|
-
post = instance_double(Post, id: 5)
|
137
|
-
allow(connection).to receive(:create).and_return(post)
|
138
|
-
|
139
|
-
expect(ReplaceTerms).to receive(:apply_tags).and_return(1)
|
140
|
-
expect(ReplaceTerms).to receive(:apply_categories).and_return(1)
|
141
|
-
expect(ReplaceMetadata).to receive(:apply).and_return(1)
|
142
|
-
|
143
|
-
expect(connection).to receive(:get).with(
|
144
|
-
Post, "posts/5", hash_including(_embed: nil)
|
145
|
-
).and_return(post)
|
146
|
-
|
147
|
-
client.create_post(title: "Foo", tag_ids: [], category_ids: [], meta: {})
|
148
|
-
end
|
149
|
-
|
150
|
-
it "does not refresh the post if neither terms nor categories changed" do
|
151
|
-
post = instance_double(Post, id: 5)
|
152
|
-
allow(connection).to receive(:create).and_return(post)
|
153
|
-
|
154
|
-
expect(ReplaceTerms).to receive(:apply_tags).and_return(0)
|
155
|
-
expect(ReplaceTerms).to receive(:apply_categories).and_return(0)
|
156
|
-
expect(ReplaceMetadata).to receive(:apply).and_return(0)
|
157
|
-
|
158
|
-
expect(connection).to_not receive(:get)
|
159
|
-
|
160
|
-
client.create_post(title: "Foo", tag_ids: [], category_ids: [], meta: {})
|
161
|
-
end
|
162
59
|
end
|
163
60
|
|
164
61
|
describe "updating a post" do
|
165
62
|
it "embeds linked resources" do
|
166
63
|
post = instance_double(Post)
|
167
64
|
|
168
|
-
expect(connection).to receive(:
|
169
|
-
Post, "posts/5
|
65
|
+
expect(connection).to receive(:put).with(
|
66
|
+
Post, "posts/5", hash_including(title: "Foo")
|
170
67
|
).and_return(post)
|
171
68
|
|
172
69
|
expect(client.update_post(5, title: "Foo")).to eq post
|
173
70
|
end
|
174
71
|
|
175
|
-
it "adds metadata to the post" do
|
176
|
-
post = instance_double(Post, id: 5)
|
177
|
-
allow(connection).to receive(:patch).and_return(post)
|
178
|
-
|
179
|
-
expect(ReplaceMetadata).to receive(:apply).with(
|
180
|
-
connection, post, {"hello" => "world"}
|
181
|
-
).and_return(0)
|
182
|
-
|
183
|
-
client.update_post(5, title: "Foo", meta: {"hello" => "world"})
|
184
|
-
end
|
185
|
-
|
186
|
-
it "changes categories of the post" do
|
187
|
-
post = instance_double(Post, id: 5)
|
188
|
-
allow(connection).to receive(:patch).and_return(post)
|
189
|
-
|
190
|
-
expect(ReplaceTerms).to receive(:apply_categories).with(
|
191
|
-
connection, post, [1, 3, 7]
|
192
|
-
).and_return(0)
|
193
|
-
|
194
|
-
client.update_post(5, title: "Foo", category_ids: [1, 3, 7])
|
195
|
-
end
|
196
|
-
|
197
|
-
it "changes tags of the post" do
|
198
|
-
post = instance_double(Post, id: 5)
|
199
|
-
allow(connection).to receive(:patch).and_return(post)
|
200
|
-
|
201
|
-
expect(ReplaceTerms).to receive(:apply_tags).with(
|
202
|
-
connection, post, [1, 3, 7]
|
203
|
-
).and_return(0)
|
204
|
-
|
205
|
-
client.update_post(5, title: "Foo", tag_ids: [1, 3, 7])
|
206
|
-
end
|
207
|
-
|
208
|
-
it "refreshes the post if terms or categories changed" do
|
209
|
-
post = instance_double(Post, id: 5)
|
210
|
-
allow(connection).to receive(:patch).and_return(post)
|
211
|
-
|
212
|
-
expect(ReplaceTerms).to receive(:apply_tags).and_return(1)
|
213
|
-
expect(ReplaceTerms).to receive(:apply_categories).and_return(1)
|
214
|
-
expect(ReplaceMetadata).to receive(:apply).and_return(1)
|
215
|
-
|
216
|
-
expect(connection).to receive(:get).with(
|
217
|
-
Post, "posts/5", hash_including(_embed: nil)
|
218
|
-
).and_return(post)
|
219
|
-
|
220
|
-
client.update_post(5, title: "Foo", tag_ids: [], category_ids: [], meta: {})
|
221
|
-
end
|
222
|
-
|
223
|
-
it "does not refresh the post if neither terms nor categories changed" do
|
224
|
-
post = instance_double(Post, id: 5)
|
225
|
-
allow(connection).to receive(:patch).and_return(post)
|
226
|
-
|
227
|
-
expect(ReplaceTerms).to receive(:apply_tags).and_return(0)
|
228
|
-
expect(ReplaceTerms).to receive(:apply_categories).and_return(0)
|
229
|
-
expect(ReplaceMetadata).to receive(:apply).and_return(0)
|
230
|
-
|
231
|
-
expect(connection).to_not receive(:get)
|
232
|
-
|
233
|
-
client.update_post(5, title: "Foo", tag_ids: [], category_ids: [], meta: {})
|
234
|
-
end
|
235
72
|
end
|
236
|
-
|
237
73
|
describe "deleting posts" do
|
238
74
|
it "deletes a post without force by default" do
|
239
75
|
expect(connection).to receive(:delete).with(
|
@@ -263,12 +99,12 @@ module WordpressClient
|
|
263
99
|
describe "categories" do
|
264
100
|
it "can be listed" do
|
265
101
|
expect(connection).to receive(:get_multiple).with(
|
266
|
-
Category, "
|
102
|
+
Category, "categories", hash_including(page: 1, per_page: 10)
|
267
103
|
)
|
268
104
|
client.categories
|
269
105
|
|
270
106
|
expect(connection).to receive(:get_multiple).with(
|
271
|
-
Category, "
|
107
|
+
Category, "categories", hash_including(page: 2, per_page: 60)
|
272
108
|
)
|
273
109
|
client.categories(page: 2, per_page: 60)
|
274
110
|
end
|
@@ -277,7 +113,7 @@ module WordpressClient
|
|
277
113
|
category = instance_double(Category)
|
278
114
|
|
279
115
|
expect(connection).to receive(:get).with(
|
280
|
-
Category, "
|
116
|
+
Category, "categories/12"
|
281
117
|
).and_return category
|
282
118
|
|
283
119
|
expect(client.find_category(12)).to eq category
|
@@ -287,7 +123,7 @@ module WordpressClient
|
|
287
123
|
category = instance_double(Category)
|
288
124
|
|
289
125
|
expect(connection).to receive(:create).with(
|
290
|
-
Category, "
|
126
|
+
Category, "categories", name: "Foo"
|
291
127
|
).and_return category
|
292
128
|
|
293
129
|
expect(client.create_category(name: "Foo")).to eq category
|
@@ -296,8 +132,8 @@ module WordpressClient
|
|
296
132
|
it "can be updated" do
|
297
133
|
category = instance_double(Category)
|
298
134
|
|
299
|
-
expect(connection).to receive(:
|
300
|
-
Category, "
|
135
|
+
expect(connection).to receive(:put).with(
|
136
|
+
Category, "categories/45", name: "New"
|
301
137
|
).and_return category
|
302
138
|
|
303
139
|
expect(client.update_category(45, name: "New")).to eq category
|
@@ -307,12 +143,12 @@ module WordpressClient
|
|
307
143
|
describe "tags" do
|
308
144
|
it "can be listed" do
|
309
145
|
expect(connection).to receive(:get_multiple).with(
|
310
|
-
Tag, "
|
146
|
+
Tag, "tags", hash_including(page: 1, per_page: 10)
|
311
147
|
)
|
312
148
|
client.tags
|
313
149
|
|
314
150
|
expect(connection).to receive(:get_multiple).with(
|
315
|
-
Tag, "
|
151
|
+
Tag, "tags", hash_including(page: 2, per_page: 60)
|
316
152
|
)
|
317
153
|
client.tags(page: 2, per_page: 60)
|
318
154
|
end
|
@@ -321,7 +157,7 @@ module WordpressClient
|
|
321
157
|
tag = instance_double(Tag)
|
322
158
|
|
323
159
|
expect(connection).to receive(:get).with(
|
324
|
-
Tag, "
|
160
|
+
Tag, "tags/12"
|
325
161
|
).and_return tag
|
326
162
|
|
327
163
|
expect(client.find_tag(12)).to eq tag
|
@@ -331,7 +167,7 @@ module WordpressClient
|
|
331
167
|
tag = instance_double(Tag)
|
332
168
|
|
333
169
|
expect(connection).to receive(:create).with(
|
334
|
-
Tag, "
|
170
|
+
Tag, "tags", name: "Foo"
|
335
171
|
).and_return tag
|
336
172
|
|
337
173
|
expect(client.create_tag(name: "Foo")).to eq tag
|
@@ -340,8 +176,8 @@ module WordpressClient
|
|
340
176
|
it "can be updated" do
|
341
177
|
tag = instance_double(Tag)
|
342
178
|
|
343
|
-
expect(connection).to receive(:
|
344
|
-
Tag, "
|
179
|
+
expect(connection).to receive(:put).with(
|
180
|
+
Tag, "tags/45", name: "New"
|
345
181
|
).and_return tag
|
346
182
|
|
347
183
|
expect(client.update_tag(45, name: "New")).to eq tag
|
@@ -400,7 +236,7 @@ module WordpressClient
|
|
400
236
|
it "can be updated" do
|
401
237
|
media = instance_double(Media)
|
402
238
|
|
403
|
-
expect(connection).to receive(:
|
239
|
+
expect(connection).to receive(:put).with(
|
404
240
|
Media, "media/7", title: "New"
|
405
241
|
).and_return(media)
|
406
242
|
|
data/spec/connection_spec.rb
CHANGED
@@ -6,7 +6,7 @@ module WordpressClient
|
|
6
6
|
Connection.new(url: "http://example.com/", username: "jane", password: "doe")
|
7
7
|
}
|
8
8
|
|
9
|
-
let(:base_url) { "http://
|
9
|
+
let(:base_url) { "http://example.com/wp/v2" }
|
10
10
|
let(:model) { class_double(Post, parse: model_instance) }
|
11
11
|
let(:model_instance) { instance_double(Post) }
|
12
12
|
|
@@ -135,31 +135,31 @@ module WordpressClient
|
|
135
135
|
"id" => 1, "title" => "Bar"
|
136
136
|
).and_return(model_instance)
|
137
137
|
|
138
|
-
response = connection.
|
138
|
+
response = connection.put(model, "foos/1", title: "Bar")
|
139
139
|
expect(response).to eq model_instance
|
140
140
|
end
|
141
141
|
|
142
142
|
it "can ignore responses" do
|
143
143
|
stub_patch("#{base_url}/foos/1", {title: "Bar"}, returns: {id: 1, title: "Bar"})
|
144
|
-
response = connection.
|
144
|
+
response = connection.put_without_response("foos/1", title: "Bar")
|
145
145
|
expect(response).to be true
|
146
146
|
end
|
147
147
|
|
148
148
|
it "raises NotFoundError if response is 400 with rest_post_invalid_id as error code" do
|
149
149
|
stub_patch(/./, {}, returns: json_fixture("invalid-post-id.json"), status: 400)
|
150
|
-
expect { connection.
|
151
|
-
expect { connection.
|
150
|
+
expect { connection.put(model, "foo", {}) }.to raise_error(NotFoundError, /post id/i)
|
151
|
+
expect { connection.put_without_response("foo", {}) }.to raise_error(NotFoundError)
|
152
152
|
end
|
153
153
|
|
154
154
|
it "raises ValidationError on any other 400 responses" do
|
155
155
|
stub_patch(/./, {}, returns: json_fixture("validation-error.json"), status: 400)
|
156
156
|
|
157
157
|
expect {
|
158
|
-
connection.
|
158
|
+
connection.put(model, "foo", {})
|
159
159
|
}.to raise_error(ValidationError, /status is not one of/)
|
160
160
|
|
161
161
|
expect {
|
162
|
-
connection.
|
162
|
+
connection.put_without_response("foo", {})
|
163
163
|
}.to raise_error(ValidationError, /status is not one of/)
|
164
164
|
end
|
165
165
|
end
|
@@ -199,10 +199,7 @@ module WordpressClient
|
|
199
199
|
headers: {
|
200
200
|
"content-length" => "11",
|
201
201
|
"content-type" => "text/plain",
|
202
|
-
|
203
|
-
# to using their own format:
|
204
|
-
# https://github.com/WP-API/WP-API/issues/1744
|
205
|
-
"content-disposition" => 'filename=foo.txt',
|
202
|
+
"content-disposition" => 'attachment; filename="foo.txt"',
|
206
203
|
},
|
207
204
|
body: "hello world",
|
208
205
|
).to_return(
|
@@ -235,11 +232,12 @@ module WordpressClient
|
|
235
232
|
headers = {"content-type" => "#{content_type}; charset=utf-8"}
|
236
233
|
headers["X-WP-Total"] = total.to_s if total
|
237
234
|
|
238
|
-
stub_request(:get, path).to_return(status: status, body: body, headers: headers)
|
235
|
+
stub_request(:get, path).with(basic_auth: ['jane', 'doe']).to_return(status: status, body: body, headers: headers)
|
239
236
|
end
|
240
237
|
|
241
238
|
def stub_successful_post_with_redirect(path, data, redirects_to:)
|
242
239
|
stub_request(:post, path).with(
|
240
|
+
basic_auth: ['jane', 'doe'],
|
243
241
|
headers: {"content-type" => "application/json; charset=#{"".encoding}"},
|
244
242
|
body: data.to_json,
|
245
243
|
).to_return(
|
@@ -249,7 +247,9 @@ module WordpressClient
|
|
249
247
|
end
|
250
248
|
|
251
249
|
def stub_failing_post(path, returns:, status:)
|
252
|
-
stub_request(:post, path).
|
250
|
+
stub_request(:post, path).with(
|
251
|
+
basic_auth: ['jane', 'doe']
|
252
|
+
).to_return(
|
253
253
|
status: status,
|
254
254
|
body: returns.to_json,
|
255
255
|
headers: {"content-type" => "application/json; charset=utf-8"},
|
@@ -257,7 +257,8 @@ module WordpressClient
|
|
257
257
|
end
|
258
258
|
|
259
259
|
def stub_patch(path, data, returns:, status: 200)
|
260
|
-
stub_request(:
|
260
|
+
stub_request(:put, path).with(
|
261
|
+
basic_auth: ['jane', 'doe'],
|
261
262
|
headers: {"content-type" => "application/json; charset=#{"".encoding}"},
|
262
263
|
body: data.to_json,
|
263
264
|
).to_return(
|
data/spec/docker/Dockerfile
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
FROM appcontainers/wordpress
|
2
2
|
|
3
|
+
# Wordpress latest isn't actually the lastest we want to be on the bleeding edge
|
4
|
+
RUN rm -rf /var/www/html/
|
5
|
+
RUN wget -P /var/www/html/ https://wordpress.org/latest.zip && \
|
6
|
+
unzip /var/www/html/latest.zip -d /var/www/html/ && \
|
7
|
+
rm -fr /var/www/html/latest.zip
|
8
|
+
|
9
|
+
# Copy the WP-Config file
|
10
|
+
RUN cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
|
11
|
+
|
12
|
+
# White list custom metadata fields
|
13
|
+
RUN echo "register_meta('post', 'foo', array('type' => 'integer', 'description' => 'Some kind of integer', 'single' => true, 'show_in_rest' => true));" >>/var/www/html/wordpress/wp-config.php
|
14
|
+
RUN echo "register_meta('post', 'bar', array('type' => 'boolean', 'description' => 'Some kind of boolean', 'single' => true, 'show_in_rest' => true));" >>/var/www/html/wordpress/wp-config.php
|
15
|
+
RUN echo "register_meta('post', 'baz', array('type' => 'string', 'description' => 'Some kind of string', 'single' => true, 'show_in_rest' => true));" >>/var/www/html/wordpress/wp-config.php
|
16
|
+
|
17
|
+
# Resolve broken mirrorfile
|
18
|
+
COPY yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
|
19
|
+
RUN yum clean all
|
20
|
+
|
3
21
|
# base image only contains American timezones
|
4
22
|
RUN yum install -y tzdata
|
5
23
|
|
24
|
+
RUN yum remove -y php php-common php-cli php-mysql
|
25
|
+
RUN yum install -y php56-php php56-php-common php56-php-cli php56-php-mysql
|
26
|
+
|
6
27
|
ENV APP_NAME testapp.com
|
7
28
|
ENV APACHE_SVRALIAS www.testapp.com localhost
|
8
29
|
ENV MYSQL_SERVER localhost
|
@@ -13,28 +34,32 @@ ENV APP_USER admin
|
|
13
34
|
ENV APP_PASS P@ssw0rd
|
14
35
|
ENV WP_KEY ILoveFlappyjacks
|
15
36
|
|
37
|
+
# Make pretty permalinks work so API is accessible
|
38
|
+
COPY htaccess /var/www/html/wordpress/.htaccess
|
39
|
+
|
16
40
|
# Restore a copy of a set up database on first boot
|
17
41
|
COPY dbdump.sql.gz /tmp/dbdump.sql.gz
|
18
42
|
COPY restore-dbdump.sh /tmp/.restore-dbdump.sh
|
19
43
|
RUN chmod +x /tmp/.restore-dbdump.sh && \
|
20
|
-
echo "if [ -f /tmp/.restore-dbdump.sh ]; then /tmp/.restore-dbdump.sh; rm -
|
44
|
+
echo "if [ -f /tmp/.restore-dbdump.sh ]; then /tmp/.restore-dbdump.sh; rm -rf /tmp/.restore-dbdump.sh; fi" >> /root/.bashrc
|
21
45
|
|
22
|
-
### Install
|
46
|
+
### Install Basic Auth plugin
|
47
|
+
# Required for API to be able to make changes
|
23
48
|
|
24
49
|
# We need tar to unpack the WP plugins
|
25
50
|
RUN yum install -y tar
|
26
51
|
|
27
|
-
# WP API
|
28
|
-
# Get download link from https://wordpress.org/plugins/rest-api/
|
29
|
-
RUN curl -SL -o /tmp/rest-api.zip https://downloads.wordpress.org/plugin/rest-api.2.0-beta8.zip \
|
30
|
-
&& unzip /tmp/rest-api.zip -d /var/www/html/wordpress/wp-content/plugins/ \
|
31
|
-
&& rm /tmp/rest-api.zip
|
32
|
-
|
33
52
|
# Basic Auth
|
34
53
|
# Get download link from GitHub or something.
|
35
54
|
RUN curl -SL https://github.com/WP-API/Basic-Auth/archive/master.tar.gz \
|
36
55
|
| tar -xzC /var/www/html/wordpress/wp-content/plugins/ \
|
37
56
|
&& mv /var/www/html/wordpress/wp-content/plugins/Basic-Auth* /var/www/html/wordpress/wp-content/plugins/basic-auth
|
38
57
|
|
39
|
-
#
|
40
|
-
|
58
|
+
# The appcontainer will run apache in the foreground after running their setup
|
59
|
+
# script. The setup script will unset all the env variables with passwords and
|
60
|
+
# other important information so they aren't exposed to the foregrounded apache
|
61
|
+
# process, so for this reason we cannot just append our DB restore to that
|
62
|
+
# script.
|
63
|
+
# The container used to just run bash, and by switching back to that we get
|
64
|
+
# everything working again.
|
65
|
+
CMD /bin/bash
|
data/spec/docker/README.md
CHANGED
@@ -1,37 +1,74 @@
|
|
1
|
-
#
|
1
|
+
# Docker image for WordpressClient
|
2
2
|
|
3
|
-
|
3
|
+
Use this docker image to run integration tests, either in this repo or in some client repo where you use the gem.
|
4
4
|
|
5
|
-
|
5
|
+
**Note:** This image is not meant for *any* production use. It's meant for integration tests, and nothing else.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
You need to publish the container's port 80 to whichever port you want your instance on, then set an environment variable for where the server should be accessible from as Wordpress needs to have this stored in the database.
|
10
|
+
|
11
|
+
You also need to run it with an interactive terminal in order for it to work.
|
6
12
|
|
7
13
|
```bash
|
8
|
-
docker
|
9
|
-
docker run -it -p 8181:80 wpclient-test
|
14
|
+
docker run -dit -p 8080:80 -e WORDPRESS_HOST=localhost:8080 hemnet/wordpress_client_test:latest
|
10
15
|
```
|
11
16
|
|
12
|
-
|
17
|
+
I you want to see the ouput or access the environment in order to debug an issue, omit the `-d` option. It will boot into a `bash` shell with Apache running in the background. You can also use `docker attach` to attach to a running instance.
|
18
|
+
|
19
|
+
**Note:** When you exit a running container, everything stored in it will be kept on disk. It is recommended that you `docker rm` the image when you are done to clean up.
|
20
|
+
|
21
|
+
When the instance is up and running, you can log in as an administrator using `test`/`test` as username and password.
|
22
|
+
|
23
|
+
## Contents
|
24
|
+
|
25
|
+
This image is based on Appcontainer's Wordpress image, which runs Apache, MySQL and PHP5 on CentOS using bash. In addition, a DB dump is restored containing a set up blog so you don't need to do the first installation steps.
|
26
|
+
|
27
|
+
* Username `test`
|
28
|
+
* Password `test`
|
29
|
+
* `.htaccess` for Pretty Permalinks is set up so the API works
|
30
|
+
|
31
|
+
## Developing the image
|
13
32
|
|
14
|
-
|
33
|
+
### Re-creating DB dump from scratch
|
34
|
+
|
35
|
+
If you need to regenerate the DB dump, remove the part where the file is copied
|
36
|
+
and restored from the `Dockerfile`, then build and start the image.
|
37
|
+
|
38
|
+
```bash
|
39
|
+
docker build -t hemnet/wordpress_client_test:dev .
|
40
|
+
docker run -it -p 8181:80 hemnet/wordpress_client_test:dev
|
41
|
+
```
|
42
|
+
|
43
|
+
You'll get a `bash` shell inside the container. Open your browser and go to the
|
44
|
+
newly booted application ([`localhost:8181`](http://localhost:8181/)).
|
45
|
+
|
46
|
+
You'll be greeted by the Wordpress installer. Fill in everything and complete
|
47
|
+
the installation.
|
48
|
+
|
49
|
+
* Blog title `wordpress_client test`
|
50
|
+
* Username `test`
|
51
|
+
* Password `test`
|
52
|
+
* [Set up permalinks according to **Day and
|
53
|
+
name**!](http://localhost:8181/wp-admin/options-permalink.php)
|
54
|
+
* Without this the provided `.htaccess` will cause API requests to redirect.
|
55
|
+
* [Activate the Basic Auth plugin](http://localhost:8181/wp-admin/plugins.php)
|
15
56
|
|
16
57
|
Then, **in your container's terminal**, run the following command:
|
17
58
|
|
18
59
|
```bash
|
19
|
-
mysqldump -u "$MYSQL_USER" --password="$MYSQL_PASS" --host="$MYSQL_HOST" "$MYSQL_DB" |
|
60
|
+
mysqldump -u "$MYSQL_USER" --password="$MYSQL_PASS" --host="$MYSQL_HOST" "$MYSQL_DB" | \
|
61
|
+
gzip -9 > /tmp/dbdump.sql.gz
|
20
62
|
```
|
21
63
|
|
22
64
|
You can then copy the file to your host using the `docker cp` command:
|
23
65
|
|
24
66
|
```bash
|
25
|
-
docker ps | grep
|
67
|
+
docker ps | grep hemnet/wordpress_client_test:dev
|
26
68
|
# See the container ID or name of your running container
|
27
69
|
docker cp THE-CONTAINER-ID:/tmp/dbdump.sql.gz .
|
28
70
|
```
|
29
71
|
|
30
|
-
|
31
|
-
|
32
|
-
Restore the DB loading code from the `Dockerfile`, commit this file to the repo and rebuild everything and verify that Wordpress is still set up correctly when the dump is restored.
|
72
|
+
Last step is to update `restore-dbdump.sh` to replace the hard-coded `WORDPRESS_HOST` placeholder with the one you used to generate the DB dump with. This corresponds with `localhost:8181` with native Docker if you followed these commands exactly. If you use `docker-machine`, you need to use your machine IP instead. (See *"Usage"* above)
|
33
73
|
|
34
|
-
|
35
|
-
datadump is a specfic IP. So you will need to change that hard coded
|
36
|
-
expectation to match the new IP used in your data dump. You can find out what
|
37
|
-
that IP is by examining the dumo but it is probably the value set in `$DOCKER_HOST`.
|
74
|
+
You can then shut down your container by logging out of the container terminal. Restore the DB loading code from the `Dockerfile`, commit this file to the repo and rebuild everything and verify that Wordpress is still set up correctly when the dump is restored.
|
data/spec/docker/dbdump.sql.gz
CHANGED
Binary file
|
@@ -2,7 +2,7 @@
|
|
2
2
|
service mysqld start
|
3
3
|
|
4
4
|
gunzip -c /tmp/dbdump.sql.gz | \
|
5
|
-
sed "s/
|
5
|
+
sed "s/localhost:8181/${WORDPRESS_HOST:-localhost:8181}/g" | \
|
6
6
|
mysql \
|
7
7
|
--user="$MYSQL_USER" \
|
8
8
|
--password="$MYSQL_PASS" \
|
@@ -10,4 +10,4 @@ gunzip -c /tmp/dbdump.sql.gz | \
|
|
10
10
|
--batch \
|
11
11
|
"$MYSQL_DB"
|
12
12
|
|
13
|
-
rm /tmp/dbdump.sql.gz
|
13
|
+
rm -rf /tmp/dbdump.sql.gz
|
@@ -0,0 +1,25 @@
|
|
1
|
+
[base]
|
2
|
+
name=CentOS-$releasever - Base
|
3
|
+
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
|
4
|
+
# baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
|
5
|
+
baseurl=https://vault.centos.org/6.10/os/$basearch/
|
6
|
+
gpgcheck=1
|
7
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
|
8
|
+
|
9
|
+
# released updates
|
10
|
+
[updates]
|
11
|
+
name=CentOS-$releasever - Updates
|
12
|
+
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
|
13
|
+
# baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
|
14
|
+
baseurl=https://vault.centos.org/6.10/updates/$basearch/
|
15
|
+
gpgcheck=1
|
16
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
|
17
|
+
|
18
|
+
# additional packages that may be useful
|
19
|
+
[extras]
|
20
|
+
name=CentOS-$releasever - Extras
|
21
|
+
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
|
22
|
+
# baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
|
23
|
+
baseurl=https://vault.centos.org/6.10/extras/$basearch/
|
24
|
+
gpgcheck=1
|
25
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
|
@@ -1 +1 @@
|
|
1
|
-
{"id":5,"date":"2015-11-17T14:51:26","guid":{"rendered":"http:\/\/example.com\/wp-content\/uploads\/2015\/11\/thoughtful.jpg"},"modified":"2015-11-17T14:51:26","modified_gmt":"2015-11-17T14:51:26","slug":"thoughtful","type":"attachment","link":"http:\/\/example.com\/?attachment_id=5","title":{"rendered":"thoughtful"},"author":1,"comment_status":"open","ping_status":"closed","alt_text":"","caption":"","description":"","media_type":"image","media_details":{"width":600,"height":800,"file":"2015\/11\/thoughtful.jpg","image_meta":{"aperture":0,"credit":"","camera":"","caption":"","created_timestamp":0,"copyright":"\u00a9 JoeDaEskimo - http:\/\/www.redbubble.com\/people\/JoeDaEskim","focal_length":0,"iso":0,"shutter_speed":0,"title":"","orientation":0},"sizes":{}},"post":null,"source_url":"http:\/\/example.com\/wp-content\/uploads\/2015\/11\/thoughtful.jpg","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/media\/5"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/media"}],"author":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/comments?post_id=5"}]}}
|
1
|
+
{"id":5,"date":"2015-11-17T14:51:26","guid":{"rendered":"http:\/\/example.com\/wp-content\/uploads\/2015\/11\/thoughtful.jpg"},"modified":"2015-11-17T14:51:26","modified_gmt":"2015-11-17T14:51:26","slug":"thoughtful","type":"attachment","link":"http:\/\/example.com\/?attachment_id=5","title":{"rendered":"thoughtful"},"author":1,"comment_status":"open","ping_status":"closed","alt_text":"accessibility is cool","caption":"","description":"","media_type":"image","media_details":{"width":600,"height":800,"file":"2015\/11\/thoughtful.jpg","image_meta":{"aperture":0,"credit":"","camera":"","caption":"","created_timestamp":0,"copyright":"\u00a9 JoeDaEskimo - http:\/\/www.redbubble.com\/people\/JoeDaEskim","focal_length":0,"iso":0,"shutter_speed":0,"title":"","orientation":0},"sizes":{}},"post":null,"source_url":"http:\/\/example.com\/wp-content\/uploads\/2015\/11\/thoughtful.jpg","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/media\/5"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/media"}],"author":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/comments?post_id=5"}]}}
|