File: TranslationsTest.php

package info (click to toggle)
php-oscarotero-gettext 4.8.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,624 kB
  • sloc: php: 5,213; xml: 22; javascript: 18; makefile: 14
file content (90 lines) | stat: -rw-r--r-- 2,795 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

namespace Gettext\Tests;

use Gettext\Translation;
use Gettext\Translations;

class TranslationsTest extends AbstractTestCase
{
    public function testClone()
    {
        $translations = new Translations();
        $translation = new Translation('', 'Test');
        $translations->append($translation);

        $clonedTranslation = clone $translation;
        $this->assertNotSame($translation, $clonedTranslation);

        $clonedTranslations = clone $translations;

        $found = $translations->find($translation);
        $this->assertSame($found, $translation);

        $clonedFound = $clonedTranslations->find($translation);
        $this->assertInstanceOf('Gettext\\Translation', $clonedFound);
        $this->assertNotSame($clonedFound, $translation);
    }

    public function testFind()
    {
        $translations = static::get('phpcode/input', 'PhpCode');

        //Find by original
        $found = $translations->find(null, 'text 2');

        $this->assertInstanceOf('Gettext\\Translation', $found);
        $this->assertEquals('text 2', $found->getOriginal());

        //Find by context
        $found = $translations->find('context', 'text 1 with context');

        $this->assertInstanceOf('Gettext\\Translation', $found);
        $this->assertEquals('text 1 with context', $found->getOriginal());
        $this->assertEquals('context', $found->getContext());

        //No results
        $found = $translations->find(null, 'text 1 with context');
        $this->assertFalse($found);

        $found = $translations->find('no-valid-context', 'text 1 with context');
        $this->assertFalse($found);

        $found = $translations->find('context', 'text 2');
        $this->assertFalse($found);

        $found = $translations->find(null, 'no valid text 2');
        $this->assertFalse($found);
    }

    public function testGettersSetters()
    {
        $translations = static::get('po2/input', 'Po');

        $this->assertEquals('gettext generator test', $translations->getHeader('Project-Id-Version'));

        $translations->setHeader('POT-Creation-Date', '2012-08-07 13:03+0100');
        $this->assertEquals('2012-08-07 13:03+0100', $translations->getHeader('POT-Creation-Date'));
    }

    public function testMergeDefault()
    {
        $translations1 = static::get('po/Po');
        $translations2 = static::get('phpcode/Po');

        $this->assertCount(3, $translations1);
        $this->assertCount(12, $translations2);

        $translations1->mergeWith($translations2);

        $this->assertCount(15, $translations1);
    }

    public function testAdd()
    {
        $translations = static::get('po/Po');
        $translations->addFromPoFile(static::asset('phpcode/Po.po'));

        $this->assertCount(15, $translations);
    }
}