annotate test/unit/lib/redmine/views/builders/xml_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents e248c7af89ec
children
rev   line source
Chris@119 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@119 3 #
Chris@119 4 # This program is free software; you can redistribute it and/or
Chris@119 5 # modify it under the terms of the GNU General Public License
Chris@119 6 # as published by the Free Software Foundation; either version 2
Chris@119 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@119 9 # This program is distributed in the hope that it will be useful,
Chris@119 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@119 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@119 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@119 14 # You should have received a copy of the GNU General Public License
Chris@119 15 # along with this program; if not, write to the Free Software
Chris@119 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@119 17
Chris@119 18 require File.expand_path('../../../../../../test_helper', __FILE__)
Chris@119 19
Chris@909 20 class Redmine::Views::Builders::XmlTest < ActiveSupport::TestCase
Chris@909 21
Chris@119 22 def test_hash
Chris@119 23 assert_xml_output('<person><name>Ryan</name><age>32</age></person>') do |b|
Chris@119 24 b.person do
Chris@119 25 b.name 'Ryan'
Chris@119 26 b.age 32
Chris@119 27 end
Chris@119 28 end
Chris@119 29 end
Chris@909 30
Chris@119 31 def test_array
Chris@119 32 assert_xml_output('<books type="array"><book title="Book 1"/><book title="Book 2"/></books>') do |b|
Chris@119 33 b.array :books do |b|
Chris@119 34 b.book :title => 'Book 1'
Chris@119 35 b.book :title => 'Book 2'
Chris@119 36 end
Chris@119 37 end
Chris@119 38 end
Chris@909 39
Chris@119 40 def test_array_with_content_tags
Chris@119 41 assert_xml_output('<books type="array"><book author="B. Smith">Book 1</book><book author="G. Cooper">Book 2</book></books>') do |b|
Chris@119 42 b.array :books do |b|
Chris@119 43 b.book 'Book 1', :author => 'B. Smith'
Chris@119 44 b.book 'Book 2', :author => 'G. Cooper'
Chris@119 45 end
Chris@119 46 end
Chris@119 47 end
Chris@909 48
Chris@1115 49 def test_nested_arrays
Chris@1115 50 assert_xml_output('<books type="array"><book><authors type="array"><author>B. Smith</author><author>G. Cooper</author></authors></book></books>') do |b|
Chris@1115 51 b.array :books do |books|
Chris@1115 52 books.book do |book|
Chris@1115 53 book.array :authors do |authors|
Chris@1115 54 authors.author 'B. Smith'
Chris@1115 55 authors.author 'G. Cooper'
Chris@1115 56 end
Chris@1115 57 end
Chris@1115 58 end
Chris@1115 59 end
Chris@1115 60 end
Chris@1115 61
Chris@119 62 def assert_xml_output(expected, &block)
Chris@1115 63 builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.new, ActionDispatch::TestResponse.new)
Chris@119 64 block.call(builder)
Chris@119 65 assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output)
Chris@119 66 end
Chris@119 67 end