2013-10-04 20:36:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2013-10-04 20:36:02 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2013-09-01 06:22:06 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.ui.formattingtagscontroller package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from openlp.core.ui import FormattingTagController
|
|
|
|
|
|
|
|
|
|
|
|
class TestFormattingTagController(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.services = FormattingTagController()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_strip(self):
|
2013-09-01 06:22:06 +00:00
|
|
|
"""
|
|
|
|
Test that the _strip strips the correct chars
|
|
|
|
"""
|
|
|
|
# GIVEN: An instance of the Formatting Tag Form and a string containing a tag
|
2013-10-04 19:27:53 +00:00
|
|
|
tag = '{tag}'
|
2013-09-01 06:22:06 +00:00
|
|
|
|
|
|
|
# WHEN: Calling _strip
|
|
|
|
result = self.services._strip(tag)
|
|
|
|
|
|
|
|
# THEN: The tag should be returned with the wrappers removed.
|
2013-10-04 19:27:53 +00:00
|
|
|
self.assertEqual(result, 'tag', 'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\'')
|
2013-09-02 20:59:19 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_end_tag_changed_processes_correctly(self):
|
2013-09-02 20:59:19 +00:00
|
|
|
"""
|
|
|
|
Test that the end html tags are generated correctly
|
|
|
|
"""
|
|
|
|
# GIVEN: A list of start , end tags and error messages
|
|
|
|
tests = []
|
|
|
|
test = {'start': '<b>', 'end': None, 'gen': '</b>', 'valid': None}
|
|
|
|
tests.append(test)
|
|
|
|
test = {'start': '<i>', 'end': '</i>', 'gen': None, 'valid': None}
|
|
|
|
tests.append(test)
|
|
|
|
test = {'start': '<b>', 'end': '</i>', 'gen': None,
|
|
|
|
'valid': 'End tag </b> does not match end tag for start tag <b>'}
|
|
|
|
tests.append(test)
|
|
|
|
|
|
|
|
# WHEN: Testing each one of them in turn
|
|
|
|
for test in tests:
|
|
|
|
error, result = self.services.end_tag_changed(test['start'], test['end'])
|
|
|
|
|
|
|
|
# THEN: The result should match the predetermined value.
|
|
|
|
self.assertTrue(result == test['gen'],
|
2014-04-02 19:35:09 +00:00
|
|
|
'Function should handle end tag correctly : %s and %s for %s ' %
|
|
|
|
(test['gen'], result, test['start']))
|
|
|
|
self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' %
|
|
|
|
error)
|
2013-09-02 20:59:19 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_start_tag_changed_processes_correctly(self):
|
2013-09-02 20:59:19 +00:00
|
|
|
"""
|
|
|
|
Test that the end html tags are generated correctly
|
|
|
|
"""
|
|
|
|
# GIVEN: A list of start , end tags and error messages
|
|
|
|
tests = []
|
|
|
|
test = {'start': '<b>', 'end': '', 'gen': '</b>', 'valid': None}
|
|
|
|
tests.append(test)
|
|
|
|
test = {'start': '<i>', 'end': '</i>', 'gen': None, 'valid': None}
|
|
|
|
tests.append(test)
|
|
|
|
test = {'start': 'superfly', 'end': '', 'gen': None, 'valid': 'Start tag superfly is not valid HTML'}
|
|
|
|
tests.append(test)
|
|
|
|
|
|
|
|
# WHEN: Testing each one of them in turn
|
|
|
|
for test in tests:
|
|
|
|
error, result = self.services.start_tag_changed(test['start'], test['end'])
|
|
|
|
|
|
|
|
# THEN: The result should match the predetermined value.
|
2014-04-02 19:35:09 +00:00
|
|
|
self.assertTrue(result == test['gen'], 'Function should handle end tag correctly : %s and %s ' %
|
|
|
|
(test['gen'], result))
|
|
|
|
self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' %
|
|
|
|
error)
|
2013-09-02 20:59:19 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_start_html_to_end_html(self):
|
2013-09-02 20:59:19 +00:00
|
|
|
"""
|
|
|
|
Test that the end html tags are generated correctly
|
|
|
|
"""
|
|
|
|
# GIVEN: A list of valid and invalid tags
|
|
|
|
tests = {'<b>': '</b>', '<i>': '</i>', 'superfly': '', '<HTML START>': None,
|
|
|
|
'<span style="-webkit-text-fill-color:red">': '</span>'}
|
|
|
|
|
|
|
|
# WHEN: Testing each one of them
|
|
|
|
for test1, test2 in tests.items():
|
|
|
|
result = self.services.start_html_to_end_html(test1)
|
|
|
|
|
|
|
|
# THEN: The result should match the predetermined value.
|
2014-04-02 19:35:09 +00:00
|
|
|
self.assertTrue(result == test2, 'Calculated end tag should be valid: %s and %s = %s' %
|
|
|
|
(test1, test2, result))
|