File: test_xml.rb

package info (click to toggle)
ruby-loofah 2.2.3-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 452 kB
  • sloc: ruby: 2,153; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,826 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require "helper"

class IntegrationTestXml < Loofah::TestCase
  context "integration test" do
    context "xml document" do
      context "custom scrubber" do
        it "act as expected" do
          xml = Loofah.xml_document <<-EOXML
            <root>
              <employee deceased='true'>Abraham Lincoln</employee>
              <employee deceased='false'>Abe Vigoda</employee>
            </root>
          EOXML
          bring_out_your_dead = Loofah::Scrubber.new do |node|
            if node.name == "employee" and node["deceased"] == "true"
              node.remove
              Loofah::Scrubber::STOP # don't bother with the rest of the subtree
            end
          end
          assert_equal 2, xml.css("employee").length
          
          xml.scrub!(bring_out_your_dead)

          employees = xml.css "employee"
          assert_equal 1, employees.length
          assert_equal "Abe Vigoda", employees.first.inner_text
        end
      end
    end

    context "xml fragment" do
      context "custom scrubber" do
        it "act as expected" do
          xml = Loofah.xml_fragment <<-EOXML
            <employee deceased='true'>Abraham Lincoln</employee>
            <employee deceased='false'>Abe Vigoda</employee>
          EOXML
          bring_out_your_dead = Loofah::Scrubber.new do |node|
            if node.name == "employee" and node["deceased"] == "true"
              node.remove
              Loofah::Scrubber::STOP # don't bother with the rest of the subtree
            end
          end
          assert_equal 2, xml.css("employee").length
          
          xml.scrub!(bring_out_your_dead)

          employees = xml.css "employee"
          assert_equal 1, employees.length
          assert_equal "Abe Vigoda", employees.first.inner_text
        end
      end
    end
  end
end