# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors 
this is a paragraph
this is a linebreak
  """
  @html_span_class_sample """
    hi
  """
  @html_span_microformats_sample """
    @foo
  """
  @html_span_invalid_microformats_sample """
    @foo
  """
  describe "StripTags scrubber" do
    test "works as expected" do
      expected = """
      this is in bold
        this is a paragraph
        this is a linebreak
        this is a link with allowed "rel" attribute: example.com
        this is a link with not allowed "rel" attribute: example.com
        this is an image: 
        alert('hacked')
      """
      assert expected == HTML.strip_tags(@html_sample)
    end
    test "does not allow attribute-based XSS" do
      expected = "\n"
      assert expected == HTML.strip_tags(@html_onerror_sample)
    end
  end
  describe "TwitterText scrubber" do
    test "normalizes HTML as expected" do
      expected = """
      this is in bold
        this is a paragraph
this is a linebreak
      """
      assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.TwitterText)
    end
    test "does not allow spans with invalid classes" do
      expected = """
      hi
      """
      assert expected ==
               HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.TwitterText)
    end
    test "does allow microformats" do
      expected = """
      @foo
      """
      assert expected ==
               HTML.filter_tags(@html_span_microformats_sample, Pleroma.HTML.Scrubber.TwitterText)
    end
    test "filters invalid microformats markup" do
      expected = """
      @foo
      """
      assert expected ==
               HTML.filter_tags(
                 @html_span_invalid_microformats_sample,
                 Pleroma.HTML.Scrubber.TwitterText
               )
    end
  end
  describe "default scrubber" do
    test "normalizes HTML as expected" do
      expected = """
      this is in bold
        this is a paragraph
this is a linebreak
      """
      assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.Default)
    end
    test "does not allow spans with invalid classes" do
      expected = """
      hi
      """
      assert expected == HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.Default)
    end
    test "does allow microformats" do
      expected = """
      @foo
      """
      assert expected ==
               HTML.filter_tags(@html_span_microformats_sample, Pleroma.HTML.Scrubber.Default)
    end
    test "filters invalid microformats markup" do
      expected = """
      @foo
      """
      assert expected ==
               HTML.filter_tags(
                 @html_span_invalid_microformats_sample,
                 Pleroma.HTML.Scrubber.Default
               )
    end
  end
end