cucumber-wordpress 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENCE +13 -0
- data/README.rdoc +38 -0
- data/Rakefile +17 -0
- data/examples/features/step_definitions/webrat_steps.rb +159 -0
- data/examples/features/support/config.yml +9 -0
- data/examples/features/support/env.rb +96 -0
- data/examples/features/support/paths.rb +21 -0
- data/examples/features/wordpress.feature +18 -0
- data/lib/cucumber-wordpress/steps.rb +71 -0
- data/lib/cucumber-wordpress.rb +90 -0
- metadata +95 -0
data/LICENCE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright © 2009, The Dextrous Web
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= cucumber-wordpress
|
2
|
+
|
3
|
+
Environment setup and step definitions for testing WordPress with Cucumber.
|
4
|
+
|
5
|
+
== Getting started
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
gem install cucumber-wordpress --source http://gemcutter.org
|
9
|
+
|
10
|
+
Copy the examples/features/ directory into an existing WordPress installation:
|
11
|
+
cd wordpress-installation
|
12
|
+
cp /usr/lib/ruby/gems/1.8/gems/cucumber-wordpress-1.0/examples/features .
|
13
|
+
|
14
|
+
Configure wp-config variables:
|
15
|
+
vim features/support/config.yml
|
16
|
+
|
17
|
+
Run cucumber:
|
18
|
+
cucumber
|
19
|
+
|
20
|
+
== Caveats
|
21
|
+
|
22
|
+
* The WordPress installation you're testing must be being served over HTTP
|
23
|
+
somehow (see WEBHOST in config.yml). Eventually I want to be able to start a
|
24
|
+
Web server from within cucumber.
|
25
|
+
* wp-config.php gets copied elsewhere and overwritten, so you can't be running
|
26
|
+
this in a production environment.
|
27
|
+
|
28
|
+
== Patches
|
29
|
+
|
30
|
+
* Send me a pull request via GitHub or an email at tom@thedextrousweb.com.
|
31
|
+
|
32
|
+
== Author
|
33
|
+
|
34
|
+
* Tom Adams <tom@thedextrousweb.com>
|
35
|
+
|
36
|
+
== Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2009 The Dextrous Web. See LICENCE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.version = "1.0"
|
5
|
+
gem.name = "cucumber-wordpress"
|
6
|
+
gem.summary = %Q{Environment setup and step definitions for testing WordPress with Cucumber}
|
7
|
+
gem.email = "tom@thedextrousweb.com"
|
8
|
+
gem.homepage = "http://github.com/dxw/cucumber-wordpress"
|
9
|
+
gem.authors = ["Tom Adams"]
|
10
|
+
gem.add_dependency "cucumber"
|
11
|
+
gem.add_dependency "webrat"
|
12
|
+
gem.add_dependency "mysql"
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
2
|
+
|
3
|
+
# Commonly used webrat steps
|
4
|
+
# http://github.com/brynary/webrat
|
5
|
+
|
6
|
+
Given /^I am on (.+)$/ do |page_name|
|
7
|
+
visit path_to(page_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
When /^I go to (.+)$/ do |page_name|
|
11
|
+
visit path_to(page_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^I press "([^\"]*)"$/ do |button|
|
15
|
+
click_button(button)
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^I follow "([^\"]*)"$/ do |link|
|
19
|
+
click_link(link)
|
20
|
+
end
|
21
|
+
|
22
|
+
When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
|
23
|
+
click_link_within(parent, link)
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
|
27
|
+
fill_in(field, :with => value)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Use this to fill in an entire form with data from a table. Example:
|
31
|
+
#
|
32
|
+
# When I fill in the following:
|
33
|
+
# | Account Number | 5002 |
|
34
|
+
# | Expiry date | 2009-11-01 |
|
35
|
+
# | Note | Nice guy |
|
36
|
+
# | Wants Email? | |
|
37
|
+
#
|
38
|
+
# TODO: Add support for checkbox, select og option
|
39
|
+
# based on naming conventions.
|
40
|
+
#
|
41
|
+
When /^I fill in the following:$/ do |fields|
|
42
|
+
fields.rows_hash.each do |name, value|
|
43
|
+
When %{I fill in "#{name}" with "#{value}"}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
|
48
|
+
select(value, :from => field)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Use this step in conjunction with Rail's datetime_select helper. For example:
|
52
|
+
# When I select "December 25, 2008 10:00" as the date and time
|
53
|
+
When /^I select "([^\"]*)" as the date and time$/ do |time|
|
54
|
+
select_datetime(time)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Use this step when using multiple datetime_select helpers on a page or
|
58
|
+
# you want to specify which datetime to select. Given the following view:
|
59
|
+
# <%= f.label :preferred %><br />
|
60
|
+
# <%= f.datetime_select :preferred %>
|
61
|
+
# <%= f.label :alternative %><br />
|
62
|
+
# <%= f.datetime_select :alternative %>
|
63
|
+
# The following steps would fill out the form:
|
64
|
+
# When I select "November 23, 2004 11:20" as the "Preferred" date and time
|
65
|
+
# And I select "November 25, 2004 10:30" as the "Alternative" date and time
|
66
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
|
67
|
+
select_datetime(datetime, :from => datetime_label)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Use this step in conjunction with Rail's time_select helper. For example:
|
71
|
+
# When I select "2:20PM" as the time
|
72
|
+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
73
|
+
# will convert the 2:20PM to 14:20 and then select it.
|
74
|
+
When /^I select "([^\"]*)" as the time$/ do |time|
|
75
|
+
select_time(time)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Use this step when using multiple time_select helpers on a page or you want to
|
79
|
+
# specify the name of the time on the form. For example:
|
80
|
+
# When I select "7:30AM" as the "Gym" time
|
81
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
|
82
|
+
select_time(time, :from => time_label)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Use this step in conjunction with Rail's date_select helper. For example:
|
86
|
+
# When I select "February 20, 1981" as the date
|
87
|
+
When /^I select "([^\"]*)" as the date$/ do |date|
|
88
|
+
select_date(date)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Use this step when using multiple date_select helpers on one page or
|
92
|
+
# you want to specify the name of the date on the form. For example:
|
93
|
+
# When I select "April 26, 1982" as the "Date of Birth" date
|
94
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
|
95
|
+
select_date(date, :from => date_label)
|
96
|
+
end
|
97
|
+
|
98
|
+
When /^I check "([^\"]*)"$/ do |field|
|
99
|
+
check(field)
|
100
|
+
end
|
101
|
+
|
102
|
+
When /^I uncheck "([^\"]*)"$/ do |field|
|
103
|
+
uncheck(field)
|
104
|
+
end
|
105
|
+
|
106
|
+
When /^I choose "([^\"]*)"$/ do |field|
|
107
|
+
choose(field)
|
108
|
+
end
|
109
|
+
|
110
|
+
When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
|
111
|
+
attach_file(field, path)
|
112
|
+
end
|
113
|
+
|
114
|
+
Then /^I should see "([^\"]*)"$/ do |text|
|
115
|
+
response.should contain(text)
|
116
|
+
end
|
117
|
+
|
118
|
+
Then /^I should see \/([^\/]*)\/$/ do |regexp|
|
119
|
+
regexp = Regexp.new(regexp)
|
120
|
+
response.should contain(regexp)
|
121
|
+
end
|
122
|
+
|
123
|
+
Then /^I should not see "([^\"]*)"$/ do |text|
|
124
|
+
response.should_not contain(text)
|
125
|
+
end
|
126
|
+
|
127
|
+
Then /^I should not see \/([^\/]*)\/$/ do |regexp|
|
128
|
+
regexp = Regexp.new(regexp)
|
129
|
+
response.should_not contain(regexp)
|
130
|
+
end
|
131
|
+
|
132
|
+
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
|
133
|
+
field_labeled(field).value.should =~ /#{value}/
|
134
|
+
end
|
135
|
+
|
136
|
+
Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
|
137
|
+
field_labeled(field).value.should_not =~ /#{value}/
|
138
|
+
end
|
139
|
+
|
140
|
+
Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
|
141
|
+
field_labeled(label).should be_checked
|
142
|
+
end
|
143
|
+
|
144
|
+
Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
|
145
|
+
field_labeled(label).should_not be_checked
|
146
|
+
end
|
147
|
+
|
148
|
+
Then /^I should be on (.+)$/ do |page_name|
|
149
|
+
uri = URI.parse(current_url)
|
150
|
+
if uri.query.blank?
|
151
|
+
uri.path.should == path_to(page_name)
|
152
|
+
else
|
153
|
+
"#{uri.path}?#{uri.query}".should include(path_to(page_name))
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
Then /^show me the page$/ do
|
158
|
+
save_and_open_page
|
159
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#
|
2
|
+
# All the standard stuff
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'spec/mocks'
|
6
|
+
require 'webrat'
|
7
|
+
Webrat.configure do |config|
|
8
|
+
config.mode = :mechanize
|
9
|
+
end
|
10
|
+
World do
|
11
|
+
session = Webrat::Session.new
|
12
|
+
session.extend(Webrat::Methods)
|
13
|
+
session.extend(Webrat::Matchers)
|
14
|
+
session
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# WordPress stuff
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'cucumber-wordpress'
|
22
|
+
require 'cucumber-wordpress/steps'
|
23
|
+
|
24
|
+
# Get the WordPress configuration for this site
|
25
|
+
WordPress.configure(YAML::load(open(File.join(File.dirname(__FILE__),'config.yml'))))
|
26
|
+
|
27
|
+
# Hide the original wp-config.php, and write our own
|
28
|
+
WordPress.write_config
|
29
|
+
WordPress.create_db
|
30
|
+
|
31
|
+
at_exit do
|
32
|
+
# Replace the original wp-config.php (if it existed)
|
33
|
+
WordPress.reset_config
|
34
|
+
WordPress.drop_db
|
35
|
+
end
|
36
|
+
|
37
|
+
# Before every scenario, reset the DB to how it was when it was first installed
|
38
|
+
Before do |scenario|
|
39
|
+
WordPress.reset_db
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# And we're done!
|
44
|
+
# Apart from a couple of patches we need to apply to webrat...
|
45
|
+
#
|
46
|
+
|
47
|
+
# For some reason the MechanizeAdapter uses response_body instead of response.body.
|
48
|
+
# This is needed
|
49
|
+
module Webrat
|
50
|
+
class Session
|
51
|
+
include Spec::Mocks::ExampleMethods
|
52
|
+
def response
|
53
|
+
m = mock
|
54
|
+
m.should_receive(:body).any_number_of_times.and_return(response_body)
|
55
|
+
m
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Use XPath in click_link_within, etc.
|
61
|
+
# This is needed too
|
62
|
+
module Webrat
|
63
|
+
class Scope
|
64
|
+
protected
|
65
|
+
|
66
|
+
def xpath_scoped_dom
|
67
|
+
Webrat::XML.xpath_at(@scope.dom, @selector)
|
68
|
+
end
|
69
|
+
|
70
|
+
def scoped_dom
|
71
|
+
begin
|
72
|
+
Webrat::XML.css_at(@scope.dom, @selector)
|
73
|
+
rescue Nokogiri::CSS::SyntaxError, Nokogiri::XML::XPath::SyntaxError => e
|
74
|
+
begin
|
75
|
+
# That was not a css selector, mayby it's an xpath selector?
|
76
|
+
xpath_scoped_dom
|
77
|
+
rescue
|
78
|
+
# Raise original css syntax error if selector is not xpath either
|
79
|
+
raise e
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Fix attach_file so it works with mechanize
|
87
|
+
# Thanks: https://webrat.lighthouseapp.com/projects/10503/tickets/303-tiny-patch-for-attach_file-to-work-with-mechanize
|
88
|
+
# This is not needed for cucumber-wordpress (yet)
|
89
|
+
module Webrat
|
90
|
+
class FileField < Field
|
91
|
+
protected
|
92
|
+
def test_uploaded_file
|
93
|
+
open(@value)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'cucumber-wordpress'
|
2
|
+
|
3
|
+
module NavigationHelpers
|
4
|
+
def path_to(page_name)
|
5
|
+
|
6
|
+
# Default WordPress paths
|
7
|
+
path = WordPress.path_to(page_name)
|
8
|
+
return path unless path.nil?
|
9
|
+
|
10
|
+
# Our own paths
|
11
|
+
partial = case page_name
|
12
|
+
when /^my special page$/
|
13
|
+
'/my-special-page.php'
|
14
|
+
else
|
15
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n"
|
16
|
+
end
|
17
|
+
URI::join("http://#{WordPress.WEBHOST}/", partial)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
World(NavigationHelpers)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: WordPress example
|
2
|
+
WordPress should be as easy to test as Rails.
|
3
|
+
|
4
|
+
Background:
|
5
|
+
Given WordPress is installed
|
6
|
+
|
7
|
+
Scenario: Submitting a post
|
8
|
+
Given I am logged in as "admin"
|
9
|
+
And I am on admin dashboard
|
10
|
+
When I follow "Add New" within "#menu-posts"
|
11
|
+
Then I should see "Add New Post"
|
12
|
+
When I fill in "title" with "hullo thar"
|
13
|
+
And I fill in "content" with "I &lt;3 cucumber"
|
14
|
+
And I press "publish"
|
15
|
+
Then there should be 1 post
|
16
|
+
Given I am on homepage
|
17
|
+
Then I should see "hullo thar"
|
18
|
+
And I should see "I <3 cucumber"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Given /^WordPress is installed$/ do
|
2
|
+
visit path_to 'homepage'
|
3
|
+
title = 'A Very Boring Test Title'
|
4
|
+
if response.body.include? '<title>WordPress › Installation</title>'
|
5
|
+
fill_in('Blog Title', :with => title)
|
6
|
+
fill_in('Your E-mail', :with => 'test@wordpress.org')
|
7
|
+
click_button('Install WordPress')
|
8
|
+
WordPress.passwords = {'admin' => response.body.match(%r[<td><code>(.+)</code><br />])[1]}
|
9
|
+
end
|
10
|
+
visit path_to 'homepage'
|
11
|
+
unless response.body.include? "<title> #{title}</title>"
|
12
|
+
raise Exception
|
13
|
+
end
|
14
|
+
|
15
|
+
# Take this so we can reset the DB before each scenario
|
16
|
+
WordPress.original_contents = {}
|
17
|
+
%w[comments
|
18
|
+
links
|
19
|
+
options
|
20
|
+
postmeta
|
21
|
+
posts
|
22
|
+
term_relationships
|
23
|
+
term_taxonomy
|
24
|
+
terms
|
25
|
+
usermeta
|
26
|
+
users].each do |table|
|
27
|
+
WordPress.original_contents[table] = WordPress.mysql.query("select * from #{WordPress.TABLE_PREFIX}#{table}").map{|row|row}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Given /^I am logged in as "([^\"]*)"$/ do |user|
|
32
|
+
visit path_to 'login page'
|
33
|
+
fill_in('Username', :with => user)
|
34
|
+
fill_in('Password', :with => WordPress.passwords[user])
|
35
|
+
click_button('Log In')
|
36
|
+
end
|
37
|
+
|
38
|
+
Given /^plugin "([^\"]*)" is (enabled|disabled)$/ do |plugin,able|
|
39
|
+
Given 'I am logged in as "admin"'
|
40
|
+
visit path_to 'admin dashboard'
|
41
|
+
click_link('Plugins')
|
42
|
+
link = %Q&//a[contains(@href,"#{plugin}")]&
|
43
|
+
if dom.xpath("#{link}/child::text()").any?{|t|t.to_s == 'Activate'}
|
44
|
+
if able == 'enabled'
|
45
|
+
click_link_within("#{link}/..",'Activate')
|
46
|
+
else
|
47
|
+
click_link_within("#{link}/..",'Deactivate')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Then /^there should be (\d+) posts?$/ do |count|
|
53
|
+
WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}posts where ID != 1 and post_type = 'post'").fetch_row.first.to_i.should == count.to_i
|
54
|
+
end
|
55
|
+
|
56
|
+
Then /^there should be (\d+) categories?$/ do |count|
|
57
|
+
# Two initial categories, which we won't count: Uncategorized and Blogroll
|
58
|
+
WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}terms where term_id > 2").fetch_row.first.to_i.should == count.to_i
|
59
|
+
end
|
60
|
+
|
61
|
+
Then /^there should be a category called "([^\"]*)"$/ do |category|
|
62
|
+
WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms where name = '#{Mysql.escape_string(category)}' or slug = '#{Mysql.escape_string(category)}'").fetch_row.first.to_i.should == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
Then /^there should be a post called "([^\"]*)"$/ do |post|
|
66
|
+
WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}posts where post_title = '#{Mysql.escape_string(post)}' or post_name = '#{Mysql.escape_string(post)}'").fetch_row.first.to_i.should == 1
|
67
|
+
end
|
68
|
+
|
69
|
+
Then /^there should be a post called "([^\"]*)" in the "([^\"]*)" category$/ do |post, category|
|
70
|
+
WordPress.mysql.query("select count(*) > 0 from #{WordPress.TABLE_PREFIX}terms join #{WordPress.TABLE_PREFIX}term_relationships join #{WordPress.TABLE_PREFIX}posts where (post_title = '#{Mysql.escape_string(post)}' or post_name = '#{Mysql.escape_string(post)}') and (name = '#{Mysql.escape_string(category)}' or slug = '#{Mysql.escape_string(category)}')").fetch_row.first.to_i.should == 1
|
71
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'mysql'
|
3
|
+
Mysql::Result.send(:include, Enumerable)
|
4
|
+
|
5
|
+
class WordPress
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.method_missing(method, *args)
|
9
|
+
self.instance.send(method, *args)
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :passwords, :mysql, :original_contents
|
13
|
+
attr_accessor :WEBHOST, :DB_NAME, :DB_USER, :DB_PASSWORD, :DB_HOST, :DB_CHARSET, :DB_COLLATE, :TABLE_PREFIX
|
14
|
+
|
15
|
+
def configure(data)
|
16
|
+
@WEBHOST = data['WEBHOST'].to_s
|
17
|
+
@DB_NAME = data['DB_NAME'].to_s
|
18
|
+
@DB_USER = data['DB_USER'].to_s
|
19
|
+
@DB_PASSWORD = data['DB_PASSWORD'].to_s
|
20
|
+
@DB_HOST = data['DB_HOST'].to_s
|
21
|
+
@DB_CHARSET = data['DB_CHARSET'].to_s
|
22
|
+
@DB_COLLATE = data['DB_COLLATE'].to_s
|
23
|
+
@TABLE_PREFIX = data['TABLE_PREFIX'].to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_db
|
27
|
+
@mysql = Mysql::new(@DB_HOST, @DB_USER, @DB_PASSWORD)
|
28
|
+
@mysql.query("create database if not exists #{@DB_NAME} character set = #{@DB_CHARSET}#{@DB_COLLATE.present? ? " collate = #{@DB_COLLATE}" : ''}")
|
29
|
+
@mysql.query("use #{@DB_NAME}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def drop_db
|
33
|
+
@mysql.query("drop database if exists #{@DB_NAME}")
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_config
|
37
|
+
# Copy production DB elsewhere
|
38
|
+
@has_config = File.exist? 'wp-config.php'
|
39
|
+
FileUtils.cp 'wp-config.php', '.wp-config.php' if @has_config
|
40
|
+
|
41
|
+
# Write our own
|
42
|
+
open('wp-config.php','w+') do |f|
|
43
|
+
f.write <<HERE
|
44
|
+
<?php
|
45
|
+
define('DB_NAME', '#{@DB_NAME}');
|
46
|
+
define('DB_USER', '#{@DB_USER}');
|
47
|
+
define('DB_PASSWORD', '#{@DB_PASSWORD}');
|
48
|
+
define('DB_HOST', '#{@DB_HOST}');
|
49
|
+
define('DB_CHARSET', '#{@DB_CHARSET}');
|
50
|
+
define('DB_COLLATE', '#{@DB_COLLATE}');
|
51
|
+
$table_prefix = '#{@TABLE_PREFIX}';
|
52
|
+
if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');
|
53
|
+
require_once(ABSPATH . 'wp-settings.php');
|
54
|
+
HERE
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def reset_config
|
59
|
+
FileUtils.rm 'wp-config.php'
|
60
|
+
FileUtils.mv '.wp-config.php', 'wp-config.php' if @has_config
|
61
|
+
end
|
62
|
+
|
63
|
+
def reset_db
|
64
|
+
@original_contents.nil? ? nil : @original_contents.each_pair do |table,contents|
|
65
|
+
@mysql.query("delete from #{@TABLE_PREFIX}#{table}")
|
66
|
+
contents.each do |row|
|
67
|
+
values = row.map{|v|"#{v.nil? ? 'null' : "'"+Mysql.escape_string(v)+"'"}"}.join(', ')
|
68
|
+
@mysql.query("insert into #{@TABLE_PREFIX}#{table} values (#{values})")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def path_to(page_name)
|
74
|
+
partial = case page_name
|
75
|
+
when /^homepage$/
|
76
|
+
'/'
|
77
|
+
when /^login page$/
|
78
|
+
'/wp-login.php'
|
79
|
+
when /^admin dashboard$/
|
80
|
+
'/wp-admin/'
|
81
|
+
when /^upload new consultation$/
|
82
|
+
'/wp-admin/consultation-new.php'
|
83
|
+
when /^media library$/
|
84
|
+
"/wp-admin/upload.php"
|
85
|
+
else
|
86
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n"
|
87
|
+
end
|
88
|
+
URI::join("http://#{@WEBHOST}/", partial)
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cucumber-wordpress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Adams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-19 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: cucumber
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: webrat
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mysql
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description:
|
46
|
+
email: tom@thedextrousweb.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
|
+
files:
|
54
|
+
- LICENCE
|
55
|
+
- README.rdoc
|
56
|
+
- Rakefile
|
57
|
+
- examples/features/step_definitions/webrat_steps.rb
|
58
|
+
- examples/features/support/config.yml
|
59
|
+
- examples/features/support/env.rb
|
60
|
+
- examples/features/support/paths.rb
|
61
|
+
- examples/features/wordpress.feature
|
62
|
+
- lib/cucumber-wordpress.rb
|
63
|
+
- lib/cucumber-wordpress/steps.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/dxw/cucumber-wordpress
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Environment setup and step definitions for testing WordPress with Cucumber
|
92
|
+
test_files:
|
93
|
+
- examples/features/support/paths.rb
|
94
|
+
- examples/features/support/env.rb
|
95
|
+
- examples/features/step_definitions/webrat_steps.rb
|