<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))

class WikiTest < ActionController::IntegrationTest
  include CacheableFlash::TestHelpers
  
  def test_view_empty_wiki_with_default_permissions
    factory_scenario :site_with_a_wiki
    
    # wiki does not have any wikipages
    assert @section.wikipages.empty?
    
    # go to wiki show page
    get "/wiki"
    
    # user is redirected to login
    assert_redirected_to '/login'
  end
  
  def test_view_empty_wiki_with_anonymous_permissions
    factory_scenario :site_with_a_wiki
    
    # wiki with anonymous permissions for creating a wikipage
    @section.update_attributes! :permissions => { :'create wikipage' => 'anonymous' }
    
    # wiki does not have any wikipages
    assert @section.wikipages.empty?
    
    # go to wiki show page
    get '/wiki'
    
    # the page renders the wiki new form
    assert_template 'wiki/new'
    
    # the page has wikipage form ...
    # ... with a title field ...
    assert_select "label[for='wikipage_title']", true, "Wikipage form should have a label for a title form field."
    assert_select "input[id='wikipage_title']", true, "Wikipage form should have a title form field."
    
    # ... and a permalink field ...
    assert_select "label[for='wikipage_permalink']", true, "Wikipage form should have a label for a permalink form field."
    assert_select "input[id='wikipage_permalink']", true, "Wikipage form should have a permalink form field."
    
    # ... and a body field ...
    assert_select "label[for='wikipage_body']", true, "Wikipage form should have a label for a body form field."
    assert_select "textarea[id='wikipage_body']", true, "Wikipage form should have a body form field."
    
    # ... and a tag list field ...
    assert_select "label[for='wikipage_tag_list']", true, "Wikipage form should have a label for a tag list form field."
    assert_select "input[id='wikipage_tag_list']", true, "Wikipage form should have a tag list form field."
    assert_select "span.hint", true, "Wikipage form should have a hint span for tags."
    
    # check that the page is not cached
    assert_not_page_cached
  end
  
  def test_view_wiki_home_page_and_wikipage_show_action
    factory_scenario :site_with_a_wiki, :home_wikipage_with_revision
    
    # wiki has at least one wikipage
    assert !@section.wikipages.empty?, "Wiki should have at least one wikipage"
    
    # go to wiki index page
    get wikipages_path(@section)
    
    # the page renders the wiki index page
    assert_template 'wiki/index', "Wiki should have a template for index view"
    
    # wiki index page should have list of wikipages ...
    assert_select "table#wikipages.list", true, "The page should contain a list of wikipages" do
      assert_select "tbody#wikipages-body", true do
        assert_select "tr#wikipage_#{@section.id}", true do
          # ... with links to wikipages show actions ...
          assert_select "a[href$='#{@wikipage.permalink}']", true, "The page should contain a show link for wikipage."
          # ... and display wikipage timestamp.
          assert_select "abbr.datetime", true, "The page should contain a timestamp for wikipage"
        end
      end
    end
    
    assert_select "a[href$='pages/new']", true, "The page should contain a link to new wikipage action."
    
    # check that the index page is cached
    assert_page_cached
  end
  
  def test_view_wikis_wikipage
    factory_scenario :site_with_a_wiki, :home_wikipage_with_revision
    
    # go to wikipage show page
    get "/pages/wiki-home"
    
    # the page renders the wiki index page
    assert_template 'wiki/show', "Wiki should have a template for show view"
    
    # authorized link should be visible only for following people:
    user            = "user-#{<EMAIL>}"
    site_admin      = "site-#{@site.id}-admin"
    wiki_moderator  = "section-#{@section.id}-moderator"
    wikipage_author = "content-#{@wikipage.id}-author"
    wikipage_owner  = "content-#{@wikipage.id}-owner"
    visible_for = "user #{user} #{wikipage_author} #{wiki_moderator} #{site_admin} #{wikipage_owner} superuser"
  
    # the page should show the wikipage ...
    assert_select "div#wikipage_#{@wikipage.id}", true, "The page should containt the wikipage" do
      # ... with meta info of wikipage ...
      assert_select "div.meta", true, "The page should contain meta information." do
        # ... with link to wikipages index ...
        assert_select "a[href$='pages']", true, "The page should contain a link to wikipages index."
        # ... with revision number ...
        assert_select "h4", /revision: #{@wikipage.version}/, "The meta information of the wikipage should contain a revision number."
        # ... with author name ...
        assert_select "p", /by: <NAME>/, "The meta information of the wikipage should contain the name of the author"
      end
      # ... with wikipage content ...
      assert_select "div.content" do
        # ... with link to a wikipage ...
        assert_select "a[href$='pages/#{@wikipage.permalink}']", true, "The page should contain a link to the wikipage."
        # ... with wikipage body ...
        assert_select "p", /this is a wiki home page/, "The content of the wikipage should contain the body of wikipage."
        # ... with link list ...
        assert_select "ul.links", true, "The page should have list of links" do
          # ... with link to the home ...
          assert_select "a[href='/']", true, "The page should contain a link to the home."
          # ... with authorized links ...
          assert_select "li[class~='visible-for #{visible_for}']", true, "The page should contain authorized span for #{visible_for}." do
            # ... with authorized edit link ...
            assert_select "a[href$='edit']", true, "The page should contain the edit link."
          end
          # ... with link to go to previous version ...
          assert_select "a[href$='rev/#{@wikipage.version - 1}']", true, "The page should contain the previous revision link."
        end
      end
    end
    <commit_msg>fixed integration wiki tests<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))

