cucumber-wordpress 1.1 → 1.2.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/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
1
  begin
2
2
  require 'jeweler'
3
3
  Jeweler::Tasks.new do |gem|
4
- gem.version = "1.1"
5
4
  gem.name = "cucumber-wordpress"
6
5
  gem.summary = %Q{Environment setup and step definitions for testing WordPress with Cucumber}
7
6
  gem.email = "tom@thedextrousweb.com"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.0
@@ -9,7 +9,7 @@ class WordPress
9
9
  self.instance.send(method, *args)
10
10
  end
11
11
 
12
- attr_accessor :config, :passwords, :mysql, :original_contents
12
+ attr_accessor :config, :passwords, :original_contents, :tables
13
13
  attr_accessor :ABSPATH, :WEBHOST, :DB_NAME, :DB_USER, :DB_PASSWORD, :DB_HOST, :DB_CHARSET, :DB_COLLATE, :TABLE_PREFIX
14
14
 
15
15
  def configure(data)
@@ -23,16 +23,30 @@ class WordPress
23
23
  @DB_CHARSET = data['DB_CHARSET'].to_s
24
24
  @DB_COLLATE = data['DB_COLLATE'].to_s
25
25
  @TABLE_PREFIX = data['TABLE_PREFIX'].to_s
26
+ @tables = %w[comments
27
+ links
28
+ options
29
+ postmeta
30
+ posts
31
+ term_relationships
32
+ term_taxonomy
33
+ terms
34
+ usermeta
35
+ users].map{|t|@TABLE_PREFIX+t}
36
+ end
37
+
38
+ def mysql
39
+ @mysql ||= Mysql::new(@DB_HOST, @DB_USER, @DB_PASSWORD)
40
+ @mysql
26
41
  end
27
42
 
28
43
  def create_db
