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
|
<?php
namespace Gettext\Tests;
use Gettext\Translation;
use Gettext\Translations;
class TranslationTest extends AbstractTestCase
{
public function testReferences()
{
$translations = static::get('phpcode/input', 'PhpCode');
$translation = $translations->find(null, 'text 10 with plural');
$this->assertInstanceOf('Gettext\\Translation', $translation);
$references = $translation->getReferences();
$this->assertCount(1, $references);
$this->assertTrue($translation->hasReferences());
$this->assertEquals(static::asset('phpcode/input.php'), $references[0][0]);
$this->assertEquals(19, $references[0][1]);
$translation->deleteReferences();
$this->assertCount(0, $translation->getReferences());
}
public function testNoReferences()
{
$po = static::get('phpcode/input', 'PhpCode')->toPoString(['noLocation' => true]);
$translations = Translations::fromPoString($po);
$translation = $translations->find(null, 'text 10 with plural');
$this->assertInstanceOf('Gettext\\Translation', $translation);
$references = $translation->getReferences();
$this->assertCount(0, $references);
$this->assertFalse($translation->hasReferences());
}
public function testPlurals()
{
$translations = static::get('phpcode/input', 'PhpCode');
$translation = $translations->find(null, 'text 10 with plural');
$this->assertTrue($translation->hasPlural());
$this->assertTrue($translation->is('', 'text 10 with plural'));
$translation = $translations->find(null, 'text 2');
$this->assertFalse($translation->hasPlural());
$translation->setPluralTranslations(['texts 2']);
$pluralTranslations = $translation->getPluralTranslations();
$this->assertCount(1, $pluralTranslations);
$this->assertEquals('texts 2', $pluralTranslations[0]);
}
public function testMerge()
{
$one = new Translation(null, '1 child');
$two = new Translation(null, '1 child');
$two->setTranslation('1 fillo');
$one->mergeWith($two);
$this->assertEquals('1 child', $one->getOriginal());
$this->assertEquals('1 fillo', $one->getTranslation());
}
}
|