class WikiTest < ActionController::IntegrationTest
  include CacheableFlash::TestHelpers
  
  def test_view_empty_wiki_with_default_permissions
    factory_scenario :site_with_a_wiki
    
    # wiki does not have any wikipages
    assert @section.wikipages.empty?
    
    # go to wiki show page
    get "/wiki"
    
    # user is redirected to login
    assert_redirected_to login_path(:return_to => request.url)
  end
  
  def test_view_empty_wiki_with_anonymous_permissions
    factory_scenario :site_with_a_wiki
    
    # wiki with anonymous permissions for creating a wikipage
    @section.update_attributes! :permissions => { :'create wikipage' => 'anonymous' }
    
    # wiki does not have any wikipages
    assert @section.wikipages.empty?
    
    # go to wiki show page
    get '/wiki'
    
    # the page renders the wiki new form
    assert_template 'wiki/new'
    
    # the page has wikipage form ...
    # ... with a title field ...
    assert_select "label[for='wikipage_title']", true
    assert_select "input[id='wikipage_title']", true
    
    # ... and a permalink field ...
    assert_select "label[for='wikipage_permalink']", true
    assert_select "input[id='wikipage_permalink']", true
    
    # ... and a body field ...
    assert_select "label[for='wikipage_body']", true
    assert_select "textarea[id='wikipage_body']", true
    
    # ... and a tag list field ...
    assert_select "label[for='wikipage_tag_list']", true
    assert_select "input[id='wikipage_tag_list']", true
    assert_select "span.hint", true
    
    # check that the page is not cached
    assert_not_page_cached
  end
  
  def test_view_wiki_home_page_and_wikipage_show_action
    factory_scenario :site_with_a_wiki, :home_wikipage_with_revision
    
    # wiki has at least one wikipage
    assert !@section.wikipages.empty?, "Wiki should have at least one wikipage"
    
    # go to wiki index page
    get wikipages_path(@section)
    
    # the page renders the wiki index page
    assert_template 'wiki/index', "Wiki should have a template for index view"
    
    # wiki index page should have list of wikipages ...
    assert_select "table#wikipages.list", true, "The page should contain a list of wikipages" do
      assert_select "tbody#wikipages-body", true do
        assert_select "tr#wikipage_#{@wikipage.id}", true do
          assert_select "a[href$='#{@wikipage.permalink}']", true
          assert_select "abbr.datetime", true
        end
      end
    end
    
    assert_select "a[href$='pages/new']", true, "The page should contain a link to new wikipage action."
    
    # check that the index page is cached
    assert_page_cached
  end
  
  def test_view_wikis_wikipage
    factory_scenario :site_with_a_wiki, :home_wikipage_with_revision
    
    # go to wikipage show page
    get "/pages/wiki-home"
    
    # the page renders the wiki index page
    assert_template 'wiki/show', "Wiki should have a template for show view"
    
    # authorized link should be visible only for following people:
    user            = "user-#{<EMAIL>}"
    site_admin      = "site-#{@site.id}-admin"
    wiki_moderator  = "section-#{@section.id}-moderator"
    wikipage_author = "content-#{@wikipage.id}-author"
    wikipage_owner  = "content-#{@wikipage.id}-owner"
    visible_for = "user #{user} #{wikipage_author} #{wiki_moderator} #{site_admin} #{wikipage_owner} superuser"
  
    # the page should show the wikipage ...
    assert_select "div#wikipage_#{@wikipage.id}", true do
      assert_select "div.meta", true do
        assert_select "a[href$='pages']", true
        assert_select "h4", /revision: #{@wikipage.version}/
        assert_select "p", /by: <NAME>/
      end
    
      assert_select "div.content" do
        assert_select "a[href$='pages/#{@wikipage.permalink}']", true
        assert_select "p", /this is a wiki home page/
        assert_select "ul.links", true do
          assert_select "a[href='/']", true
          assert_select "li[class~='visible-for #{visible_for}']", true, "The page should contain authorized span for #{visible_for}." do
            assert_select "a[href$='edit']", true
          end
          assert_select "a[href$='rev/#{@wikipage.version - 1}']", true
        end
      end
    end
    
{'fraction_non_alphanumeric': 0.10539821326743964, 'fraction_numerical': 0.00038015586390420075, 'mean_word_length': 2.8959644576082932, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5757992', 'n_tokens_mistral': 3241, 'n_tokens_neox': 3251, 'n_words': 991}