diff --git a/openlp/core/ui/formattingtagcontroller.py b/openlp/core/ui/formattingtagcontroller.py
index 242b26e30..b0c10630a 100644
--- a/openlp/core/ui/formattingtagcontroller.py
+++ b/openlp/core/ui/formattingtagcontroller.py
@@ -76,14 +76,16 @@ class FormattingTagController(object):
The end html tag.
"""
- if not desc:
- pass
for linenumber, html1 in enumerate(self.protected_tags):
if self._strip(html1[u'start tag']) == tag:
return translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag
+ if self._strip(html1[u'desc']) == desc:
+ return translate('OpenLP.FormattingTagForm', 'Description %s already defined.') % tag
for linenumber, html1 in enumerate(self.custom_tags):
if self._strip(html1[u'start tag']) == tag:
return translate('OpenLP.FormattingTagForm', 'Tag %s already defined.') % tag
+ if self._strip(html1[u'desc']) == desc:
+ return translate('OpenLP.FormattingTagForm', 'Description %s already defined.') % tag
tag = {
'desc': desc,
'start tag': '{%s}' % tag,
diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py
index c2aeddc9a..05ffca57e 100644
--- a/openlp/core/ui/formattingtagform.py
+++ b/openlp/core/ui/formattingtagform.py
@@ -160,13 +160,18 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont
"""
This function processes all user edits in the table. It is called on each cell change.
"""
- print (cur_row, cur_col, pre_col, pre_col)
# only process for editable rows
if self.tag_table_widget.item(pre_row, 0):
item = self.tag_table_widget.item(pre_row, pre_col)
text = item.text()
errors = None
- if pre_col is EDITCOLUMN.StartHtml:
+ if pre_col is EDITCOLUMN.Description:
+ if not text:
+ errors = translate('OpenLP.FormattingTagForm', 'Description is missing')
+ elif pre_col is EDITCOLUMN.Tag:
+ if not text:
+ errors = translate('OpenLP.FormattingTagForm', 'Tag is missing')
+ elif pre_col is EDITCOLUMN.StartHtml:
# HTML edited
item = self.tag_table_widget.item(pre_row, 3)
end_html = item.text()
@@ -184,5 +189,6 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont
if errors:
QtGui.QMessageBox.warning(self,
translate('OpenLP.FormattingTagForm', 'Validation Error'), errors, QtGui.QMessageBox.Ok)
+ #self.tag_table_widget.selectRow(pre_row - 1)
self.tag_table_widget.resizeRowsToContents()
diff --git a/tests/functional/openlp_core_ui/tests_formattingtagscontroller.py b/tests/functional/openlp_core_ui/tests_formattingtagscontroller.py
index 7959e82b5..279dd43f1 100644
--- a/tests/functional/openlp_core_ui/tests_formattingtagscontroller.py
+++ b/tests/functional/openlp_core_ui/tests_formattingtagscontroller.py
@@ -3,8 +3,6 @@ Package to test the openlp.core.ui.formattingtagscontroller package.
"""
from unittest import TestCase
-from mock import MagicMock, patch
-
from openlp.core.ui import FormattingTagController
@@ -17,7 +15,6 @@ class TestFormattingTagController(TestCase):
"""
Test that the _strip strips the correct chars
"""
-
# GIVEN: An instance of the Formatting Tag Form and a string containing a tag
tag = u'{tag}'
@@ -25,4 +22,67 @@ class TestFormattingTagController(TestCase):
result = self.services._strip(tag)
# THEN: The tag should be returned with the wrappers removed.
- self.assertEqual(result, u'tag', u'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\'')
\ No newline at end of file
+ self.assertEqual(result, u'tag', u'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\'')
+
+ def test_end_tag_changed_processes_correctly(self):
+ """
+ Test that the end html tags are generated correctly
+ """
+ # GIVEN: A list of start , end tags and error messages
+ tests = []
+ test = {'start': '', 'end': None, 'gen': '', 'valid': None}
+ tests.append(test)
+ test = {'start': '', 'end': '', 'gen': None, 'valid': None}
+ tests.append(test)
+ test = {'start': '', 'end': '', 'gen': None,
+ 'valid': 'End tag does not match end tag for start tag '}
+ 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'],
+ '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)
+
+ def test_start_tag_changed_processes_correctly(self):
+ """
+ Test that the end html tags are generated correctly
+ """
+ # GIVEN: A list of start , end tags and error messages
+ tests = []
+ test = {'start': '', 'end': '', 'gen': '', 'valid': None}
+ tests.append(test)
+ test = {'start': '', 'end': '', '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.
+ 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)
+
+ def test_start_html_to_end_html(self):
+ """
+ Test that the end html tags are generated correctly
+ """
+ # GIVEN: A list of valid and invalid tags
+ tests = {'': '', '': '', 'superfly': '', '': None,
+ '': ''}
+
+ # 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.
+ self.assertTrue(result == test2, 'Calculated end tag should be valid: %s and %s = %s'
+ % (test1, test2, result))
\ No newline at end of file