|
1 |
# Redmine - project management software
|
|
2 |
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or
|
|
5 |
# modify it under the terms of the GNU General Public License
|
|
6 |
# as published by the Free Software Foundation; either version 2
|
|
7 |
# of the License, or (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 |
|
|
18 |
require File.expand_path('../../../test_helper', __FILE__)
|
|
19 |
|
|
20 |
class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base
|
|
21 |
fixtures :projects, :issues
|
|
22 |
|
|
23 |
test "GET /search.xml should return xml content" do
|
|
24 |
get '/search.xml'
|
|
25 |
|
|
26 |
assert_response :success
|
|
27 |
assert_equal 'application/xml', @response.content_type
|
|
28 |
end
|
|
29 |
|
|
30 |
test "GET /search.json should return json content" do
|
|
31 |
get '/search.json'
|
|
32 |
|
|
33 |
assert_response :success
|
|
34 |
assert_equal 'application/json', @response.content_type
|
|
35 |
|
|
36 |
json = ActiveSupport::JSON.decode(response.body)
|
|
37 |
assert_kind_of Hash, json
|
|
38 |
assert_kind_of Array, json['results']
|
|
39 |
end
|
|
40 |
|
|
41 |
test "GET /search.xml without query strings should return empty results" do
|
|
42 |
get '/search.xml', :q => '', :all_words => ''
|
|
43 |
|
|
44 |
assert_response :success
|
|
45 |
assert_equal 0, assigns(:results).size
|
|
46 |
end
|
|
47 |
|
|
48 |
test "GET /search.xml with query strings should return results" do
|
|
49 |
get '/search.xml', :q => 'recipe subproject commit', :all_words => ''
|
|
50 |
|
|
51 |
assert_response :success
|
|
52 |
assert_not_empty(assigns(:results))
|
|
53 |
|
|
54 |
assert_select 'results[type=array]' do
|
|
55 |
assert_select 'result', :count => assigns(:results).count
|
|
56 |
assigns(:results).size.times.each do |i|
|
|
57 |
assert_select 'result' do
|
|
58 |
assert_select 'id', :text => assigns(:results)[i].id.to_s
|
|
59 |
assert_select 'title', :text => assigns(:results)[i].event_title
|
|
60 |
assert_select 'type', :text => assigns(:results)[i].event_type
|
|
61 |
assert_select 'url', :text => url_for(assigns(:results)[i].event_url(:only_path => false))
|
|
62 |
assert_select 'description', :text => assigns(:results)[i].event_description
|
|
63 |
assert_select 'datetime'
|
|
64 |
end
|
|
65 |
end
|
|
66 |
end
|
|
67 |
end
|
|
68 |
end
|