Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,86 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for gettext locales.
*
* @package PhpMyAdmin-test
*/
class LocaleTest extends PHPUnit_Framework_TestCase
{
public function test_setlocale_system()
{
putenv("LC_ALL=");
// For an existing locale, it never needs emulation.
putenv("LANG=C");
_setlocale(LC_MESSAGES, "");
$this->assertEquals(0, locale_emulation());
}
public function test_setlocale_emulation()
{
putenv("LC_ALL=");
// If we set it to a non-existent locale, it still works, but uses
// emulation.
_setlocale(LC_MESSAGES, "xxx_XXX");
$this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
$this->assertEquals(1, locale_emulation());
}
public function test_get_list_of_locales()
{
// For a locale containing country code, we prefer
// full locale name, but if that's not found, fall back
// to the language only locale name.
$this->assertEquals(
array("sr_RS", "sr"),
get_list_of_locales("sr_RS")
);
// If language code is used, it's the only thing returned.
$this->assertEquals(
array("sr"),
get_list_of_locales("sr")
);
// There is support for language and charset only.
$this->assertEquals(
array("sr.UTF-8", "sr"),
get_list_of_locales("sr.UTF-8")
);
// It can also split out character set from the full locale name.
$this->assertEquals(
array("sr_RS.UTF-8", "sr_RS", "sr"),
get_list_of_locales("sr_RS.UTF-8")
);
// There is support for @modifier in locale names as well.
$this->assertEquals(
array("sr_RS.UTF-8@latin", "sr_RS@latin", "sr@latin",
"sr_RS.UTF-8", "sr_RS", "sr"),
get_list_of_locales("sr_RS.UTF-8@latin")
);
// We can pass in only language and modifier.
$this->assertEquals(
array("sr@latin", "sr"),
get_list_of_locales("sr@latin")
);
// If locale name is not following the regular POSIX pattern,
// it's used verbatim.
$this->assertEquals(
array("something"),
get_list_of_locales("something")
);
// Passing in an empty string returns an empty array.
$this->assertEquals(
array(),
get_list_of_locales("")
);
}
}

View File

@ -0,0 +1,143 @@
<?php
/**
* Tests for FileReader
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/php-gettext/streams.php';
class PMA_FileReader_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new FileReader('./test/test_data/test.file');
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for read
*
* @return void
*/
public function testRead()
{
$this->assertEquals(
$this->object->read(4),
'TEST'
);
$this->assertEquals(
$this->object->read(false),
''
);
}
/**
* Test for seekto
*
* @return void
*/
public function testSeekto()
{
$this->assertEquals(
$this->object->seekto(1),
1
);
}
/**
* Test for currentpos
*
* @return void
*/
public function testCurrentpos()
{
$this->assertEquals(
$this->object->currentpos(),
0
);
}
/**
* Test for length
*
* @return void
*/
public function testLength()
{
$this->assertEquals(
$this->object->length(),
10
);
}
/**
* Test for close
*
* @return void
*/
public function testClose()
{
$this->assertEquals(
$this->object->close(),
null
);
}
/**
* Test for non existing file
*
* @return void
*/
public function testForNonExistingFile()
{
$file = new FileReader('./path/for/no/file.txt');
// looking at the return value of a constructor is curious
// but the constructor returns a value
$this->assertFalse(
$file->__construct('./path/for/no/file.txt')
);
}
public function testForCachedFileReader()
{
$reader = new CachedFileReader('./test/test_data/test.file');
$this->assertEquals(
$reader->__construct('./test/test_data/test.file'),
null
);
$this->assertFalse(
$reader->__construct('./path/for/no/file.txt')
);
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* Tests for StreamReader
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/php-gettext/streams.php';
class PMA_StreamReader_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new StreamReader();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for read
*
* @return void
*/
public function testRead()
{
$this->assertFalse($this->object->read(4));
}
/**
* Test for seekto
*
* @return void
*/
public function testSeekto()
{
$this->assertFalse($this->object->seekto(1));
}
/**
* Test for currentpos
*
* @return void
*/
public function testCurrentpos()
{
$this->assertFalse($this->object->currentpos());
}
/**
* Test for length
*
* @return void
*/
public function testLength()
{
$this->assertFalse($this->object->length());
}
}

View File

@ -0,0 +1,125 @@
<?php
/**
* Tests for StringReader
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/php-gettext/streams.php';
class PMA_StringReader_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = new StringReader('sample string');
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for read
*
* @param int $bytes Number of bytes to read
* @param string $output Expected output
*
* @return void
*
* @dataProvider providerForTestRead
*/
public function testRead($bytes, $output)
{
$this->assertEquals(
$this->object->read($bytes),
$output
);
}
/**
* Provider for testRead
*
* @return array
*/
public function providerForTestRead()
{
return array(
array(
4,
'samp'
),
array(
6,
'sample'
),
array(
9,
'sample st'
)
);
}
/**
* Test for seekto
*
* @return void
*/
public function testSeekto()
{
$this->assertEquals(
$this->object->seekto(3),
3
);
}
/**
* Test for currentpos
*
* @return void
*/
public function testCurrentpos()
{
$this->assertEquals(
$this->object->currentpos(),
0
);
}
/**
* Test for length
*
* @return void
*/
public function testLength()
{
$this->assertEquals(
$this->object->length(),
13
);
}
}

