From 3e63fcf7ee73b2064d8eb0f21abd0115b205f741 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 7 Mar 2007 18:54:43 +0000 Subject: [PATCH] added some unit tests for wiki git-svn-id: http://redmine.rubyforge.org/svn/branches/work@311 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- wiki/test/fixtures/wiki_content_versions.yml | 41 ++++++++++++++ wiki/test/fixtures/wiki_contents.yml | 17 ++++-- wiki/test/fixtures/wiki_pages.yml | 6 ++ wiki/test/fixtures/wikis.yml | 6 ++ wiki/test/unit/wiki_content_test.rb | 58 ++++++++++++++++++-- wiki/test/unit/wiki_page_test.rb | 50 +++++++++++++++++ wiki/test/unit/wiki_test.rb | 39 +++++++++++++ 7 files changed, 208 insertions(+), 9 deletions(-) create mode 100644 wiki/test/fixtures/wiki_content_versions.yml create mode 100644 wiki/test/fixtures/wiki_pages.yml create mode 100644 wiki/test/fixtures/wikis.yml create mode 100644 wiki/test/unit/wiki_page_test.rb create mode 100644 wiki/test/unit/wiki_test.rb diff --git a/wiki/test/fixtures/wiki_content_versions.yml b/wiki/test/fixtures/wiki_content_versions.yml new file mode 100644 index 000000000..8f174eca4 --- /dev/null +++ b/wiki/test/fixtures/wiki_content_versions.yml @@ -0,0 +1,41 @@ +--- +wiki_content_versions_001: + updated_on: 2007-03-07 00:08:07 +01:00 + page_id: 1 + id: 1 + version: 1 + author_id: 1 + comment: Page creation + wiki_content_id: 1 + compression: "" + data: |- + h1. CookBook documentation + + Some [[documentation]] here... +wiki_content_versions_002: + updated_on: 2007-03-07 00:08:34 +01:00 + page_id: 1 + id: 2 + version: 2 + author_id: 1 + comment: Small update + wiki_content_id: 1 + compression: "" + data: |- + h1. CookBook documentation + + Some updated [[documentation]] here... +wiki_content_versions_003: + updated_on: 2007-03-07 00:10:51 +01:00 + page_id: 1 + id: 3 + version: 3 + author_id: 1 + comment: Gzip compression activated + wiki_content_id: 1 + compression: gzip + data: !binary | + H4sIAPv07UUAC8sw1FNwzs/PdgJihZT85NLc1LySxJLM/DxeLl6u4PzcVIXS + gpTEktQUhehoFPnYWIWM1KJUhfLMkgyF9KrMggKgmozM4pL8okoAf/LnOFYA + AAA= + diff --git a/wiki/test/fixtures/wiki_contents.yml b/wiki/test/fixtures/wiki_contents.yml index b49c4eb4e..ce1c8bd74 100644 --- a/wiki/test/fixtures/wiki_contents.yml +++ b/wiki/test/fixtures/wiki_contents.yml @@ -1,5 +1,12 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -one: - id: 1 -two: - id: 2 +--- +wiki_contents_001: + text: |- + h1. CookBook documentation + + Some updated [[documentation]] here with gzipped history + updated_on: 2007-03-07 00:10:51 +01:00 + page_id: 1 + id: 1 + version: 3 + author_id: 1 + comment: Gzip compression activated diff --git a/wiki/test/fixtures/wiki_pages.yml b/wiki/test/fixtures/wiki_pages.yml new file mode 100644 index 000000000..d488add26 --- /dev/null +++ b/wiki/test/fixtures/wiki_pages.yml @@ -0,0 +1,6 @@ +--- +wiki_pages_001: + created_on: 2007-03-07 00:08:07 +01:00 + title: CookBook_documentation + id: 1 + wiki_id: 1 diff --git a/wiki/test/fixtures/wikis.yml b/wiki/test/fixtures/wikis.yml new file mode 100644 index 000000000..ff7b4a1ae --- /dev/null +++ b/wiki/test/fixtures/wikis.yml @@ -0,0 +1,6 @@ +--- +wikis_001: + status: 1 + start_page: CookBook documentation + project_id: 1 + id: 1 diff --git a/wiki/test/unit/wiki_content_test.rb b/wiki/test/unit/wiki_content_test.rb index af452d7dc..a6b714ebe 100644 --- a/wiki/test/unit/wiki_content_test.rb +++ b/wiki/test/unit/wiki_content_test.rb @@ -1,10 +1,60 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + require File.dirname(__FILE__) + '/../test_helper' class WikiContentTest < Test::Unit::TestCase - fixtures :wiki_contents + fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :users - # Replace this with your real tests. - def test_truth - assert true + def setup + @wiki = Wiki.find(1) + @page = @wiki.pages.first + end + + def test_create + page = WikiPage.new(:wiki => @wiki, :title => "Page") + page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comment => "My comment") + assert page.save + page.reload + + content = page.content + assert_kind_of WikiContent, content + assert_equal 1, content.version + assert_equal 1, content.versions.length + assert_equal "Content text", content.text + assert_equal "My comment", content.comment + assert_equal User.find(1), content.author + assert_equal content.text, content.versions.last.text + end + + def test_update + content = @page.content + version_count = content.version + content.text = "My new content" + assert content.save + content.reload + assert_equal version_count+1, content.version + assert_equal version_count+1, content.versions.length + end + + def test_fetch_history + assert !@page.content.versions.empty? + @page.content.versions.each do |version| + assert_kind_of String, version.text + end end end diff --git a/wiki/test/unit/wiki_page_test.rb b/wiki/test/unit/wiki_page_test.rb new file mode 100644 index 000000000..bfe8aa06f --- /dev/null +++ b/wiki/test/unit/wiki_page_test.rb @@ -0,0 +1,50 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' + +class WikiPageTest < Test::Unit::TestCase + fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions + + def setup + @wiki = Wiki.find(1) + @page = @wiki.pages.first + end + + def test_create + page = WikiPage.new(:wiki => @wiki) + assert !page.save + assert_equal 1, page.errors.count + + page.title = "Page" + assert page.save + page.reload + + @wiki.reload + assert @wiki.pages.include?(page) + end + + def test_find_or_new_page + page = @wiki.find_or_new_page("CookBook documentation") + assert_kind_of WikiPage, page + assert !page.new_record? + + page = @wiki.find_or_new_page("Non existing page") + assert_kind_of WikiPage, page + assert page.new_record? + end +end diff --git a/wiki/test/unit/wiki_test.rb b/wiki/test/unit/wiki_test.rb new file mode 100644 index 000000000..a89be2e71 --- /dev/null +++ b/wiki/test/unit/wiki_test.rb @@ -0,0 +1,39 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' + +class WikiTest < Test::Unit::TestCase + fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions + + def test_create + wiki = Wiki.new(:project => Project.find(2)) + assert !wiki.save + assert_equal 1, wiki.errors.count + + wiki.start_page = "Start page" + assert wiki.save + end + + def test_update + @wiki = Wiki.find(1) + @wiki.start_page = "Another start page" + assert @wiki.save + @wiki.reload + assert_equal "Another start page", @wiki.start_page + end +end