class Nanoc::Extra::Checking::Checks::MixedContentTest < Nanoc::TestCase def create_output_file(name, lines) FileUtils.mkdir_p('output') File.open('output/' + name, 'w') do |io| io.write(lines.join('\n')) end end def assert_include(haystack, needle) assert haystack.include?(needle), "Expected to find '#{needle}' in #{haystack}" end def test_https_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '
', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end def test_root_relative_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end def test_protocol_relative_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end def test_document_relative_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end def test_query_relative_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end def test_fragment_relative_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end def test_http_content with_site do |site| create_output_file('foo.html', [ '', '', '', '', '', '', '', '', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run issues = check.issues.to_a assert_equal 8, issues.count descriptions = issues.map(&:description) issues.each do |issue| assert_equal 'output/foo.html', issue.subject end # The order of the reported issues is not important, so use this class's # `assert_include` helper to avoid asserting those details assert_include descriptions, 'mixed content include: http://nanoc.ws/logo.png' assert_include descriptions, 'mixed content include: HTTP://nanoc.ws/logo.png' assert_include descriptions, 'mixed content include: http://nanoc.ws/style.css' assert_include descriptions, 'mixed content include: http://nanoc.ws/app.js' assert_include descriptions, 'mixed content include: http://nanoc.ws/process.cgi' assert_include descriptions, 'mixed content include: http://nanoc.ws/preview.html' assert_include descriptions, 'mixed content include: http://nanoc.ws/theme-song.flac' assert_include descriptions, 'mixed content include: http://nanoc.ws/screencast.mkv' end end def test_inert_content with_site do |site| create_output_file('foo.html', [ 'The homepage', 'Content', '', '', '', '', '', '', '', '', 'http://nanoc.ws/harmless-text
', ]) check = Nanoc::Extra::Checking::Checks::MixedContent.create(site) check.run assert_empty check.issues end end end