29
- @mysql = Mysql::new(@DB_HOST, @DB_USER, @DB_PASSWORD)
30
- @mysql.query("create database if not exists #{@DB_NAME} character set = #{@DB_CHARSET}#{@DB_COLLATE.present? ? " collate = #{@DB_COLLATE}" : ''}")
31
- @mysql.query("use #{@DB_NAME}")
44
+ mysql.query("create database #{@DB_NAME} character set = #{@DB_CHARSET}#{@DB_COLLATE.present? ? " collate = #{@DB_COLLATE}" : ''}")
45
+ mysql.query("use #{@DB_NAME}")
32
46
  end
33
47
 
34
48
  def drop_db
35
- @mysql.query("drop database if exists #{@DB_NAME}")
49
+ mysql.query("drop database if exists #{@DB_NAME}")
36
50
  end
37
51
 
38
52
  def write_config
@@ -44,6 +58,7 @@ class WordPress
44
58
  open(File.join(@ABSPATH,'wp-config.php'),'w+') do |f|
45
59
  f.write <<HERE
46
60
  <?php
61
+ define('WP_DEBUG', true);
47
62
  define('DB_NAME', '#{@DB_NAME}');
48
63
  define('DB_USER', '#{@DB_USER}');
49
64
  define('DB_PASSWORD', '#{@DB_PASSWORD}');
@@ -64,10 +79,10 @@ HERE
64
79
 
65
80
  def reset_db
66
81
  @original_contents.nil? ? nil : @original_contents.each_pair do |table,contents|
67
- @mysql.query("delete from #{@TABLE_PREFIX}#{table}")
82
+ mysql.query("delete from #{table}")
68
83
  contents.each do |row|
69
84
  values = row.map{|v|"#{v.nil? ? 'null' : "'"+Mysql.escape_string(v)+"'"}"}.join(', ')
70
- @mysql.query("insert into #{@TABLE_PREFIX}#{table} values (#{values})")
85
+ mysql.query("insert into #{table} values (#{values})")
71
86
  end
72
87
  end
73
88
  end
@@ -88,12 +103,19 @@ HERE
88
103
  '/wp-admin/themes.php'
89
104
  when /^new page$/
90
105
  '/wp-admin/page-new.php'
91
- when /^post "(.+?)"$/
92
- id = WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{$1}"').fetch_row.first.to_i
106
+ when /^(post|page) "(.+?)"$/
107
+ id = WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{$2}"').fetch_row.first.to_i
93
108
  WordPress.php("echo get_permalink(#{id})")
109
+ when /^edit (post|page) "(.+?)"$/
110
+ id = WordPress.mysql.query(%Q'SELECT ID FROM #{WordPress.TABLE_PREFIX}posts WHERE post_title="#{$2}"').fetch_row.first.to_i
111
+ "/wp-admin/#{$1}.php?action=edit&post=#{id}"
94
112
  else
95
113
  return nil
96
114
  end
97
115
  URI::join("http://#{@WEBHOST}/", partial)
98
116
  end
117
+
118
+ def php code
119
+ `php -r 'include "#{WordPress.ABSPATH}/wp-load.php"; #{code};' 2>/dev/null`
120
+ end
99
121
  end
@@ -12,17 +12,8 @@ Given /^WordPress is installed$/ do
12
12
 
13
13
  # Take this so we can reset the DB before each scenario
14
14
  WordPress.original_contents = {}
15
- %w[comments
16
- links
17
- options
18
- postmeta
19
- posts
20
- term_relationships
21
- term_taxonomy
22
- terms
23
- usermeta
24
- users].each do |table|
25
- WordPress.original_contents[table] = WordPress.mysql.query("select * from #{WordPress.TABLE_PREFIX}#{table}").map{|row|row}
15
+ WordPress.tables.each do |table|
16
+ WordPress.original_contents[table] = WordPress.mysql.query("select * from #{table}").map{|row|row}
26
17
  end
27
18
  end
28
19
 
@@ -33,6 +24,11 @@ Given /^I am logged in as "([^\"]*)"$/ do |user|
33
24
  click_button('Log In')
34
25
  end
35
26
 
27
+ Given /^I am not logged in$/ do
28
+ visit path_to 'admin dashboard'
29
+ click_link('Log Out')
30
+ end
31
+
36
32
  Given /^theme "([^\"]*)" is enabled$/ do |theme|
37
33
  Given 'I am logged in as "admin"'
38
34
  Given 'I am on manage themes'
@@ -53,6 +49,36 @@ Given /^plugin "([^\"]*)" is (enabled|disabled)$/ do |plugin,able|
53
49
  end
54
50
  end
55
51
 
52
+ Given /^there is a (post|page) called "([^\"]*)"$/ do |post_type,title|
53
+ visit path_to "new #{post_type}"
54
+ fill_in 'title', :with => title
55
+ click_button 'Publish'
56
+ end
57
+
58
+ Given /^the (post|page) "([^\"]*)" has meta "([^\"]*)" as "(.*)"$/ do |post_type,title,key,value|
59
+ visit path_to %Q%edit #{post_type} "#{title}"%
60
+ fill_in 'metakeyinput', :with => key
61
+ fill_in 'metavalue', :with => value
62
+ click_button 'Update'
63
+ end
64
+
65
+ Given /^the page "([^\"]*)" has template "([^\"]*)"$/ do |title,template|
66
+ visit path_to %Q%edit page "#{title}"%
67
+ select template, :from => 'Page Template'
68
+ click_button 'Update'
69
+ end
70
+
71
+ Given /^permalinks are set as "([^\"]*)"$/ do |structure|
72
+ visit '/wp-admin/options-permalink.php'
73
+ fill_in 'permalink_structure', :with => structure
74
+ click_button 'Save Changes'
75
+ end
76
+
77
+ Given /^option "([^\"]*)" is set to "(.*)"$/ do |option, value|
78
+ WordPress.mysql.query(%Q'DELETE FROM #{WordPress.TABLE_PREFIX}options WHERE option_name="#{Mysql.escape_string option}"')
79
+ WordPress.mysql.query(%Q'INSERT INTO #{WordPress.TABLE_PREFIX}options SET option_name="#{Mysql.escape_string option}", option_value="#{Mysql.escape_string value}"')
80
+ end
81
+
56
82
  Then /^there should be (\d+) posts?$/ do |count|
57
83
  WordPress.mysql.query("select count(*) from #{WordPress.TABLE_PREFIX}posts where ID != 1 and post_type = 'post' and post_status != 'trash'").fetch_row.first.to_i.should == count.to_i
58
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-wordpress
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.1"
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Adams
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-23 00:00:00 +00:00
12
+ date: 2010-03-05 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - LICENCE
56
56
  - README.rdoc
57
57
  - Rakefile
58
+ - VERSION
58
59
  - examples/features/step_definitions/webrat_steps.rb
59
60
  - examples/features/support/config.yml
60
61
  - examples/features/support/env.rb
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  requirements: []
87
88
 
88
89
  rubyforge_project:
89
- rubygems_version: 1.3.5
90
+ rubygems_version: 1.3.3
90
91
  signing_key:
91
92
  specification_version: 3
92
93
  summary: Environment setup and step definitions for testing WordPress with Cucumber