Package translate :: Package storage :: Module test_php
[hide private]
[frames] | no frames]

Source Code for Module translate.storage.test_php

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3   
 4  from translate.storage import php 
 5  from translate.storage import test_monolingual 
 6  from translate.misc import wStringIO 
 7   
8 -def test_php_escaping():
9 """Test the helper escaping funtions""" 10 # Encoding 11 assert php.phpencode("'") == "\\'" 12 assert php.phpencode('"', quotechar='"') == '\\"' 13 assert php.phpencode("\n") == "\\n" 14 # Decoding 15 assert php.phpdecode("\\'") == "'" 16 assert php.phpdecode('\\"') == '"' 17 assert php.phpdecode("\\n") == "\n"
18
19 -class TestPhpUnit(test_monolingual.TestMonolingualUnit):
20 UnitClass = php.phpunit 21
22 - def test_difficult_escapes(self):
23 pass
24
25 -class TestPhpFile(test_monolingual.TestMonolingualStore):
26 StoreClass = php.phpfile 27
28 - def phpparse(self, phpsource):
29 """helper that parses php source without requiring files""" 30 dummyfile = wStringIO.StringIO(phpsource) 31 phpfile = php.phpfile(dummyfile) 32 return phpfile
33
34 - def phpregen(self, phpsource):
35 """helper that converts php source to phpfile object and back""" 36 return str(self.phpparse(phpsource))
37
38 - def test_simpledefinition(self):
39 """checks that a simple php definition is parsed correctly""" 40 phpsource = """$lang['mediaselect'] = 'Bestand selectie';""" 41 phpfile = self.phpparse(phpsource) 42 assert len(phpfile.units) == 1 43 phpunit = phpfile.units[0] 44 assert phpunit.name == "$lang['mediaselect']" 45 assert phpunit.source == "Bestand selectie"
46
48 """checks that a simple php definition can be regenerated as source""" 49 phpsource = """$lang['mediaselect']='Bestand selectie';""" 50 phpregen = self.phpregen(phpsource) 51 assert phpsource + '\n' == phpregen
52
53 - def test_spaces_in_name(self):
54 """check that spaces in the array name doesn't throw us off""" 55 phpsource = """$lang[ 'mediaselect' ] = 'Bestand selectie';""" 56 phpfile = self.phpparse(phpsource) 57 assert len(phpfile.units) == 1 58 phpunit = phpfile.units[0] 59 assert phpunit.name == "$lang['mediaselect']" 60 assert phpunit.source == "Bestand selectie"
61