from Products.DataGridField.tests.DataGridTestCase import DataGridTestCase


class TestSetup(DataGridTestCase):
    """ Unit test cases for DataGridField setup and installation """

    def testCSSNamespaceCollosion(self):
        """ See Issue #30 at
            http://plone.org/products/datagridfield/issues/30
        """
        dgf_skin_layer = getattr(self.portal.portal_skins, 'DataGridWidget')
        self.failUnless(dgf_skin_layer, "The DataGridWidget skin layer "
            " wasn't even installed within the site.")
        self.failIf(dgf_skin_layer.objectIds().count('datagridwidget.css') > 1)

    def testNamespaceCollidingCSSFilesMerged(self):
        """ And an additional follow-up to Issue #30. We have non-overlapping
            CSS declarations in a datagridwidget.css.dtml and
            datagridwidget.css file.
        """
        # datagridwidget.css.dtml handles many of the editing/view
        # interactions with DGF for example display: none of hidden
        # columns so we confirm:
        #   - td.datagridwidget-hidden-data
        raw_css = self.portal.restrictedTraverse('datagridwidget.css').raw
        self.failUnless('td.datagridwidget-hidden-data' in raw_css)

        # by contrast datagridwidget.css applies styles to what appear to be
        # autogenerated classes on the Archetypes base edit.  We maintain
        # these for BBB. Confirm:
        #   - div.ArchetypesDataGridWidget table td img
        self.failUnless('div.ArchetypesDataGridWidget table td img' in raw_css)


def test_suite():
    from unittest import TestSuite, makeSuite
    suite = TestSuite()
    suite.addTest(makeSuite(TestSetup))
    return suite
