Move gollum back end to gollum-lib #647
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
<ol class="tree">
|
||||
<li class="file">
|
||||
<a href="0"><span class="icon"></span>0</a>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -1,11 +0,0 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>folder0</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder0/0"><span class="icon"></span>0</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -1,11 +0,0 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>.</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder0"><span class="icon"></span>folder0</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -1,20 +0,0 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>folder0</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder0/0"><span class="icon"></span>0</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder1</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder1/1"><span class="icon"></span>1</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -1,23 +0,0 @@
|
||||
<ol class="tree">
|
||||
<li class="file">
|
||||
<a href="root"><span class="icon"></span>root</a>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder0</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder0/0"><span class="icon"></span>0</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder1</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder1/1"><span class="icon"></span>1</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -1,41 +0,0 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>folder0</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li>
|
||||
<label>folder1</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li>
|
||||
<label>folder2</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder0/folder1/folder2/0"><span class="icon"></span>0</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder3</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder0/folder1/folder3/1"><span class="icon"></span>1</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder4</label>
|
||||
<input type="checkbox" />
|
||||
<ol>
|
||||
<li class="file">
|
||||
<a href="folder4/2"><span class="icon"></span>2</a>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
+4
-1
@@ -4,6 +4,9 @@ require 'test/unit'
|
||||
require 'shoulda'
|
||||
require 'mocha/setup'
|
||||
require 'fileutils'
|
||||
require 'minitest/reporters'
|
||||
|
||||
MiniTest::Reporters.use!
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
$LOAD_PATH.unshift(File.join(dir, '..', 'lib'))
|
||||
@@ -11,7 +14,7 @@ $LOAD_PATH.unshift(dir)
|
||||
|
||||
ENV['RACK_ENV'] = 'test'
|
||||
require 'gollum'
|
||||
require 'gollum/frontend/app'
|
||||
require 'gollum/app'
|
||||
|
||||
# Disable the metadata feature
|
||||
$METADATA = false
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
||||
|
||||
context "Wiki" do
|
||||
setup do
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
|
||||
end
|
||||
|
||||
test "normalizes commit hash" do
|
||||
commit = {:message => 'abc'}
|
||||
name = @wiki.repo.config['user.name'] || @wiki.default_committer_name
|
||||
email = @wiki.repo.config['user.email'] || @wiki.default_committer_email
|
||||
committer = Gollum::Committer.new(@wiki, commit)
|
||||
assert_equal name, committer.actor.name
|
||||
assert_equal email, committer.actor.email
|
||||
|
||||
commit[:name] = 'bob'
|
||||
commit[:email] = ''
|
||||
committer = Gollum::Committer.new(@wiki, commit)
|
||||
assert_equal 'bob', committer.actor.name
|
||||
assert_equal email, committer.actor.email
|
||||
|
||||
commit[:email] = 'foo@bar.com'
|
||||
committer = Gollum::Committer.new(@wiki, commit)
|
||||
assert_equal 'bob', committer.actor.name
|
||||
assert_equal 'foo@bar.com', committer.actor.email
|
||||
end
|
||||
|
||||
test "yield after_commit callback" do
|
||||
@path = cloned_testpath('examples/lotr.git')
|
||||
yielded = nil
|
||||
begin
|
||||
wiki = Gollum::Wiki.new(@path)
|
||||
committer = Gollum::Committer.new(wiki)
|
||||
committer.after_commit do |index, sha1|
|
||||
yielded = sha1
|
||||
assert_equal committer, index
|
||||
end
|
||||
|
||||
res = wiki.write_page("Gollum", :markdown, "# Gollum",
|
||||
:committer => committer)
|
||||
|
||||
assert_equal committer, res
|
||||
|
||||
sha1 = committer.commit
|
||||
assert_equal sha1, yielded
|
||||
ensure
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
|
||||
test "parents with default master ref" do
|
||||
ref = '874f597a5659b4c3b153674ea04e406ff393975e'
|
||||
committer = Gollum::Committer.new(@wiki)
|
||||
assert_equal ref, committer.parents.first.sha
|
||||
end
|
||||
|
||||
test "parents with custom ref" do
|
||||
ref = '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), :ref => ref)
|
||||
committer = Gollum::Committer.new(@wiki)
|
||||
assert_equal ref, committer.parents.first.sha
|
||||
end
|
||||
end
|
||||
@@ -1,45 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
path = File.join(File.dirname(__FILE__), "helper")
|
||||
require File.expand_path(path)
|
||||
|
||||
context "File" do
|
||||
setup do
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
|
||||
end
|
||||
|
||||
test "new file" do
|
||||
file = Gollum::File.new(@wiki)
|
||||
assert_nil file.raw_data
|
||||
end
|
||||
|
||||
test "existing file" do
|
||||
commit = @wiki.repo.commits.first
|
||||
file = @wiki.file("Mordor/todo.txt")
|
||||
assert_equal "[ ] Write section on Ents\n", file.raw_data
|
||||
assert_equal 'todo.txt', file.name
|
||||
assert_equal commit.id, file.version.id
|
||||
assert_equal commit.author.name, file.version.author.name
|
||||
end
|
||||
|
||||
test "accessing tree" do
|
||||
assert_nil @wiki.file("Mordor")
|
||||
end
|
||||
end
|
||||
|
||||
context "File with checkout" do
|
||||
setup do
|
||||
@path = cloned_testpath("examples/lotr.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "symbolic link" do
|
||||
commit = @wiki.repo.commits.first
|
||||
file = @wiki.file("Data-Two.csv")
|
||||
|
||||
assert_match /^FirstName,LastName\n/, file.raw_data
|
||||
end
|
||||
end
|
||||
@@ -1,120 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/file_view', __FILE__
|
||||
|
||||
class FakePage
|
||||
def initialize filepath
|
||||
@filepath = filepath
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def filename_stripped
|
||||
::File.basename(@filepath, ::File.extname(@filepath))
|
||||
end
|
||||
|
||||
def filename
|
||||
::File.basename(@filepath)
|
||||
end
|
||||
|
||||
def path
|
||||
return @filepath
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def name
|
||||
self.class.canonicalize_filename @filepath
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def self.strip_filename filename
|
||||
::File.basename( filename, ::File.extname( filename ))
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def self.canonicalize_filename filename
|
||||
strip_filename(filename).gsub('-', ' ')
|
||||
end
|
||||
end
|
||||
|
||||
class FakePages
|
||||
def initialize filepath_array
|
||||
@array = filepath_array.map { | filepath | FakePage.new filepath }
|
||||
end
|
||||
|
||||
def size
|
||||
@array.size
|
||||
end
|
||||
|
||||
def [] index
|
||||
@array[ index ]
|
||||
end
|
||||
end
|
||||
|
||||
def view pages
|
||||
Gollum::FileView.new( pages ).render_files
|
||||
end
|
||||
|
||||
@@test_path = File.expand_path( '../file_view/' , __FILE__ ) + '/'
|
||||
|
||||
def read file
|
||||
File.read @@test_path + file + '.txt'
|
||||
end
|
||||
|
||||
# For creating expected files.
|
||||
# write name, actual
|
||||
def write file, content
|
||||
File.open(@@test_path + file + '.txt', 'w') do | f |
|
||||
f.write content
|
||||
end
|
||||
end
|
||||
|
||||
def to_html html
|
||||
# Remove blank nodes for proper formatting
|
||||
doc = Nokogiri.XML(html) do |cfg|
|
||||
cfg.default_xml.noblanks
|
||||
end
|
||||
|
||||
# Save as XHTML
|
||||
doc.to_xml( { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML, :indent => 2, :encoding => 'UTF-8' } )
|
||||
end
|
||||
|
||||
def check name, pages_array
|
||||
pages = FakePages.new pages_array
|
||||
expected = read name
|
||||
actual = to_html view pages
|
||||
|
||||
# Uncomment when updating tests
|
||||
# write name, actual
|
||||
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
# Test Notes
|
||||
# root files must be before any folders.
|
||||
# Home.md => file at root folder
|
||||
# docs/sanitization.md => file within folder
|
||||
context 'file_view' do
|
||||
test 'one file' do
|
||||
check '1_file', [ '0.md' ]
|
||||
end
|
||||
|
||||
test 'one folder' do
|
||||
check '1_folder', [ 'folder0/' ]
|
||||
end
|
||||
|
||||
test 'one file with one folder' do
|
||||
check '1_file_1_folder', [ 'folder0/0.md' ]
|
||||
end
|
||||
|
||||
test 'two files with two folders' do
|
||||
check '2_files_2_folders', [ 'folder0/0.md', 'folder1/1.md' ]
|
||||
end
|
||||
|
||||
test 'two files with two folders and one root file' do
|
||||
check '2_files_2_folders_1_root', [ 'root.md', 'folder0/0.md', 'folder1/1.md' ]
|
||||
end
|
||||
|
||||
test 'nested folders' do
|
||||
check 'nested_folders', [ 'folder0/folder1/folder2/0.md', 'folder0/folder1/folder3/1.md', 'folder4/2.md' ]
|
||||
end
|
||||
end # context
|
||||
@@ -1,64 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
||||
|
||||
context "GitAccess" do
|
||||
setup do
|
||||
@access = Gollum::GitAccess.new(testpath("examples/lotr.git"))
|
||||
end
|
||||
|
||||
test "#commit fills commit_map cache" do
|
||||
assert @access.commit_map.empty?
|
||||
actual = @access.repo.commits.first
|
||||
expected = @access.commit(actual.id)
|
||||
assert_equal actual.message, expected.message
|
||||
assert_equal actual.message, @access.commit_map[actual.id].message
|
||||
end
|
||||
|
||||
test "#tree_map_for caches ref and tree" do
|
||||
assert @access.ref_map.empty?
|
||||
assert @access.tree_map.empty?
|
||||
@access.tree 'master'
|
||||
assert_equal({"master"=>"874f597a5659b4c3b153674ea04e406ff393975e"}, @access.ref_map)
|
||||
|
||||
@access.tree '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'
|
||||
map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3']
|
||||
assert_equal 'Bilbo-Baggins.md', map[0].path
|
||||
assert_equal '', map[0].dir
|
||||
assert_equal map[0].path, map[0].name
|
||||
assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
|
||||
assert_equal '/Mordor', map[3].dir
|
||||
assert_equal 'Eye-Of-Sauron.md', map[3].name
|
||||
end
|
||||
|
||||
test "#tree_map_for only caches tree for commit" do
|
||||
assert @access.tree_map.empty?
|
||||
@access.tree '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
|
||||
assert @access.ref_map.empty?
|
||||
|
||||
entry = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
|
||||
assert_equal 'Bilbo-Baggins.md', entry.path
|
||||
end
|
||||
|
||||
test "cannot access commit from invalid ref" do
|
||||
assert_nil @access.commit('foo')
|
||||
end
|
||||
|
||||
test "cannot access sha from invalid ref" do
|
||||
assert_nil @access.ref_to_sha('foo')
|
||||
end
|
||||
|
||||
test "cannot access tree from invalid ref" do
|
||||
assert_equal [], @access.tree('foo')
|
||||
end
|
||||
|
||||
test "sets #mode for blob entries" do
|
||||
@access.tree '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
|
||||
file = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
|
||||
assert_equal 0100644, file.mode
|
||||
|
||||
@access.tree '874f597a5659b4c3b153674ea04e406ff393975e'
|
||||
symlink = @access.tree_map['874f597a5659b4c3b153674ea04e406ff393975e'].find { |entry| entry.name == 'Data-Two.csv' }
|
||||
assert_not_nil symlink
|
||||
assert_equal 0120000, symlink.mode
|
||||
end
|
||||
end
|
||||
@@ -1,100 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path( '../helper', __FILE__ )
|
||||
require File.expand_path( '../wiki_factory', __FILE__ )
|
||||
|
||||
context "gitcode" do
|
||||
|
||||
def page_with_content c
|
||||
index = @wiki.repo.index
|
||||
index.add 'Sample-Html.md', c
|
||||
index.commit 'adding file html sample'
|
||||
|
||||
page = @wiki.page 'Sample Html'
|
||||
page
|
||||
end
|
||||
|
||||
setup do
|
||||
# context
|
||||
@wiki, @path, @cleanup = WikiFactory.create 'examples/test.git'
|
||||
|
||||
# given
|
||||
p = page_with_content "a\n\n```html:gollum/gollum/master/test/file_view/1_file.txt```\n\nb"
|
||||
|
||||
# when rendering the page
|
||||
@rendered = Gollum::Markup.new(p).render
|
||||
end
|
||||
|
||||
test 'that the rendered output is correctly fetched and rendered as html code' do
|
||||
assert_equal %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"nt\"><ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">></span>\n <span class=\"nt\"><li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">></span>\n <span class=\"nt\"><a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">><span</span> <span class=\"na\">class=</span><span class=\"s\">\"icon\"</span><span class=\"nt\">></span></span>0<span class=\"nt\"></a></span>\n <span class=\"nt\"></li></span>\n<span class=\"nt\"></ol></span>\n</pre></div>\n\n<p>b</p>}, @rendered
|
||||
end
|
||||
|
||||
test 'contents' do
|
||||
g = Gollum::Gitcode.new 'gollum/gollum/master/test/file_view/1_file.txt'
|
||||
|
||||
assert_equal g.contents, %{<ol class=\"tree\">\n <li class=\"file\">\n <a href=\"0\"><span class=\"icon\"></span>0</a>\n </li>\n</ol>\n}
|
||||
end
|
||||
|
||||
test "gitcode relative local file" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:file-exists.py```\nb", commit_details)
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("file-exists.py", "import sys\n\nprint sys.maxint\n")
|
||||
index.commit("Add file-exists.py")
|
||||
|
||||
@wiki.clear_cache
|
||||
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
|
||||
end
|
||||
|
||||
test "gitcode relative local file in subdir" do
|
||||
index = @wiki.repo.index
|
||||
index.add("foo/file-exists.py", "import sys\n\nprint sys.maxint\n")
|
||||
index.commit("Add file-exists.py")
|
||||
|
||||
@wiki.write_page("Pippin", :markdown, "a\n```python:file-exists.py```\nb", commit_details, 'foo')
|
||||
|
||||
page = @wiki.paged('Pippin', 'foo')
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span>\n</pre></div>\n\n<p>b</p>}, output
|
||||
end
|
||||
|
||||
test "gitcode relative no file" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:no-file-exists.py```\nb", commit_details)
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\nFile not found: no-file-exists.py\nb</p>}, output
|
||||
end
|
||||
|
||||
test "gitcode absolute local file" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:/monkey/file-exists.py```\nb", commit_details)
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("monkey/file-exists.py", "import sys\n\nprint sys.platform\n")
|
||||
index.commit("Add monkey/file-exists.py")
|
||||
@wiki.clear_cache
|
||||
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\n</p><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>\n\n<span class="k">print</span> <span class="n">sys</span><span class="o">.</span><span class="n">platform</span>\n</pre></div>\n\n<p>b</p>}, output
|
||||
end
|
||||
|
||||
test "gitcode absolute no file" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:/monkey/no-file-exists.py```\nb", commit_details)
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\nFile not found: /monkey/no-file-exists.py\nb</p>}, output
|
||||
end
|
||||
|
||||
test "gitcode error generates santized html" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a\n```python:<script>foo</script>```\nb", commit_details)
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\nFile not found: <script>foo</script>\nb</p>}, output
|
||||
end
|
||||
|
||||
teardown do
|
||||
@cleanup.call
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/frontend/views/history', __FILE__
|
||||
require File.expand_path '../../lib/gollum/views/history', __FILE__
|
||||
|
||||
context "Precious::Views::History" do
|
||||
setup do
|
||||
|
||||
@@ -1,824 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path( "../helper", __FILE__ )
|
||||
require File.expand_path( "../wiki_factory", __FILE__ )
|
||||
|
||||
context "Markup" do
|
||||
setup do
|
||||
@wiki, @path, @teardown = WikiFactory.create 'examples/test.git'
|
||||
end
|
||||
|
||||
teardown do
|
||||
@teardown.call
|
||||
end
|
||||
|
||||
test "formats page from Wiki#pages" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
|
||||
assert @wiki.pages[0].formatted_data
|
||||
end
|
||||
|
||||
# This test is to assume that Sanitize.clean doesn't raise Encoding::CompatibilityError on ruby 1.9
|
||||
test "formats non ASCII-7 character page from Wiki#pages" do
|
||||
wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
|
||||
assert_nothing_raised(defined?(Encoding) && Encoding::CompatibilityError) do
|
||||
assert wiki.page("strider").formatted_data
|
||||
end
|
||||
end
|
||||
|
||||
test "Gollum::Markup#render yields a DocumentFragment" do
|
||||
yielded = false
|
||||
@wiki.write_page("Yielded", :markdown, "abc", commit_details)
|
||||
|
||||
page = @wiki.page("Yielded")
|
||||
markup = Gollum::Markup.new(page)
|
||||
markup.render do |doc|
|
||||
assert_kind_of Nokogiri::HTML::DocumentFragment, doc
|
||||
yielded = true
|
||||
end
|
||||
assert yielded
|
||||
end
|
||||
|
||||
test "Gollum::Page#formatted_data yields a DocumentFragment" do
|
||||
yielded = false
|
||||
@wiki.write_page("Yielded", :markdown, "abc", commit_details)
|
||||
|
||||
page = @wiki.page("Yielded")
|
||||
page.formatted_data do |doc|
|
||||
assert_kind_of Nokogiri::HTML::DocumentFragment, doc
|
||||
yielded = true
|
||||
end
|
||||
assert yielded
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Links
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "absolute link to non-existent page" do
|
||||
@wiki.write_page("linktest", :markdown, "[[/Page]]", commit_details)
|
||||
|
||||
page = @wiki.page("linktest")
|
||||
doc = Nokogiri::HTML page.formatted_data
|
||||
paras = doc / :p
|
||||
para = paras.first
|
||||
anchors = para / :a
|
||||
assert_equal 1, paras.size
|
||||
assert_equal 1, anchors.size
|
||||
assert_equal 'internal absent', anchors[0]['class']
|
||||
assert_equal '/Page', anchors[0]['href']
|
||||
assert_equal '/Page', anchors[0].text
|
||||
end
|
||||
|
||||
test "double page links no space" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
|
||||
|
||||
# "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a><a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
doc = Nokogiri::HTML page.formatted_data
|
||||
paras = doc / :p
|
||||
para = paras.first
|
||||
anchors = para / :a
|
||||
assert_equal 1, paras.size
|
||||
assert_equal 2, anchors.size
|
||||
assert_equal 'internal absent', anchors[0]['class']
|
||||
assert_equal 'internal absent', anchors[1]['class']
|
||||
assert_equal '/Foo', anchors[0]['href']
|
||||
assert_equal '/Bar', anchors[1]['href']
|
||||
assert_equal 'Foo', anchors[0].text
|
||||
assert_equal 'Bar', anchors[1].text
|
||||
end
|
||||
|
||||
test "double page links with space" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]] [[Bar]] b", commit_details)
|
||||
|
||||
# "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a> <a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
doc = Nokogiri::HTML page.formatted_data
|
||||
paras = doc / :p
|
||||
para = paras.first
|
||||
anchors = para / :a
|
||||
assert_equal 1, paras.size
|
||||
assert_equal 2, anchors.size
|
||||
assert_equal 'internal absent', anchors[0]['class']
|
||||
assert_equal 'internal absent', anchors[1]['class']
|
||||
assert_equal '/Foo', anchors[0]['href']
|
||||
assert_equal '/Bar', anchors[1]['href']
|
||||
assert_equal 'Foo', anchors[0].text
|
||||
assert_equal 'Bar', anchors[1].text
|
||||
end
|
||||
|
||||
test "page link" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", commit_details)
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
output = page.formatted_data
|
||||
assert_match /class="internal present"/, output
|
||||
assert_match /href="\/Bilbo-Baggins"/, output
|
||||
assert_match /\>Bilbo Baggins\</, output
|
||||
end
|
||||
|
||||
test "adds nofollow to links on historical pages" do
|
||||
sha1 = @wiki.write_page("Sauron", :markdown, "a [[b]] c", commit_details)
|
||||
page = @wiki.page("Sauron")
|
||||
sha2 = @wiki.update_page(page, page.name, :markdown, "c [[b]] a", commit_details)
|
||||
regx = /rel="nofollow"/
|
||||
assert_no_match regx, page.formatted_data
|
||||
assert_match regx, @wiki.page(page.name, sha1).formatted_data
|
||||
assert_match regx, @wiki.page(page.name, sha2).formatted_data
|
||||
end
|
||||
|
||||
test "absent page link" do
|
||||
@wiki.write_page("Tolkien", :markdown, "a [[J. R. R. Tolkien]]'s b", commit_details)
|
||||
|
||||
page = @wiki.page("Tolkien")
|
||||
output = page.formatted_data
|
||||
assert_match /class="internal absent"/, output
|
||||
assert_match /href="\/J\.\-R\.\-R\.\-Tolkien"/, output
|
||||
assert_match /\>J\. R\. R\. Tolkien\</, output
|
||||
end
|
||||
|
||||
test "page link with custom base path" do
|
||||
["/wiki", "/wiki/"].each_with_index do |path, i|
|
||||
name = "Bilbo Baggins #{i}"
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => path)
|
||||
@wiki.write_page(name, :markdown, "a [[#{name}]] b", commit_details)
|
||||
|
||||
page = @wiki.page(name)
|
||||
output = page.formatted_data
|
||||
assert_match /class="internal present"/, output
|
||||
assert_match /href="\/wiki\/Bilbo-Baggins-\d"/, output
|
||||
assert_match /\>Bilbo Baggins \d\</, output
|
||||
end
|
||||
end
|
||||
|
||||
test "page link with included #" do
|
||||
@wiki.write_page("Precious #1", :markdown, "a [[Precious #1]] b", commit_details)
|
||||
page = @wiki.page('Precious #1')
|
||||
output = page.formatted_data
|
||||
assert_match /class="internal present"/, output
|
||||
assert_match /href="\/Precious-%231"/, output
|
||||
end
|
||||
|
||||
test "page link with extra #" do
|
||||
@wiki.write_page("Potato", :markdown, "a [[Potato#1]] b", commit_details)
|
||||
page = @wiki.page('Potato')
|
||||
output = page.formatted_data
|
||||
assert_match /class="internal present"/, output
|
||||
assert_match /href="\/Potato#1"/, output
|
||||
end
|
||||
|
||||
test "external page link" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
|
||||
end
|
||||
|
||||
test "page link with different text" do
|
||||
@wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
output = page.formatted_data
|
||||
assert_equal "<p>a<aclass=\"internalpresent\"href=\"/Potato\">PotatoHeaad</a></p>", normal(output)
|
||||
end
|
||||
|
||||
test "page link with different text on mediawiki" do
|
||||
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
output = page.formatted_data
|
||||
assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>
|
||||
"), normal(output)
|
||||
end
|
||||
|
||||
test "wiki link within inline code block" do
|
||||
@wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
assert_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
|
||||
end
|
||||
|
||||
test "regexp gsub! backref (#383)" do
|
||||
# bug only triggers on "```" syntax
|
||||
# not `code`
|
||||
page = 'test_rgx'
|
||||
@wiki.write_page(page, :markdown,
|
||||
(<<-'DATA'
|
||||
```
|
||||
rot13='tr '\''A-Za-z'\'' '\''N-ZA-Mn-za-m'\'
|
||||
```
|
||||
DATA
|
||||
), commit_details)
|
||||
output = @wiki.page(page).formatted_data
|
||||
expected = %Q{<pre><code> <div class=\"highlight\"><pre><span class=\"n\">rot13</span><span class=\"o\">=</span><span class=\"err\">'</span><span class=\"n\">tr</span> <span class=\"sc\">'\\''</span><span class=\"n\">A</span><span class=\"o\">-</span><span class=\"n\">Za</span><span class=\"o\">-</span><span class=\"n\">z</span><span class=\"sc\">'\\''</span> <span class=\"sc\">'\\''</span><span class=\"n\">N</span><span class=\"o\">-</span><span class=\"n\">ZA</span><span class=\"o\">-</span><span class=\"n\">Mn</span><span class=\"o\">-</span><span class=\"n\">za</span><span class=\"o\">-</span><span class=\"n\">m</span><span class=\"err\">'\\'</span>\n</pre></div>\n</code></pre>}
|
||||
assert_equal expected, output
|
||||
end
|
||||
|
||||
# Issue #568
|
||||
test "tilde code blocks without a language" do
|
||||
page = 'test_rgx'
|
||||
@wiki.write_page(page, :markdown,
|
||||
%Q(~~~
|
||||
'hi'
|
||||
~~~
|
||||
), commit_details)
|
||||
output = @wiki.page(page).formatted_data
|
||||
expected = %Q{<div class=\"highlight\"><pre><span class=\"err\">'</span><span class=\"n\">hi</span><span class=\"err\">'</span>\n</pre></div>}
|
||||
assert_equal expected, output
|
||||
end
|
||||
|
||||
test "tilde code blocks #537" do
|
||||
page = 'test_rgx'
|
||||
@wiki.write_page(page, :markdown,
|
||||
%Q(~~~ {.ruby}
|
||||
'hi'
|
||||
~~~
|
||||
), commit_details)
|
||||
output = @wiki.page(page).formatted_data
|
||||
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
|
||||
assert_equal expected, output
|
||||
end
|
||||
|
||||
# Issue #537
|
||||
test "tilde code blocks with more than one class" do
|
||||
page = 'test_rgx'
|
||||
@wiki.write_page(page, :markdown,
|
||||
%Q(~~~ {#hi .ruby .sauce}
|
||||
'hi'
|
||||
~~~
|
||||
), commit_details)
|
||||
output = @wiki.page(page).formatted_data
|
||||
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
|
||||
assert_equal expected, output
|
||||
end
|
||||
|
||||
# Issue #537
|
||||
test "tilde code blocks with lots of tildes" do
|
||||
page = 'test_rgx'
|
||||
@wiki.write_page(page, :markdown,
|
||||
%Q(~~~~~~ {#hi .ruby .sauce}
|
||||
~~
|
||||
'hi'~
|
||||
~~~~~~
|
||||
), commit_details)
|
||||
output = @wiki.page(page).formatted_data
|
||||
expected = %Q{<div class=\"highlight\"><pre><span class=\"o\">~~</span>\n<span class=\"s1\">'hi'</span><span class=\"o\">~</span>\n</pre></div>}
|
||||
assert_equal expected, output
|
||||
end
|
||||
|
||||
test "four space indented code block" do
|
||||
page = 'test_four'
|
||||
@wiki.write_page(page, :markdown,
|
||||
%( test
|
||||
test), commit_details)
|
||||
output = @wiki.page(page).formatted_data
|
||||
expected = %(<pre><code>test\ntest\n</code></pre>)
|
||||
assert_equal expected, output
|
||||
end
|
||||
|
||||
test "wiki link within code block" do
|
||||
@wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
assert_equal "<pre><code>sed -i '' 's/[[:space:]]*$//'\n</code></pre>", page.formatted_data
|
||||
end
|
||||
|
||||
test "piped wiki link within code block" do
|
||||
@wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
assert_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Images
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "image with http url" do
|
||||
['http', 'https'].each do |scheme|
|
||||
name = "Bilbo Baggins #{scheme}"
|
||||
@wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", commit_details)
|
||||
|
||||
page = @wiki.page(name)
|
||||
output = page.formatted_data
|
||||
assert_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.jpg\" /> b</p>}, output
|
||||
end
|
||||
end
|
||||
|
||||
test "image with extension in caps with http url" do
|
||||
['http', 'https'].each do |scheme|
|
||||
name = "Bilbo Baggins #{scheme}"
|
||||
@wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.JPG]] b", commit_details)
|
||||
|
||||
page = @wiki.page(name)
|
||||
output = page.formatted_data
|
||||
assert_equal %{<p>a <img src=\"#{scheme}://example.com/bilbo.JPG\" /> b</p>}, output
|
||||
end
|
||||
end
|
||||
|
||||
test "image with absolute path" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("alpha.jpg", "hi")
|
||||
index.commit("Add alpha.jpg")
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
|
||||
end
|
||||
|
||||
test "image with relative path on root" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("alpha.jpg", "hi")
|
||||
index.add("Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
assert_equal %Q{<p>a <img src=\"/wiki/alpha.jpg\" /><a href=\"/wiki/alpha.jpg\">a</a> b</p>}, page.formatted_data
|
||||
end
|
||||
|
||||
test "image with relative path" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("greek/alpha.jpg", "hi")
|
||||
index.add("greek/Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
output = page.formatted_data
|
||||
assert_equal %{<p>a <img src=\"/wiki/greek/alpha.jpg\" /><a href=\"/wiki/greek/alpha.jpg\">a</a> b</p>}, output
|
||||
end
|
||||
|
||||
test "image with absolute path on a preview" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("alpha.jpg", "hi")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown)
|
||||
assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /> b</p>}, page.formatted_data
|
||||
end
|
||||
|
||||
test "image with relative path on a preview" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("alpha.jpg", "hi")
|
||||
index.add("greek/alpha.jpg", "hi")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown)
|
||||
assert_equal %{<p>a <img src=\"/wiki/alpha.jpg\" /><img src=\"/wiki/greek/alpha.jpg\" /> b</p>}, page.formatted_data
|
||||
end
|
||||
|
||||
test "image with alt" do
|
||||
content = "a [[alpha.jpg|alt=Alpha Dog]] b"
|
||||
output = %{<p>a<imgsrc=\"/greek/alpha.jpg\"alt=\"AlphaDog\"/>b</p>}
|
||||
relative_image(content, output)
|
||||
end
|
||||
|
||||
test "image with em or px dimension" do
|
||||
%w{em px}.each do |unit|
|
||||
%w{width height}.each do |dim|
|
||||
content = "a [[alpha.jpg|#{dim}=100#{unit}]] b"
|
||||
output = "<p>a<imgsrc=\"/greek/alpha.jpg\"#{dim}=\"100#{unit}\"/>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "image with bogus dimension" do
|
||||
%w{width height}.each do |dim|
|
||||
content = "a [[alpha.jpg|#{dim}=100]] b"
|
||||
output = "<p>a<imgsrc=\"/greek/alpha.jpg\"/>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
end
|
||||
|
||||
test "image with vertical align" do
|
||||
%w{top texttop middle absmiddle bottom absbottom baseline}.each do |align|
|
||||
content = "a [[alpha.jpg|align=#{align}]] b"
|
||||
output = %Q{<p>a<imgsrc=\"/greek/alpha.jpg\"align=\"#{align}\"/>b</p>}
|
||||
relative_image(content, output)
|
||||
end
|
||||
end
|
||||
|
||||
test "image with horizontal align" do
|
||||
%w{left center right}.each do |align|
|
||||
content = "a [[alpha.jpg|align=#{align}]] b"
|
||||
output = "<p>a<spanclass=\"align-#{align}\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
end
|
||||
|
||||
test "image with float" do
|
||||
content = "a\n\n[[alpha.jpg|float]]\n\nb"
|
||||
output = "<p>a</p><p><spanclass=\"float-left\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span></p><p>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
|
||||
test "image with float and align" do
|
||||
%w{left right}.each do |align|
|
||||
content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb"
|
||||
output = "<p>a</p><p><spanclass=\"float-#{align}\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span></p><p>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
end
|
||||
|
||||
test "image with frame" do
|
||||
content = "a\n\n[[alpha.jpg|frame]]\n\nb"
|
||||
output = "<p>a</p><p><spanclass=\"frame\"><span><imgsrc=\"/greek/alpha.jpg\"/></span></span></p><p>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
|
||||
test "absolute image with frame" do
|
||||
content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb"
|
||||
output = "<p>a</p><p><spanclass=\"frame\"><span><imgsrc=\"http://example.com/bilbo.jpg\"/></span></span></p><p>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
|
||||
test "image with frame and alt" do
|
||||
content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb"
|
||||
output = "<p>a</p><p><spanclass=\"frame\"><span><imgsrc=\"/greek/alpha.jpg\"alt=\"Alpha\"/><span>Alpha</span></span></span></p><p>b</p>"
|
||||
relative_image(content, output)
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# File links
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "file link with absolute path" do
|
||||
index = @wiki.repo.index
|
||||
index.add("alpha.jpg", "hi")
|
||||
index.commit("Add alpha.jpg")
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[Alpha|/alpha.jpg]] b", commit_details)
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
output = Gollum::Markup.new(page).render
|
||||
assert_equal %{<p>a <a href="/alpha.jpg">Alpha</a> b</p>}, output
|
||||
end
|
||||
|
||||
test "file link with relative path" do
|
||||
index = @wiki.repo.index
|
||||
index.add("greek/alpha.jpg", "hi")
|
||||
index.add("greek/Bilbo-Baggins.md", "a [[Alpha|alpha.jpg]] b")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
output = Gollum::Markup.new(page).render
|
||||
assert_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>}, output
|
||||
end
|
||||
|
||||
test "file link with external path" do
|
||||
index = @wiki.repo.index
|
||||
index.add("greek/Bilbo-Baggins.md", "a [[Alpha|http://example.com/alpha.jpg]] b")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
assert_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Code
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "regular code blocks" do
|
||||
content = "a\n\n```ruby\nx = 1\n```\n\nb"
|
||||
output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>\n\n<p>b</p>}
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_equal output, rendered
|
||||
end
|
||||
|
||||
test "code blocks with carriage returns" do
|
||||
content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
|
||||
output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</pre></div>\n\n<p>b</p>}
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_equal output, rendered
|
||||
end
|
||||
|
||||
test "code blocks with two-space indent" do
|
||||
content = "a\n\n```ruby\n x = 1\n\n y = 2\n```\n\nb"
|
||||
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
|
||||
"x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
|
||||
"</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
|
||||
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "code blocks with one-tab indent" do
|
||||
content = "a\n\n```ruby\n\tx = 1\n\n\ty = 2\n```\n\nb"
|
||||
output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
|
||||
"x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
|
||||
"</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
|
||||
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "code blocks with multibyte caracters indent" do
|
||||
content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb"
|
||||
output = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'</span>\n</pre></div>\n\n<p>b</p>}
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render(false, 'utf-8')
|
||||
assert_equal output, rendered
|
||||
end
|
||||
|
||||
test "code blocks with ascii characters" do
|
||||
content = "a\n\n```\n├─foo\n```\n\nb"
|
||||
output = %(<p>a</p><divclass=\"highlight\"><pre><spanclass=\"err\">├─</span><spanclass=\"n\">foo</span></pre></div><p>b</p>)
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "code with wiki links" do
|
||||
content = <<-END
|
||||
booya
|
||||
|
||||
``` python
|
||||
np.array([[2,2],[1,3]],np.float)
|
||||
```
|
||||
END
|
||||
|
||||
# rendered with Gollum::Markup
|
||||
page, rendered = render_page(content)
|
||||
assert_markup_highlights_code Gollum::Markup, rendered
|
||||
end
|
||||
|
||||
test "code with trailing whitespace" do
|
||||
content = <<-END
|
||||
shoop da woop
|
||||
|
||||
``` python
|
||||
np.array([[2,2],[1,3]],np.float)
|
||||
```
|
||||
END
|
||||
|
||||
# rendered with Gollum::Markup
|
||||
page, rendered = render_page(content)
|
||||
assert_markup_highlights_code Gollum::Markup, rendered
|
||||
end
|
||||
|
||||
def assert_markup_highlights_code(markup_class, rendered)
|
||||
assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
|
||||
assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
|
||||
assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
|
||||
end
|
||||
|
||||
test "embed code page absolute link" do
|
||||
@wiki.write_page("base", :markdown, "a\n!base\b", commit_details)
|
||||
@wiki.write_page("a", :markdown, "a\n```html:/base```\b", commit_details)
|
||||
|
||||
page = @wiki.page("a")
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\nFile not found: /base</p>}, output
|
||||
end
|
||||
|
||||
test "embed code page relative link" do
|
||||
@wiki.write_page("base", :markdown, "a\n!rel\b", commit_details)
|
||||
@wiki.write_page("a", :markdown, "a\n```html:base```\b", commit_details)
|
||||
|
||||
page = @wiki.page("a")
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\nFile not found: base</p>}, output
|
||||
end
|
||||
|
||||
test "code block in unsupported language" do
|
||||
@wiki.write_page("a", :markdown, "a\n```nonexistent\ncode\n```\nb", commit_details)
|
||||
|
||||
page = @wiki.page("a")
|
||||
output = page.formatted_data
|
||||
assert_equal %Q{<p>a\ncode\nb</p>}, output
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Web Sequence Diagrams
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "sequence diagram blocks" do
|
||||
content = "a\n\n{{{{{{default\nalice->bob: Test\n}}}}}}\n\nb"
|
||||
output = /.*<img src="http:\/\/www\.websequencediagrams\.com\/\?img=\w{9}" \/>.*/
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add sequence diagram")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_not_nil rendered.match(output)
|
||||
end
|
||||
|
||||
if $METADATA #########################################################################
|
||||
#
|
||||
# Metadata Blocks
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "metadata blocks" do
|
||||
content = "a\n\n<!-- ---\ntags: [foo, bar]\n-->\n\nb"
|
||||
output = "<p>a</p>\n\n<p>b</p>"
|
||||
result = {'tags'=>['foo','bar']}
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add metadata")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_equal output, rendered
|
||||
assert_equal result, page.metadata
|
||||
end
|
||||
|
||||
test "metadata blocks with newline" do
|
||||
content = "a\n\n<!--\n---\ntags: [foo, bar]\n-->\n\nb"
|
||||
output = "<p>a</p>\n\n<p>b</p>"
|
||||
result = {'tags'=>['foo','bar']}
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add metadata")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_equal output, rendered
|
||||
assert_equal result, page.metadata
|
||||
end
|
||||
|
||||
test "metadata sanitation" do
|
||||
content = "a\n\n<!-- ---\nfoo: <script>alert('');</script>\n-->\n\nb"
|
||||
output = "<p>a</p>\n\n<p>b</p>"
|
||||
result = {'foo'=>nil}
|
||||
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.md", content)
|
||||
index.commit("Add metadata")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_equal output, rendered
|
||||
assert_equal result, page.metadata
|
||||
end
|
||||
end # if $METADATA
|
||||
#########################################################################
|
||||
#
|
||||
# Various
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
test "strips javscript protocol urls" do
|
||||
content = "[Hack me](javascript:hacked=true)"
|
||||
output = "<p><a>Hackme</a></p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "allows apt uri schemes" do
|
||||
content = "[Hack me](apt:gettext)"
|
||||
output = "<p><a href=\"apt:gettext\">Hackme</a></p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "removes style blocks completely" do
|
||||
content = "<style>body { color: red }</style>foobar"
|
||||
output = "<p>foobar</p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "removes script blocks completely" do
|
||||
content = "<script>alert('hax');</script>foobar"
|
||||
output = "<p>foobar</p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "escaped wiki link" do
|
||||
content = "a '[[Foo]], b"
|
||||
output = "<p>a [[Foo]], b</p>"
|
||||
compare(content, output)
|
||||
end
|
||||
|
||||
test "quoted wiki link" do
|
||||
content = "a '[[Foo]]', b"
|
||||
output = "<p>a '<a class=\"internal absent\" href=\"/Foo\">Foo</a>', b</p>"
|
||||
compare(content, output, 'md', [
|
||||
/class="internal absent"/,
|
||||
/href="\/Foo"/,
|
||||
/\>Foo\</])
|
||||
end
|
||||
|
||||
test "org mode style double links" do
|
||||
content = "a [[http://google.com][Google]] b"
|
||||
output = "<p>a <a href=\"http://google.com\">Google</a> b</p>"
|
||||
compare(content, output, 'org')
|
||||
end
|
||||
|
||||
test "org mode style double file links" do
|
||||
content = "a [[file:f.org][Google]] b"
|
||||
output = "<p>a <a class=\"internal absent\" href=\"/f\">Google</a> b</p>"
|
||||
compare(content, output, 'org')
|
||||
end
|
||||
|
||||
test "short double links" do
|
||||
content = "a [[b]] c"
|
||||
output = %(<p>a <a class="internal absent" href="/b">b</a> c</p>)
|
||||
compare(content, output, 'org')
|
||||
end
|
||||
|
||||
test "double linked pipe" do
|
||||
content = "a [[|]] b"
|
||||
output = %(<p>a <a class="internal absent" href="/"></a> b</p>)
|
||||
compare(content, output, 'org')
|
||||
end
|
||||
|
||||
test "id with prefix ok" do
|
||||
content = "h2(example#wiki-foo). xxxx"
|
||||
output = %(<h2 class="example" id="wiki-foo">xxxx<a class=\"anchor\" id=\"xxxx\" href=\"#xxxx\"></a></h2>)
|
||||
compare(content, output, :textile)
|
||||
end
|
||||
|
||||
test "id prefix added" do
|
||||
content = "h2(#foo). xxxx[1]\n\nfn1.footnote"
|
||||
output = "<h2 id=\"wiki-foo\">xxxx" +
|
||||
"<sup class=\"footnote\" id=\"wiki-fnr1\"><a href=\"#wiki-fn1\">1</a></sup>" +
|
||||
"<a class=\"anchor\" id=\"xxxx1\" href=\"#xxxx1\"></a></h2>" +
|
||||
"\n<p class=\"footnote\" id=\"wiki-fn1\"><a href=\"#wiki-fnr1\"><sup>1</sup></a> footnote</p>"
|
||||
compare(content, output, :textile)
|
||||
end
|
||||
|
||||
test "name prefix added" do
|
||||
content = "abc\n\n__TOC__\n\n==Header==\n\nblah"
|
||||
compare content, '', :mediawiki, [
|
||||
/id="wiki-toc"/,
|
||||
/href="#wiki-Header"/,
|
||||
/id="wiki-Header"/,
|
||||
/name="wiki-Header"/
|
||||
]
|
||||
end
|
||||
|
||||
if ENV['ASCIIDOC']
|
||||
#########################################################################
|
||||
# Asciidoc
|
||||
#########################################################################
|
||||
|
||||
test "asciidoc header" do
|
||||
compare("= Book Title\n\n== Heading", '<div class="sect1"><h2 id="wiki-_heading">Heading<a class="anchor" id="Heading" href="#Heading"></a></h2><div class="sectionbody"></div></div>', 'asciidoc')
|
||||
end
|
||||
|
||||
test "internal links with asciidoc" do
|
||||
compare("= Book Title\n\n[[anid]]\n== Heading", '<div class="sect1"><h2 id="wiki-anid">Heading<a class="anchor" id="Heading" href="#Heading"></a></h2><div class="sectionbody"></div></div>', 'asciidoc')
|
||||
end
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
#
|
||||
# Helpers
|
||||
#
|
||||
#########################################################################
|
||||
|
||||
def render_page(content, ext = "md")
|
||||
index = @wiki.repo.index
|
||||
index.add("Bilbo-Baggins.#{ext}", content)
|
||||
index.commit("Add baggins")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
[page, Gollum::Markup.new(page).render]
|
||||
end
|
||||
|
||||
def compare(content, output, ext = "md", regexes = [])
|
||||
page, rendered = render_page(content, ext)
|
||||
|
||||
if regexes.empty?
|
||||
assert_equal normal(output), normal(rendered)
|
||||
else
|
||||
output = page.formatted_data
|
||||
regexes.each { |r| assert_match r, output }
|
||||
end
|
||||
end
|
||||
|
||||
def relative_image(content, output)
|
||||
index = @wiki.repo.index
|
||||
index.add("greek/alpha.jpg", "hi")
|
||||
index.add("greek/Bilbo-Baggins.md", content)
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
rendered = Gollum::Markup.new(page).render
|
||||
assert_equal normal(output), normal(rendered)
|
||||
end
|
||||
end
|
||||
@@ -1,273 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
||||
|
||||
context "Page" do
|
||||
setup do
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
|
||||
end
|
||||
|
||||
test "new page" do
|
||||
page = Gollum::Page.new(@wiki)
|
||||
assert_nil page.raw_data
|
||||
assert_nil page.formatted_data
|
||||
end
|
||||
|
||||
test "get existing page" do
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||
assert page.formatted_data =~ %r{<h1>Bilbo Baggins<a class="anchor" id="Bilbo-Baggins" href="#Bilbo-Baggins"></a></h1>\n\n<p>Bilbo Baggins}
|
||||
assert_equal 'Bilbo-Baggins.md', page.path
|
||||
assert_equal :markdown, page.format
|
||||
assert_equal @wiki.repo.commits.first.id, page.version.id
|
||||
end
|
||||
|
||||
test "get existing page case insensitive" do
|
||||
assert_equal @wiki.page('Bilbo Baggins').path, @wiki.page('bilbo baggins').path
|
||||
end
|
||||
|
||||
test "get existing page with hyphen" do
|
||||
assert_equal @wiki.page('Bilbo Baggins').path, @wiki.page('Bilbo-Baggins').path
|
||||
end
|
||||
|
||||
test "get existing page with underscore" do
|
||||
assert_nil @wiki.page('Bilbo_Baggins')
|
||||
end
|
||||
|
||||
test "get existing page where filename contains whitespace, with hypen" do
|
||||
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path
|
||||
end
|
||||
|
||||
test "get existing page where filename contains whitespace, with underscore" do
|
||||
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise_Gamgee').path
|
||||
end
|
||||
|
||||
test "get existing page where filename contains whitespace, with whitespace" do
|
||||
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise Gamgee').path
|
||||
end
|
||||
|
||||
test "get nested page" do
|
||||
page = @wiki.page('Eye Of Sauron')
|
||||
assert_equal 'Mordor/Eye-Of-Sauron.md', page.path
|
||||
end
|
||||
|
||||
test "url_path" do
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
assert_equal 'Bilbo-Baggins', page.url_path
|
||||
end
|
||||
|
||||
test "nested url_path" do
|
||||
page = @wiki.page('Eye Of Sauron')
|
||||
assert_equal 'Mordor/Eye-Of-Sauron', page.url_path
|
||||
end
|
||||
|
||||
test "page versions" do
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
assert_equal ["f25eccd98e9b667f9e22946f3e2f945378b8a72d", "5bc1aaec6149e854078f1d0f8b71933bbc6c2e43"],
|
||||
page.versions.map { |v| v.id }
|
||||
end
|
||||
|
||||
test "page versions across renames" do
|
||||
page = @wiki.page 'My-Precious'
|
||||
assert_equal ['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b', '94523d7ae48aeba575099dd12926420d8fd0425d'],
|
||||
page.versions(:follow => true).map { |v| v.id }
|
||||
end
|
||||
|
||||
test "page versions without renames" do
|
||||
page = @wiki.page 'My-Precious'
|
||||
assert_equal ['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'],
|
||||
page.versions(:follow => false).map { |v| v.id }
|
||||
end
|
||||
|
||||
test "specific page version" do
|
||||
page = @wiki.page('Bilbo Baggins', 'fbabba862dfa7ac35b39042dd4ad780c9f67b8cb')
|
||||
assert_equal 'fbabba862dfa7ac35b39042dd4ad780c9f67b8cb', page.version.id
|
||||
end
|
||||
|
||||
test "no page match" do
|
||||
assert_nil @wiki.page('I do not exist')
|
||||
end
|
||||
|
||||
test "no version match" do
|
||||
assert_nil @wiki.page('Bilbo Baggins', 'I do not exist')
|
||||
end
|
||||
|
||||
test "no ext match" do
|
||||
assert_nil @wiki.page('Data')
|
||||
end
|
||||
|
||||
test "cname" do
|
||||
assert_equal "Foo", Gollum::Page.cname("Foo")
|
||||
assert_equal "Foo-Bar", Gollum::Page.cname("Foo Bar")
|
||||
# / is now a directory delimiter so it must be preserved
|
||||
assert_equal "Foo-/-Bar", Gollum::Page.cname("Foo / Bar")
|
||||
assert_equal "José", Gollum::Page.cname("José")
|
||||
assert_equal "モルドール", Gollum::Page.cname("モルドール")
|
||||
end
|
||||
|
||||
test "title from filename with normal contents" do
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
assert_equal 'Bilbo Baggins', page.title
|
||||
end
|
||||
|
||||
test "title from filename with html contents" do
|
||||
page = @wiki.page('My <b>Precious', '0ed8cbe0a25235bd867e65193c7d837c66b328ef')
|
||||
assert_equal 'My Precious', page.title
|
||||
end
|
||||
|
||||
test "title from filename with normal contents" do
|
||||
page = @wiki.page('Home')
|
||||
assert_equal "Home", page.title
|
||||
end
|
||||
|
||||
test "title from filename with html contents" do
|
||||
page = @wiki.page('Eye Of Sauron')
|
||||
assert_equal "Eye Of Sauron", page.title
|
||||
end
|
||||
|
||||
test "top level header" do
|
||||
header = @wiki.page('Home').header
|
||||
assert_equal "Hobbits\n", header.raw_data
|
||||
assert_equal "_Header.md", header.path
|
||||
end
|
||||
|
||||
test "nested header" do
|
||||
header = @wiki.page('Eye Of Sauron').header
|
||||
assert_equal "Sauron\n", header.raw_data
|
||||
assert_equal "Mordor/_Header.md", header.path
|
||||
end
|
||||
|
||||
test "header itself" do
|
||||
header = @wiki.page("_Header")
|
||||
assert_nil header.header
|
||||
assert_nil header.footer
|
||||
assert_nil header.sidebar
|
||||
end
|
||||
|
||||
test "top level footer" do
|
||||
footer = @wiki.page('Home').footer
|
||||
assert_equal 'Lord of the Rings wiki', footer.raw_data
|
||||
assert_equal '_Footer.md', footer.path
|
||||
end
|
||||
|
||||
test "nested footer" do
|
||||
footer = @wiki.page('Eye Of Sauron').footer
|
||||
assert_equal "Ones does not simply **walk** into Mordor!\n", footer.raw_data
|
||||
assert_equal "Mordor/_Footer.md", footer.path
|
||||
end
|
||||
|
||||
test "footer itself" do
|
||||
footer = @wiki.page("_Footer")
|
||||
assert_nil footer.header
|
||||
assert_nil footer.footer
|
||||
assert_nil footer.sidebar
|
||||
end
|
||||
|
||||
test "top level sidebar" do
|
||||
sidebar = @wiki.page('Home').sidebar
|
||||
assert_equal 'Lord of the Rings wiki', sidebar.raw_data
|
||||
assert_equal '_Sidebar.md', sidebar.path
|
||||
end
|
||||
|
||||
test "nested sidebar" do
|
||||
sidebar = @wiki.page('Eye Of Sauron').sidebar
|
||||
assert_equal "Ones does not simply **walk** into Mordor!\n", sidebar.raw_data
|
||||
assert_equal "Mordor/_Sidebar.md", sidebar.path
|
||||
end
|
||||
|
||||
test "sidebar itself" do
|
||||
sidebar = @wiki.page("_Sidebar")
|
||||
assert_nil sidebar.header
|
||||
assert_nil sidebar.footer
|
||||
assert_nil sidebar.sidebar
|
||||
end
|
||||
|
||||
test "cannot convert non string to human readable page title" do
|
||||
assert_equal '', Gollum::Page.cname(nil)
|
||||
assert_equal '', Gollum::Page.cname(3)
|
||||
end
|
||||
|
||||
test "normalize_dir" do
|
||||
assert_equal "", Gollum::BlobEntry.normalize_dir("")
|
||||
assert_equal "", Gollum::BlobEntry.normalize_dir(".")
|
||||
assert_equal "", Gollum::BlobEntry.normalize_dir("/")
|
||||
assert_equal "", Gollum::BlobEntry.normalize_dir("c:/")
|
||||
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("foo")
|
||||
assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo")
|
||||
end
|
||||
end
|
||||
|
||||
context "with a checkout" do
|
||||
setup do
|
||||
@path = cloned_testpath("examples/lotr.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "get existing page with symbolic link" do
|
||||
page = @wiki.page("Hobbit")
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||
assert page.formatted_data =~ %r{<h1>Bilbo Baggins<a class="anchor" id="Bilbo-Baggins" href="#Bilbo-Baggins"></a></h1>\n\n<p>Bilbo Baggins}
|
||||
assert_equal 'Hobbit.md', page.path
|
||||
assert_equal :markdown, page.format
|
||||
end
|
||||
end
|
||||
|
||||
context "within a sub-directory" do
|
||||
setup do
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' })
|
||||
end
|
||||
|
||||
test "get existing page" do
|
||||
page = @wiki.page('Elrond')
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert page.raw_data =~ /^# Elrond\n\nElrond/
|
||||
assert_equal 'Rivendell/Elrond.md', page.path
|
||||
assert_equal :markdown, page.format
|
||||
assert_equal @wiki.repo.commits.first.id, page.version.id
|
||||
end
|
||||
|
||||
test "should not get page from parent dir" do
|
||||
page = @wiki.page('Bilbo Baggins')
|
||||
assert_equal nil, page
|
||||
end
|
||||
|
||||
test "should inherit header/footer/sidebar pages from parent directories" do
|
||||
page = @wiki.page('Elrond')
|
||||
|
||||
assert_equal Gollum::Page, page.sidebar.class
|
||||
assert_equal Gollum::Page, page.header.class
|
||||
assert_equal Gollum::Page, page.footer.class
|
||||
|
||||
assert page.sidebar.raw_data =~ /^Lord of the Rings/
|
||||
assert page.header.raw_data =~ /^Hobbits/
|
||||
assert page.footer.raw_data =~ /^Lord of the Rings/
|
||||
end
|
||||
|
||||
if $METADATA
|
||||
test "get metadata on page" do
|
||||
page = @wiki.page('Elrond')
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert_equal 'elf', page.metadata['race']
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with custom markup engines" do
|
||||
setup do
|
||||
Gollum::Markup.register(:redacted, "Redacted", :regexp => /rd/) { |content| content.gsub /\S/, '-' }
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
|
||||
end
|
||||
|
||||
test "should use the specified engine" do
|
||||
page = @wiki.page('Riddles')
|
||||
assert_equal :redacted, page.format
|
||||
assert page.raw_data.include? 'Time'
|
||||
assert page.raw_data =~ /^[\s\-]*$/
|
||||
end
|
||||
end
|
||||
@@ -1,57 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
||||
|
||||
context "Page Reverting" do
|
||||
setup do
|
||||
@path = cloned_testpath("examples/revert.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
=begin
|
||||
# Grit is broken and this test fails often. See #363.
|
||||
test "reverts single commit" do
|
||||
page1 = @wiki.page("B")
|
||||
sha = @wiki.revert_commit('7c45b5f16ff3bae2a0063191ef832701214d4df5')
|
||||
page2 = @wiki.page("B")
|
||||
assert_equal sha, page2.version.sha
|
||||
assert_equal "INITIAL", body=page2.raw_data.strip
|
||||
assert_equal body, File.read(File.join(@path, "B.md")).strip
|
||||
end
|
||||
|
||||
test "reverts single commit for a page" do
|
||||
page1 = nil
|
||||
while (page1 == nil)
|
||||
page1 = @wiki.page('B')
|
||||
end
|
||||
|
||||
sha = @wiki.revert_page(page1, '7c45b5f16ff3bae2a0063191ef832701214d4df5')
|
||||
|
||||
page2 = nil
|
||||
while (page2 == nil)
|
||||
page2 = @wiki.page('B')
|
||||
end
|
||||
|
||||
assert_equal sha, page2.version.sha
|
||||
assert_equal "INITIAL", body=page2.raw_data.strip
|
||||
assert_equal body, File.read(File.join(@path, "B.md")).strip
|
||||
end
|
||||
|
||||
test "reverts multiple commits for a page" do
|
||||
page1 = @wiki.page('A')
|
||||
sha = @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2^', 'b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f')
|
||||
page2 = @wiki.page('A')
|
||||
assert_equal sha, page2.version.sha
|
||||
assert_equal "INITIAL", body=page2.raw_data.strip
|
||||
assert_equal body, File.read(File.join(@path, "A.md")).strip
|
||||
end
|
||||
=end
|
||||
|
||||
test "cannot revert conflicting commit" do
|
||||
page1 = @wiki.page('A')
|
||||
assert_equal false, @wiki.revert_page(page1, '302a5491a9a5ba12c7652ac831a44961afa312d2')
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/frontend/views/page', __FILE__
|
||||
require File.expand_path '../../lib/gollum/views/page', __FILE__
|
||||
|
||||
context "Precious::Views::Page" do
|
||||
setup do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/frontend/views/pages', __FILE__
|
||||
require File.expand_path '../../lib/gollum/views/pages', __FILE__
|
||||
|
||||
FakeResult = Struct.new(:path) do
|
||||
def name
|
||||
|
||||
@@ -20,73 +20,6 @@ context "Unicode Support" do
|
||||
assert_equal '%ED%95%9C%EA%B8%80', encodeURIComponent(c)
|
||||
assert_equal '%ED%95%9C%EA%B8%80', CGI::escape(c)
|
||||
end
|
||||
|
||||
test "create and read non-latin page with anchor" do
|
||||
@wiki.write_page("test", :markdown, "# 한글")
|
||||
|
||||
page = @wiki.page("test")
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert_equal "# 한글", utf8(page.raw_data)
|
||||
|
||||
# markup.rb
|
||||
doc = Nokogiri::HTML page.formatted_data
|
||||
h1s = doc / :h1
|
||||
h1 = h1s.first
|
||||
anchors = h1 / :a
|
||||
assert_equal 1, h1s.size
|
||||
assert_equal 1, anchors.size
|
||||
assert_equal '#한글', anchors[0]['href']
|
||||
assert_equal '한글', anchors[0]['id']
|
||||
assert_equal 'anchor', anchors[0]['class']
|
||||
assert_equal '', anchors[0].text
|
||||
end
|
||||
|
||||
def check_h1 text, page
|
||||
@wiki.write_page(page, :markdown, "# " + text)
|
||||
|
||||
page = @wiki.page(page)
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert_equal '# ' + text, utf8(page.raw_data)
|
||||
|
||||
output = page.formatted_data
|
||||
|
||||
# UTF-8 headers should not be encoded.
|
||||
assert_match /<h1>#{text}<a class="anchor" id="#{text}" href="##{text}"><\/a><\/h1>/, output
|
||||
end
|
||||
|
||||
test "create and read non-latin page with anchor" do
|
||||
# href="#한글"
|
||||
# href="#%ED%95%9C%EA%B8%80"
|
||||
check_h1 '한글', '1'
|
||||
# href="#Synhtèse"
|
||||
# href="#Synht%C3%A8se"
|
||||
check_h1 'Synhtèse', '2'
|
||||
end
|
||||
|
||||
test "create and read non-latin page with anchor 2" do
|
||||
@wiki.write_page("test", :markdown, "# \"La\" faune d'Édiacara")
|
||||
|
||||
page = @wiki.page("test")
|
||||
assert_equal Gollum::Page, page.class
|
||||
assert_equal "# \"La\" faune d'Édiacara", utf8(page.raw_data)
|
||||
|
||||
# markup.rb test: ', ", É
|
||||
doc = Nokogiri::HTML page.formatted_data
|
||||
h1s = doc / :h1
|
||||
h1 = h1s.first
|
||||
anchors = h1 / :a
|
||||
assert_equal 1, h1s.size
|
||||
assert_equal 1, anchors.size
|
||||
assert_equal %q(#%22La%22-faune-d'Édiacara), anchors[0]['href']
|
||||
assert_equal %q(%22La%22-faune-d'Édiacara), anchors[0]['id']
|
||||
assert_equal 'anchor', anchors[0]['class']
|
||||
assert_equal '', anchors[0].text
|
||||
end
|
||||
|
||||
test "unicode with existing format rules" do
|
||||
@wiki.write_page("test", :markdown, "# 한글")
|
||||
assert_equal @wiki.page("test").path, @wiki.page("test").path
|
||||
end
|
||||
end
|
||||
|
||||
context "Frontend Unicode support" do
|
||||
|
||||
@@ -1,667 +0,0 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
|
||||
|
||||
context "Wiki" do
|
||||
setup do
|
||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
|
||||
Gollum::Wiki.markup_classes = nil
|
||||
end
|
||||
|
||||
test "#markup_class gets default markup" do
|
||||
assert_equal Gollum::Markup, Gollum::Wiki.markup_class
|
||||
end
|
||||
|
||||
test "#default_markup_class= doesn't clobber alternate markups" do
|
||||
custom = Class.new(Gollum::Markup)
|
||||
custom_md = Class.new(Gollum::Markup)
|
||||
|
||||
Gollum::Wiki.markup_classes = Hash.new Gollum::Markup
|
||||
Gollum::Wiki.markup_classes[:markdown] = custom_md
|
||||
Gollum::Wiki.default_markup_class = custom
|
||||
|
||||
assert_equal custom, Gollum::Wiki.default_markup_class
|
||||
assert_equal custom, Gollum::Wiki.markup_classes[:orgmode]
|
||||
assert_equal custom_md, Gollum::Wiki.markup_classes[:markdown]
|
||||
end
|
||||
|
||||
test "repo path" do
|
||||
assert_equal testpath("examples/lotr.git"), @wiki.path
|
||||
end
|
||||
|
||||
test "git repo" do
|
||||
assert_equal Grit::Repo, @wiki.repo.class
|
||||
assert @wiki.exist?
|
||||
end
|
||||
|
||||
test "shows paginated log with no page" do
|
||||
Gollum::Wiki.per_page = 3
|
||||
commits = @wiki.repo.commits[0..2].map { |x| x.id }
|
||||
assert_equal commits, @wiki.log.map { |c| c.id }
|
||||
end
|
||||
|
||||
test "shows paginated log with 1st page" do
|
||||
Gollum::Wiki.per_page = 3
|
||||
commits = @wiki.repo.commits[0..2].map { |x| x.id }
|
||||
assert_equal commits, @wiki.log(:page => 1).map { |c| c.id }
|
||||
end
|
||||
|
||||
test "shows paginated log with next page" do
|
||||
Gollum::Wiki.per_page = 3
|
||||
commits = @wiki.repo.commits[3..5].map { |x| x.id }
|
||||
assert_equal commits, @wiki.log(:page => 2).map { |c| c.id }
|
||||
end
|
||||
|
||||
test "list pages" do
|
||||
pages = @wiki.pages
|
||||
assert_equal \
|
||||
['Bilbo-Baggins.md', 'Boromir.md', 'Elrond.md', 'Eye-Of-Sauron.md', 'Hobbit.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'],
|
||||
pages.map { |p| p.filename }.sort
|
||||
end
|
||||
|
||||
test "list files" do
|
||||
files = @wiki.files
|
||||
assert_equal \
|
||||
['Data-Two.csv', 'Data.csv', 'Riddles.rd', 'eye.jpg', 'todo.txt'],
|
||||
files.map { |p| p.filename }.sort
|
||||
end
|
||||
|
||||
test "counts pages" do
|
||||
assert_equal 8, @wiki.size
|
||||
end
|
||||
|
||||
test "text_data" do
|
||||
wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
|
||||
if String.instance_methods.include?(:encoding)
|
||||
utf8 = wiki.page("strider").text_data
|
||||
assert_equal Encoding::UTF_8, utf8.encoding
|
||||
sjis = wiki.page("sjis").text_data(Encoding::SHIFT_JIS)
|
||||
assert_equal Encoding::SHIFT_JIS, sjis.encoding
|
||||
else
|
||||
page = wiki.page("strider")
|
||||
assert_equal page.raw_data, page.text_data
|
||||
end
|
||||
end
|
||||
|
||||
test "gets reverse diff" do
|
||||
diff = @wiki.full_reverse_diff('a8ad3c09dd842a3517085bfadd37718856dee813')
|
||||
assert_match "b/Mordor/_Sidebar.md", diff
|
||||
assert_match "b/_Sidebar.md", diff
|
||||
end
|
||||
|
||||
test "gets reverse diff for a page" do
|
||||
diff = @wiki.full_reverse_diff_for('_Sidebar.md', 'a8ad3c09dd842a3517085bfadd37718856dee813')
|
||||
regex = /b\/Mordor\/\_Sidebar\.md/
|
||||
assert_match "b/_Sidebar.md", diff
|
||||
assert_no_match regex, diff
|
||||
end
|
||||
|
||||
test "gets scoped page from specified directory" do
|
||||
@path = cloned_testpath('examples/lotr.git')
|
||||
begin
|
||||
wiki = Gollum::Wiki.new(@path)
|
||||
index = wiki.repo.index
|
||||
index.read_tree 'master'
|
||||
index.add('Foobar/Elrond.md', 'Baz')
|
||||
index.commit 'Add Foobar/Elrond.', [wiki.repo.commits.last], Grit::Actor.new('Tom Preston-Werner', 'tom@github.com')
|
||||
|
||||
assert_equal 'Rivendell/Elrond.md', wiki.page('Elrond', nil, 'Rivendell').path
|
||||
# test paged as well.
|
||||
assert_equal 'Foobar/Elrond.md', wiki.paged('Elrond', 'Foobar').path
|
||||
ensure
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki page previewing" do
|
||||
setup do
|
||||
@path = testpath("examples/lotr.git")
|
||||
Gollum::Wiki.default_options = {:universal_toc => false}
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
test "preview_page" do
|
||||
page = @wiki.preview_page("Test", "# Bilbo", :markdown)
|
||||
assert_equal "# Bilbo", page.raw_data
|
||||
assert_equal %Q{<h1>Bilbo<a class=\"anchor\" id=\"Bilbo\" href=\"#Bilbo\"></a></h1>}, page.formatted_data
|
||||
assert_equal "Test.md", page.filename
|
||||
assert_equal "Test", page.name
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki TOC" do
|
||||
setup do
|
||||
@path = testpath("examples/lotr.git")
|
||||
options = {:universal_toc => true}
|
||||
@wiki = Gollum::Wiki.new(@path, options)
|
||||
end
|
||||
|
||||
test "toc_generation" do
|
||||
page = @wiki.preview_page("Test", "# Bilbo", :markdown)
|
||||
assert_equal "# Bilbo", page.raw_data
|
||||
assert_equal '<h1>Bilbo<a class="anchor" id="Bilbo" href="#Bilbo"></a></h1>', page.formatted_data.gsub(/\n/,"")
|
||||
assert_equal %{<div class="toc"><div class="toc-title">Table of Contents</div><ul><li><a href="#Bilbo">Bilbo</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
|
||||
end
|
||||
|
||||
# Ensure ' creates valid links in TOC
|
||||
# Incorrect: <a href=\"#a\" b=\"\">
|
||||
# Correct: <a href=\"#a'b\">
|
||||
test "' in link" do
|
||||
page = @wiki.preview_page("Test", "# a'b", :markdown)
|
||||
assert_equal "# a'b", page.raw_data
|
||||
assert_equal %q{<h1>a'b<a class="anchor" id="a'b" href="#a'b"></a></h1>}, page.formatted_data.gsub(/\n/,"")
|
||||
assert_equal %{<div class=\"toc\"><div class=\"toc-title\">Table of Contents</div><ul><li><a href=\"#a'b\">a'b</a></li></ul></div>}, page.toc_data.gsub(/\n */,"")
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki page writing" do
|
||||
setup do
|
||||
@path = testpath("examples/test.git")
|
||||
FileUtils.rm_rf(@path)
|
||||
Grit::Repo.init_bare(@path)
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
test "write_page" do
|
||||
cd = commit_details
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", cd)
|
||||
assert_equal 1, @wiki.repo.commits.size
|
||||
assert_equal cd[:message], @wiki.repo.commits.first.message
|
||||
assert_equal cd[:name], @wiki.repo.commits.first.author.name
|
||||
assert_equal cd[:email], @wiki.repo.commits.first.author.email
|
||||
assert @wiki.page("Gollum")
|
||||
|
||||
@wiki.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert @wiki.page("Bilbo")
|
||||
assert @wiki.page("Gollum")
|
||||
end
|
||||
|
||||
test "is not allowed to overwrite file" do
|
||||
@wiki.write_page("Abc-Def", :markdown, "# Gollum", commit_details)
|
||||
assert_raises Gollum::DuplicatePageError do
|
||||
@wiki.write_page("ABC DEF", :textile, "# Gollum", commit_details)
|
||||
end
|
||||
end
|
||||
|
||||
test "update_page" do
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
cd = commit_details
|
||||
@wiki.update_page(page, page.name, :markdown, "# Gollum2", cd)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
|
||||
assert_equal cd[:message], @wiki.repo.commits.first.message
|
||||
assert_equal cd[:name], @wiki.repo.commits.first.author.name
|
||||
assert_equal cd[:email], @wiki.repo.commits.first.author.email
|
||||
end
|
||||
|
||||
if $METADATA
|
||||
test "page title override with metadata" do
|
||||
@wiki.write_page("Gollum", :markdown, "<!-- --- title: Over -->", commit_details)
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
|
||||
assert_equal 'Over', page.url_path_title
|
||||
end
|
||||
end
|
||||
|
||||
test "update page with format change" do
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
|
||||
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal :textile, @wiki.page("Gollum").format
|
||||
assert_equal "h1. Gollum", @wiki.page("Gollum").raw_data
|
||||
end
|
||||
|
||||
test "update page with name change" do
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
|
||||
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit_details)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
|
||||
end
|
||||
|
||||
test "update page with name and format change" do
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
|
||||
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit_details)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal :textile, @wiki.page("Smeagol").format
|
||||
assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
|
||||
end
|
||||
|
||||
test "update nested page with format change" do
|
||||
index = @wiki.repo.index
|
||||
index.add("lotr/Gollum.md", "# Gollum")
|
||||
index.commit("Add nested page")
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
@wiki.update_page(page, page.name, :textile, "h1. Gollum", commit_details)
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
assert_equal "lotr/Gollum.textile", page.path
|
||||
assert_equal :textile, page.format
|
||||
assert_equal "h1. Gollum", page.raw_data
|
||||
end
|
||||
|
||||
test "delete root page" do
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.delete_page(page, commit_details)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_nil @wiki.page("Gollum")
|
||||
end
|
||||
|
||||
test "delete nested page" do
|
||||
index = @wiki.repo.index
|
||||
index.add("greek/Bilbo-Baggins.md", "hi")
|
||||
index.add("Gollum.md", "hi")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo-Baggins")
|
||||
assert page
|
||||
@wiki.delete_page(page, commit_details)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_nil @wiki.page("Bilbo-Baggins")
|
||||
|
||||
assert @wiki.page("Gollum")
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki page writing with whitespace (filename contains whitespace)" do
|
||||
setup do
|
||||
@path = cloned_testpath("examples/lotr.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
test "update_page" do
|
||||
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
|
||||
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
|
||||
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee2", commit_details)
|
||||
|
||||
assert_equal :textile, @wiki.page("Samwise Gamgee").format
|
||||
assert_equal "h1. Samwise Gamgee2", @wiki.page("Samwise Gamgee").raw_data
|
||||
assert_equal "Samwise-Gamgee.textile", @wiki.page("Samwise Gamgee").filename
|
||||
end
|
||||
|
||||
test "update page with format change, verify non-canonicalization of filename, where filename contains Whitespace" do
|
||||
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
|
||||
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
|
||||
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, page.name, :textile, "h1. Samwise Gamgee", commit_details)
|
||||
|
||||
assert_equal :textile, @wiki.page("Samwise Gamgee").format
|
||||
assert_equal "h1. Samwise Gamgee", @wiki.page("Samwise Gamgee").raw_data
|
||||
assert_equal "Samwise-Gamgee.textile", @wiki.page("Samwise Gamgee").filename
|
||||
end
|
||||
|
||||
test "update page with name change, verify canonicalization of filename, where filename contains Whitespace" do
|
||||
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
|
||||
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
|
||||
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
|
||||
|
||||
assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
|
||||
assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
|
||||
end
|
||||
|
||||
test "update page with name and format change, verify canonicalization of filename, where filename contains Whitespace" do
|
||||
assert_equal :mediawiki, @wiki.page("Samwise Gamgee").format
|
||||
assert_equal "Samwise Gamgee.mediawiki", @wiki.page("Samwise Gamgee").filename
|
||||
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, 'Sam Gamgee', :textile, "h1. Samwise Gamgee", commit_details)
|
||||
|
||||
assert_equal :textile, @wiki.page("Sam Gamgee").format
|
||||
assert_equal "h1. Samwise Gamgee", @wiki.page("Sam Gamgee").raw_data
|
||||
assert_equal "Sam-Gamgee.textile", @wiki.page("Sam Gamgee").filename
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki sync with working directory" do
|
||||
setup do
|
||||
@path = testpath('examples/wdtest')
|
||||
Grit::Repo.init(@path)
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
|
||||
test "write a page" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
assert_equal "Hi", File.read(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
test "write a page in subdirectory" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details, "Subdirectory")
|
||||
assert_equal "Hi", File.read(File.join(@path, "Subdirectory", "New-Page.md"))
|
||||
end
|
||||
|
||||
test "update a page with same name and format" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
page = @wiki.page("New Page")
|
||||
@wiki.update_page(page, page.name, page.format, "Bye", commit_details)
|
||||
assert_equal "Bye", File.read(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
test "update a page with different name and same format" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
page = @wiki.page("New Page")
|
||||
@wiki.update_page(page, "New Page 2", page.format, "Bye", commit_details)
|
||||
assert_equal "Bye", File.read(File.join(@path, "New-Page-2.md"))
|
||||
assert !File.exist?(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
test "update a page with same name and different format" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
page = @wiki.page("New Page")
|
||||
@wiki.update_page(page, page.name, :textile, "Bye", commit_details)
|
||||
assert_equal "Bye", File.read(File.join(@path, "New-Page.textile"))
|
||||
assert !File.exist?(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
test "update a page with different name and different format" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
page = @wiki.page("New Page")
|
||||
@wiki.update_page(page, "New Page 2", :textile, "Bye", commit_details)
|
||||
assert_equal "Bye", File.read(File.join(@path, "New-Page-2.textile"))
|
||||
assert !File.exist?(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
test "delete a page" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
page = @wiki.page("New Page")
|
||||
@wiki.delete_page(page, commit_details)
|
||||
assert !File.exist?(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_r(@path)
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki sync with working directory (filename contains whitespace)" do
|
||||
setup do
|
||||
@path = cloned_testpath("examples/lotr.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
end
|
||||
test "update a page with same name and format" do
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, page.name, page.format, "What we need is a few good taters.", commit_details)
|
||||
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise Gamgee.mediawiki"))
|
||||
end
|
||||
|
||||
test "update a page with different name and same format" do
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, "Sam Gamgee", page.format, "What we need is a few good taters.", commit_details)
|
||||
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.mediawiki"))
|
||||
assert !File.exist?(File.join(@path, "Samwise Gamgee"))
|
||||
end
|
||||
|
||||
test "update a page with same name and different format" do
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, page.name, :textile, "What we need is a few good taters.", commit_details)
|
||||
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Samwise-Gamgee.textile"))
|
||||
assert !File.exist?(File.join(@path, "Samwise-Gamgee.mediawiki"))
|
||||
end
|
||||
|
||||
test "update a page with different name and different format" do
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.update_page(page, "Sam Gamgee", :textile, "What we need is a few good taters.", commit_details)
|
||||
assert_equal "What we need is a few good taters.", File.read(File.join(@path, "Sam-Gamgee.textile"))
|
||||
assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
|
||||
end
|
||||
|
||||
test "delete a page" do
|
||||
page = @wiki.page("Samwise Gamgee")
|
||||
@wiki.delete_page(page, commit_details)
|
||||
assert !File.exist?(File.join(@path, "Samwise Gamgee.mediawiki"))
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_r(@path)
|
||||
end
|
||||
end
|
||||
|
||||
context "page_file_dir option" do
|
||||
setup do
|
||||
@path = cloned_testpath('examples/page_file_dir')
|
||||
@repo = Grit::Repo.init(@path)
|
||||
@page_file_dir = 'docs'
|
||||
@wiki = Gollum::Wiki.new(@path, :page_file_dir => @page_file_dir)
|
||||
end
|
||||
|
||||
test "write a page in sub directory" do
|
||||
@wiki.write_page("New Page", :markdown, "Hi", commit_details)
|
||||
assert_equal "Hi", File.read(File.join(@path, @page_file_dir, "New-Page.md"))
|
||||
assert !File.exist?(File.join(@path, "New-Page.md"))
|
||||
end
|
||||
|
||||
test "edit a page in a sub directory" do
|
||||
page = @wiki.page('foo')
|
||||
@wiki.update_page(page, page.name, page.format, 'new contents', commit_details)
|
||||
end
|
||||
|
||||
test "a file in page file dir should be found" do
|
||||
assert @wiki.page("foo")
|
||||
end
|
||||
|
||||
test "a file out of page file dir should not be found" do
|
||||
assert !@wiki.page("bar")
|
||||
end
|
||||
|
||||
test "search results should be restricted in page filer dir" do
|
||||
results = @wiki.search("foo")
|
||||
assert_equal 1, results.size
|
||||
assert_equal "docs/foo", results[0][:name]
|
||||
end
|
||||
|
||||
test "search results should make the content/filename search additive" do
|
||||
# This file contains the word 'foo' and is called 'foo', so it should
|
||||
# have a count of 2, not 1...
|
||||
results = @wiki.search("foo")
|
||||
assert_equal 2, results[0][:count]
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_r(@path)
|
||||
end
|
||||
end
|
||||
|
||||
context "Wiki page writing with different branch" do
|
||||
setup do
|
||||
@path = testpath("examples/test.git")
|
||||
FileUtils.rm_rf(@path)
|
||||
@repo = Grit::Repo.init_bare(@path)
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
|
||||
# We need an initial commit to create the master branch
|
||||
# before we can create new branches
|
||||
cd = commit_details
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", cd)
|
||||
|
||||
# Create our test branch and check it out
|
||||
@repo.update_ref("test", @repo.commits.first.id)
|
||||
@branch = Gollum::Wiki.new(@path, :ref => "test")
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "write_page" do
|
||||
cd = commit_details
|
||||
|
||||
@branch.write_page("Bilbo", :markdown, "# Bilbo", commit_details)
|
||||
assert @branch.page("Bilbo")
|
||||
assert @wiki.page("Gollum")
|
||||
|
||||
assert_equal 1, @wiki.repo.commits.size
|
||||
assert_equal 1, @branch.repo.commits.size
|
||||
|
||||
assert_equal nil, @wiki.page("Bilbo")
|
||||
end
|
||||
end
|
||||
|
||||
context "Renames directory traversal" do
|
||||
setup do
|
||||
@path = cloned_testpath("examples/revert.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, {})
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
test "rename aborts on nil" do
|
||||
cd = {:message => "def"}
|
||||
res = @wiki.rename_page(@wiki.page("some-super-fake-page"), "B", cd)
|
||||
assert !res, "rename did not abort with non-existant page"
|
||||
res = @wiki.rename_page(@wiki.page("B"), "", cd)
|
||||
assert !res, "rename did not abort with empty rename"
|
||||
res = @wiki.rename_page(@wiki.page("B"), nil, cd)
|
||||
assert !res, "rename did not abort with nil rename"
|
||||
end
|
||||
|
||||
test "rename page no-act" do
|
||||
# Make sure renames don't do anything if the name is the same.
|
||||
cd = {:message => "def"}
|
||||
|
||||
# B.md => B.md
|
||||
res = @wiki.rename_page(@wiki.page("B"), "B", cd)
|
||||
assert !res, "NOOP rename did not abort"
|
||||
end
|
||||
|
||||
test "rename page without directories" do
|
||||
# Make sure renames work with relative paths.
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.page("B")
|
||||
|
||||
# B.md => C.md
|
||||
res = @wiki.rename_page(source, "C", cd)
|
||||
assert res
|
||||
|
||||
renamed_ok(source, @wiki.page("C"))
|
||||
end
|
||||
|
||||
test "rename page with subdirs" do
|
||||
# Make sure renames in subdirectories happen ok
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.paged("H", "G")
|
||||
|
||||
# G/H.md => G/F.md
|
||||
@wiki.rename_page(source, "G/F", cd)
|
||||
|
||||
renamed_ok(source, @wiki.paged("F", "G"))
|
||||
end
|
||||
|
||||
test "rename page absolute path is still no-act" do
|
||||
# Make sure renames don't do anything if the name is the same.
|
||||
cd = {:message => "def"}
|
||||
|
||||
# B.md => B.md
|
||||
res = @wiki.rename_page(@wiki.page("B"), "/B", cd)
|
||||
assert !res, "NOOP rename did not abort"
|
||||
end
|
||||
|
||||
test "rename page absolute path NOOPs ok" do
|
||||
# Make sure renames don't do anything if the name is the same and we are in a subdirectory.
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.paged("H", "G")
|
||||
|
||||
# G/H.md => G/H.md
|
||||
res = @wiki.rename_page(source, "/G/H", cd)
|
||||
assert !res, "NOOP rename did not abort"
|
||||
end
|
||||
|
||||
test "rename page absolute directory" do
|
||||
# Make sure renames work with absolute paths.
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.page("B")
|
||||
|
||||
# B.md => C.md
|
||||
res = @wiki.rename_page(source, "/C", cd)
|
||||
assert res
|
||||
|
||||
renamed_ok(source, @wiki.page("C"))
|
||||
end
|
||||
|
||||
test "rename page absolute directory with subdirs" do
|
||||
# Make sure renames in subdirectories happen ok
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.paged("H", "G")
|
||||
|
||||
# G/H.md => G/F.md
|
||||
@wiki.rename_page(source, "/G/F", cd)
|
||||
|
||||
renamed_ok(source, @wiki.paged("F", "G"))
|
||||
end
|
||||
|
||||
test "rename page relative directory with new dir creation" do
|
||||
# Make sure renames in subdirectories create more subdirectories ok
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.paged("H", "G")
|
||||
|
||||
# G/H.md => G/K/F.md
|
||||
assert_not_equal k = @wiki.rename_page(source, "K/F", cd), false
|
||||
|
||||
new_page = @wiki.paged("F", "K")
|
||||
assert_not_equal new_page, nil
|
||||
renamed_ok(source, new_page)
|
||||
end
|
||||
|
||||
test "rename page absolute directory with subdir creation" do
|
||||
# Make sure renames in subdirectories create more subdirectories ok
|
||||
cd = {:message => "def"}
|
||||
source = @wiki.paged("H", "G")
|
||||
|
||||
# G/H.md => G/K/F.md
|
||||
assert_not_equal @wiki.rename_page(source, "/G/K/F", cd), false
|
||||
|
||||
new_page = @wiki.paged("F", "G/K")
|
||||
assert_not_equal new_page, nil
|
||||
renamed_ok(source, new_page)
|
||||
end
|
||||
|
||||
def renamed_ok(page_source, page_target)
|
||||
@wiki.clear_cache
|
||||
page1 = @wiki.paged(page_source.name, page_source.path)
|
||||
assert_nil page1
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_target.raw_data
|
||||
assert_equal 'def', page_target.version.message
|
||||
assert_not_equal page_source.version.sha, page_target.version.sha
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
class WikiFactory
|
||||
def self.create p, opt={}
|
||||
path = testpath "examples/test.git"
|
||||
Grit::Repo.init_bare(path)
|
||||
Gollum::Wiki.default_options = {:universal_toc => false}.merge(opt)
|
||||
cleanup = Proc.new { FileUtils.rm_r File.join(File.dirname(__FILE__), *%w[examples test.git]) }
|
||||
wiki = Gollum::Wiki.new(path)
|
||||
# set 'wiki-' prefix on ids for tests
|
||||
wiki.sanitization.id_prefix = 'wiki-'
|
||||
return wiki, path, cleanup
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user