2 # -*- coding: utf-8 -*-
4 from translate
.storage
import php
5 from translate
.storage
import test_monolingual
6 from translate
.misc
import wStringIO
8 def test_php_escaping():
9 """Test the helper escaping funtions"""
11 assert php
.phpencode("'") == "\\'"
12 assert php
.phpencode('"', quotechar
='"') == '\\"'
13 assert php
.phpencode("\n") == "\\n"
15 assert php
.phpdecode("\\'") == "'"
16 assert php
.phpdecode('\\"') == '"'
17 assert php
.phpdecode("\\n") == "\n"
19 class TestPhpUnit(test_monolingual
.TestMonolingualUnit
):
20 UnitClass
= php
.phpunit
22 def test_difficult_escapes(self
):
25 class TestPhpFile(test_monolingual
.TestMonolingualStore
):
26 StoreClass
= php
.phpfile
28 def phpparse(self
, phpsource
):
29 """helper that parses php source without requiring files"""
30 dummyfile
= wStringIO
.StringIO(phpsource
)
31 phpfile
= php
.phpfile(dummyfile
)
34 def phpregen(self
, phpsource
):
35 """helper that converts php source to phpfile object and back"""
36 return str(self
.phpparse(phpsource
))
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"
47 def test_simpledefinition_source(self
):
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
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"