Skip to content

Commit

Permalink
Create a test about translated expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
defro committed Jan 9, 2017
1 parent 1f0b12f commit b708f5a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
54 changes: 54 additions & 0 deletions tests/TranslationTest.php
@@ -0,0 +1,54 @@
<?php
namespace CodeIgniterGetText\Tests;

require_once('include/gettext_test_functions.php');
require_once('include/gettext_test_constants.php');

class TranslationTest extends \PHPUnit_Framework_TestCase
{
const EXPRESSION = "Let me test this expression";

/**
* @before
*/
public function testFrenchLocale()
{
$config = array(
'gettext_locale_dir' => 'testTranslations',
'gettext_text_domain' => 'my-domain',
'gettext_catalog_codeset' => 'UTF-8',
'gettext_locale' => 'fr_FR'
);

// only for avoid output when launch test
$this->expectOutputRegex('//');

\Gettext::init($config);
}

public function testDoubleUnderscore()
{
$this->assertEquals("Une expression en Français", __("A expression in English"));
}

public function testUnderscroreE()
{
$this->expectOutputRegex("/(Une expression en Français)$/");
_e("A expression in English");
}

public function testUnderscroreN_Singular()
{
$this->assertEquals(
"Une expression en Français", __("A expression in English"), 1
);
}

public function testUnderscroreN_Plural()
{
$this->assertEquals(
"Une expression en Français", __("A expression in English"), 2
);
}

}
2 changes: 1 addition & 1 deletion tests/include/gettext_test_constants.php
@@ -1,4 +1,4 @@
<?php

// Simulate constants defined in CodeIgniter
define('APPPATH', dirname(__FILE__));
define('APPPATH', realpath(dirname(__FILE__) . '/../') . '/');
Binary file not shown.
21 changes: 21 additions & 0 deletions tests/testTranslations/fr_FR/LC_MESSAGES/my-domain.po
@@ -0,0 +1,21 @@
msgid ""
msgstr ""
"Project-Id-Version: CodeIgniter Gettext Test\n"
"POT-Creation-Date: 2017-01-09 01:07+0100\n"
"PO-Revision-Date: 2017-01-09 01:07+0100\n"
"Last-Translator: Joël Gaujard <j.gaujard@gmail.com>\n"
"Language-Team: Joël Gaujard <j.gaujard@gmail.com>\n"
"Language: fr_FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: ../../..\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2\n"
"X-Poedit-SearchPath-0: .\n"

#: TranslationTest.php:31
msgid "A expression in English"
msgstr "Une expression en Français"

0 comments on commit b708f5a

Please sign in to comment.