Fixed false positive theme detection

This commit is contained in:
Christian Mehlmauer
2014-07-16 18:25:35 +02:00
parent 102e30c29a
commit 6ebb9b6f66
6 changed files with 50 additions and 22 deletions

View File

@@ -15,9 +15,9 @@ class WpTheme < WpItem
include WpTheme::Output
include WpTheme::Childtheme
attr_writer :style_url
attr_accessor :additional_url
def allowed_options; super << :style_url end
def allowed_options; super << :additional_url end
def initialize(*args)
super(*args)
@@ -36,10 +36,7 @@ class WpTheme < WpItem
# @return [ String ] The url to the theme stylesheet
def style_url
unless @style_url
@style_url = uri.merge('style.css').to_s
end
@style_url
uri.merge('style.css').to_s
end
end

View File

@@ -30,13 +30,13 @@ class WpTheme < WpItem
response = Browser.get_and_follow_location(target_uri.to_s)
# https + domain is optional because of relative links
matches = %r{(?:https?://[^"']+)?/([^/]+)/themes/([^"']+)/style.css}i.match(response.body)
matches = /(?:https?:\/\/[^"']+)?\/([^\/]+)\/themes\/([^"'\/]+)[^"']*\/style.css/i.match(response.body)
if matches
return new(
target_uri,
{
name: matches[2],
style_url: matches[0],
additional_url: matches[0],
wp_content_dir: matches[1]
}
)

View File

@@ -7,6 +7,7 @@ class WpTheme
def additional_output(verbose = false)
theme_desc = verbose ? @theme_description : truncate(@theme_description, 100)
puts " | Style URL: #{style_url}"
puts " | Additional URL: #{additional_url}" if additional_url
puts " | Theme Name: #@theme_name" if @theme_name
puts " | Theme URI: #@theme_uri" if @theme_uri
puts " | Description: #{theme_desc}"

View File

@@ -52,6 +52,13 @@ describe 'WpTheme::Findable' do
end
end
context 'when other style.css is referenced' do
it 'returns the WpTheme' do
@file = 'yootheme.html'
@expected = WpTheme.new(uri, name: 'yoo_solar_wp')
end
end
end
describe '::find_from_wooframework' do

View File

@@ -29,24 +29,11 @@ describe WpTheme do
let(:theme_path) { 'wp-content/themes/theme-name/' }
describe '#allowed_options' do
its(:allowed_options) { is_expected.to include :style_url }
its(:allowed_options) { is_expected.to include :additional_url }
end
describe '#forge_uri' do
its(:uri) { is_expected.to eq uri.merge(theme_path) }
end
describe '#style_url' do
its(:style_url) { is_expected.to eq uri.merge(theme_path + '/style.css').to_s }
context 'when its already set' do
it 'returns it instead of the default one' do
url = uri.merge(theme_path + '/custom.css').to_s
wp_theme.style_url = url
expect(wp_theme.style_url).to eq url
end
end
end
end

View File

@@ -0,0 +1,36 @@
<!DOCTYPE HTML>
<html lang="de-DE" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>XXXXX </title>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://domain.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://domain.com/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 3.9.1" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/base.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/layout.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/menus.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/modules.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/tools.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/system.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/extensions.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/custom.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/animation.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/texture/noise.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/color/green.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/font1/droidsans.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/font2/droidsans.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/font3/droidsans.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/styles/wood/css/style.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/responsive.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/css/print.css" />
<link rel="stylesheet" href="/wp-content/themes/yoo_solar_wp/fonts/droidsans.css" />
<script src="/wp-content/themes/yoo_solar_wp/warp/js/warp.js"></script>
</head>
<body></body>
</html>