# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - tests i18n strings definition of page names

    @copyright: 2009 MoinMoin:ReimarBauer

    @license: GNU GPL, see COPYING for details.
"""

from MoinMoin.i18n import strings
from MoinMoin.Page import Page


class TestStrings:
    """
    tests page name strings of i18n
    """
    def underlay_pages(self, language='en'):
        underlay_page_list = []
        for name in self.request.rootpage.getPageList(exists=1):
            page = Page(self.request, name)
            if page.getPageStatus()[0] and page.pi['language'] == language:
                # is an underlay page in the wanted language
                underlay_page_list.append(name)
        return underlay_page_list

    def testUniqueStringNames(self):
        """
        tests if given names from  strings.all_pages are unique defined
        """
        assert len(list(set(strings.all_pages))) == len(strings.all_pages)

    def testStringPageIsUnderlayPage(self):
        """
        tests if the page in the strings.all_pages list is defined as underlay page
        """
        underlay_pages = self.underlay_pages('en')
        missing_pages =  [page_name for page_name in strings.all_pages if page_name not in underlay_pages]
        assert missing_pages == []

    def testOrphanedUnderlayPage(self):
        """
        tests if we have in underlay pages which don't be listed in strings.all_pages
        """
        orphaned_pages = []
        underlay_pages = self.underlay_pages('en')
        orphaned_pages = [page_name for page_name in underlay_pages if page_name not in strings.all_pages]
        #orph = '\n'.join(orphaned_pages)
        #open('/tmp/orphaned.txt', 'w').write(orph.encode('utf-8'))
        assert orphaned_pages == []

coverage_modules = ['MoinMoin.i18n.strings']
