some code',
+ '`<Location /redmine>'
+ )
+ end
+
+ it 'should escaping' do
+ assert_html_output(
+ 'this is a '
+ }
+
+ before do
+ project_2.reload
+
+ wiki_page_2_1 = FactoryGirl.create :wiki_page_with_content,
+ wiki: project_2.wiki,
+ title: 'Start Page'
+
+ project_2.wiki.pages << wiki_page_2_1
+ project_2.wiki.start_page = 'Start Page'
+ project_2.wiki.save!
+
+ project.wiki = wiki_1
+
+ wiki_1.pages << wiki_page_1_1
+ wiki_1.pages << wiki_page_1_2
+ wiki_1.pages << wiki_page_1_3
+ end
+
+ context 'Plain wiki link' do
+ subject { format_text('[[CookBook documentation]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Arbitrary wiki link' do
+ title = ''
+ subject { format_text("[[#{title}]]") }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Plain wiki page link' do
+ subject { format_text('[[Another page|Page]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Wiki link with anchor' do
+ subject { format_text('[[CookBook documentation#One-section]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Wiki page link with anchor' do
+ subject { format_text('[[Another page#anchor|Page]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Wiki link to an unknown page' do
+ subject { format_text('[[Unknown page]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Wiki page link to an unknown page' do
+ subject { format_text('[[Unknown page|404]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context "Link to another project's wiki" do
+ subject { format_text('[[onlinestore:]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context "Link to another project's wiki with label" do
+ subject { format_text('[[onlinestore:|Wiki]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context "Link to another project's wiki page" do
+ subject { format_text('[[onlinestore:Start page]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context "Link to another project's wiki page with label" do
+ subject { format_text('[[onlinestore:Start page|Text]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Link to an unknown wiki page in another project' do
+ subject { format_text('[[onlinestore:Unknown page]]') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Struck through link to wiki page' do
+ subject { format_text('-[[Another page|Page]]-') }
+
+ it { is_expected.to be_html_eql("") }
+ end
+
+ context 'Named struck through link to wiki page' do
+ subject { format_text('-[[Another page|Page]] link-') }
+
+ it { is_expected.to be_html_eql("Page link
[[Another page|Page]]
') } + end + + context 'Link to wiki of non-existing project' do + subject { format_text('[[unknowproject:Start]]') } + + it { is_expected.to be_html_eql('[[unknowproject:Start]]
') } + end + + context 'Link to wiki page of non-existing project' do + subject { format_text('[[unknowproject:Start|Page title]]') } + + it { is_expected.to be_html_eql('[[unknowproject:Start|Page title]]
') } + end + end + + context 'Redmine links' do + let(:repository) do + FactoryGirl.build_stubbed :repository_subversion, project: project + end + let(:source_url) do + { controller: 'repositories', + action: 'entry', + project_id: identifier, + path: 'some/file' } + end + let(:source_url_with_ext) do + { controller: 'repositories', + action: 'entry', + project_id: identifier, + path: 'some/file.ext' } + end + + before do + allow(project).to receive(:repository).and_return(repository) + allow(User).to receive(:current).and_return(project_member) + allow(project_member) + .to receive(:allowed_to?) + .with(:browse_repository, project) + .and_return(true) + + @to_test = { + # source + 'source:/some/file' => link_to('source:/some/file', source_url, class: 'source'), + 'source:/some/file.' => link_to('source:/some/file', source_url, class: 'source') + '.', + 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, class: 'source') + '.', + 'source:/some/file. ' => link_to('source:/some/file', source_url, class: 'source') + '.', + 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, class: 'source') + '.', + 'source:/some/file, ' => link_to('source:/some/file', source_url, class: 'source') + ',', + 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(rev: 52), class: 'source'), + 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(rev: 52), class: 'source'), + 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(anchor: 'L110'), class: 'source'), + 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(anchor: 'L110'), class: 'source'), + 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(rev: 52, anchor: 'L110'), class: 'source'), + 'export:/some/file' => link_to('export:/some/file', source_url.merge(format: 'raw'), class: 'source download'), + # escaping + '!source:/some/file' => 'source:/some/file', + # invalid expressions + 'source:' => 'source:' + } + end + + it '' do + @to_test.each do |text, result| + expect(format_text(text)).to be_html_eql("#{result}
") + end + end + end + + context 'Pre content should not parse wiki and redmine links' do + let(:wiki) { + FactoryGirl.create :wiki, + start_page: 'CookBook documentation', + project: project + } + let(:wiki_page) { + FactoryGirl.create :wiki_page_with_content, + wiki: wiki, + title: 'CookBook documentation' + } + let(:raw) { + <<-RAW +[[CookBook documentation]] + +##{issue.id} + +
+[[CookBook documentation]]
+
+##{issue.id}
+
+ RAW
+ }
+
+ let(:expected) {
+ <<-EXPECTED
+
+
+
+[[CookBook documentation]]
+
+##{issue.id}
+
+ EXPECTED
+ }
+
+ before do
+ project.wiki = wiki
+ wiki.pages << wiki_page
+ end
+
+ subject { format_text(raw) }
+
+ it { is_expected.to be_html_eql(expected) }
+ end
+
+ describe 'options' do
+ describe '#format' do
+ it 'uses format of Settings, if nothing is specified' do
+ expect(format_text('*Stars!*')).to be_html_eql('Stars!
') + end + + it 'uses format of options, if specified' do + expect(format_text('*Stars!*', format: 'plain')).to be_html_eql('*Stars!*
') + end + end + end + end + + describe 'macros within pre block' do + let(:wiki_text) { + <<-WIKI_TEXT +{{include(wiki)}}
+
+ {{include(wiki)}}
+ WIKI_TEXT
+ }
+
+ subject(:html) { format_text(wiki_text) }
+
+ it 'does not expand the macro within ' do + expect(html).to be_html_eql(%[ ++ }).at_path('fieldset') + end + end + end +end{{ $root.DOUBLE_LEFT_CURLY_BRACE }}include(wiki)}}++ Error executing the macro include (Page not found) +
+ ]) + end + end + + describe '{{toc}}', 'table of contents macro' do + # Source: http://en.wikipedia.org/wiki/Orange_(fruit) + let(:wiki_text) { + <<-WIKI_TEXT +{{toc}} + +h1. Orange + +h2. Varietes + +h3. Common Oranges + +h4. Valencia + +h5. Naranjito + +h4. Hart's Tardiff Valencia + +h3. Navel Oranges + +h3. Blood Oranges + +h3. Acidless Oranges + +h2. Attributes + + WIKI_TEXT + } + + subject(:html) { format_text(wiki_text) } + + context 'w/o request present' do + let(:request) { nil } + + it 'emits a table of contents for headings h1-h4 with anchors' do + expect(html).to be_html_eql(%{ +