View File

@ -0,0 +1,223 @@
<?php
/**
* Tests for gettext_reader
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/php-gettext/gettext.php';
require_once 'libraries/php-gettext/streams.php';
class PMA_Gettext_Test extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$reader = new StringReader("cchars/nint");
$this->object = new gettext_reader($reader);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for readint
*
* @return void
*/
public function testReadint()
{
$this->assertEquals(
$this->object->readint(),
1848603506
);
}
/**
* Test for readintarray
*
* @return void
*/
public function testReadintarray()
{
$this->assertEquals(
$this->object->readintarray(1),
array(
1 => 1848603506
)
);
}
/**
* Test for get_original_string
*
* @return void
*/
public function testGet_original_string()
{
$this->assertEquals(
$this->object->get_original_string(1),
''
);
}
/**
* Test for get_translation_string
*
* @return void
*/
public function testGet_translation_string()
{
$this->assertEquals(
$this->object->get_translation_string(1),
''
);
}
/**
* Test for find_string
*
* @param string $string string
* @param int $start start (internally used in recursive function)
* @param int $end end (internally used in recursive function)
* @param string $output Expected output
*
* @return void
*
* @dataProvider providerForTestFind_string
*/
public function testFind_string($string, $start, $end, $output)
{
$this->assertEquals(
$this->object->find_string($string, $start, $end),
$output
);
}
/**
* Data provider for testFind_string
*
* @return array
*/
public function providerForTestFind_string()
{
return array(
array(
'sample_string/string',
2,
5,
-1
),
array(
'sample_string/string',
-1,
-1,
-1
)
);
}
/**
* Test for translate
*
* @return void
*/
public function testTranslate()
{
$this->assertEquals(
$this->object->translate('transferable_string'),
'transferable_string'
);
}
/**
* Test for sanitize_plural_expression
*
* @param string $expr Expression to sanitize
* @param string $output Expected output
*
* @return void
*
* @dataProvider providerForTestSanitize_plural_expression
*/
public function testSanitize_plural_expression($expr, $output)
{
$this->assertEquals(
$this->object->sanitize_plural_expression($expr),
$output
);
}
/**
* Data provider for testSanitize_plural_expression
*
* @return array
*/
public function providerForTestSanitize_plural_expression()
{
return array(
array(
'employeeId = 1',
'employeeId=1;'
),
array(
'id = 1 ? true : false',
'id=1 ? (true) : (false);'
)
);
}
/**
* Test for extract_plural_forms_header_from_po_header
*
* @return void
*/
public function testExtract_plural_forms_header_from_po_header()
{
$this->assertEquals(
$this->object->extract_plural_forms_header_from_po_header(
'id = 1 ? true : false'
),
'nplurals=2; plural=n == 1 ? 0 : 1;'
);
}
/**
* Test for pgettext
*
* @return void
*/
public function testPgettext()
{
$this->assertEquals(
$this->object->pgettext('context', 'msgId'),
'msgId'
);
}
}

View File

@ -0,0 +1,91 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for gettext parsing.
*
* @package PhpMyAdmin-test
*/
require_once 'libraries/php-gettext/gettext.php';
class ParsingTest extends PHPUnit_Framework_TestCase
{
/**
* Test for extract_plural_forms_header_from_po_header
*
* @return void
*/
public function test_extract_plural_forms_header_from_po_header()
{
$parser = new gettext_reader(null);
// It defaults to a "Western-style" plural header.
$this->assertEquals(
'nplurals=2; plural=n == 1 ? 0 : 1;',
$parser->extract_plural_forms_header_from_po_header("")
);
// Extracting it from the middle of the header works.
$this->assertEquals(
'nplurals=1; plural=0;',
$parser->extract_plural_forms_header_from_po_header(
"Content-type: text/html; charset=UTF-8\n"
. "Plural-Forms: nplurals=1; plural=0;\n"
. "Last-Translator: nobody\n"
)
);
// It's also case-insensitive.
$this->assertEquals(
'nplurals=1; plural=0;',
$parser->extract_plural_forms_header_from_po_header(
"PLURAL-forms: nplurals=1; plural=0;\n"
)
);
// It falls back to default if it's not on a separate line.
$this->assertEquals(
'nplurals=2; plural=n == 1 ? 0 : 1;',
$parser->extract_plural_forms_header_from_po_header(
"Content-type: text/html; charset=UTF-8" // note the missing \n here
. "Plural-Forms: nplurals=1; plural=0;\n"
. "Last-Translator: nobody\n"
)
);
}
/**
* Test for npgettext
*
* @param int $number Number
* @param string $expected Expected output
*
* @return void
*
* @dataProvider data_provider_test_npgettext
*/
public function test_npgettext($number, $expected)
{
$parser = new gettext_reader(null);
$result = $parser->npgettext(
"context",
"%d pig went to the market\n",
"%d pigs went to the market\n",
$number
);
$this->assertSame($expected, $result);
}
/**
* Data provider for test_npgettext
*
* @return array
*/
public static function data_provider_test_npgettext()
{
return array(
array(1, "%d pig went to the market\n"),
array(2, "%d pigs went to the market\n"),
);
}
}