<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Tests][1106] trunk: Add pomo tests from GlotPress</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://unit-tests.trac.wordpress.org/changeset/1106">1106</a></dd>
<dt>Author</dt> <dd>nbachiyski</dd>
<dt>Date</dt> <dd>2012-10-31 23:28:48 +0000 (Wed, 31 Oct 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add pomo tests from GlotPress</pre>
<h3>Added Paths</h3>
<ul>
<li>trunk/data/pomo/</li>
<li><a href="#trunkdatapomobad_npluralsmo">trunk/data/pomo/bad_nplurals.mo</a></li>
<li><a href="#trunkdatapomobad_npluralspo">trunk/data/pomo/bad_nplurals.po</a></li>
<li><a href="#trunkdatapomocontextmo">trunk/data/pomo/context.mo</a></li>
<li><a href="#trunkdatapomode_DE28mo">trunk/data/pomo/de_DE-2.8.mo</a></li>
<li><a href="#trunkdatapomoemptypo">trunk/data/pomo/empty.po</a></li>
<li><a href="#trunkdatapomomopot">trunk/data/pomo/mo.pot</a></li>
<li><a href="#trunkdatapomooverloadmo">trunk/data/pomo/overload.mo</a></li>
<li><a href="#trunkdatapomopluralmo">trunk/data/pomo/plural.mo</a></li>
<li><a href="#trunkdatapomosimplemo">trunk/data/pomo/simple.mo</a></li>
<li><a href="#trunkdatapomosimplepo">trunk/data/pomo/simple.po</a></li>
<li><a href="#trunkdatapomowindowslineendingspo">trunk/data/pomo/windows-line-endings.po</a></li>
<li>trunk/tests/pomo/</li>
<li><a href="#trunktestspomotest_mophp">trunk/tests/pomo/test_mo.php</a></li>
<li><a href="#trunktestspomotest_noop_translationsphp">trunk/tests/pomo/test_noop_translations.php</a></li>
<li><a href="#trunktestspomotest_pophp">trunk/tests/pomo/test_po.php</a></li>
<li><a href="#trunktestspomotest_translation_entryphp">trunk/tests/pomo/test_translation_entry.php</a></li>
<li><a href="#trunktestspomotest_translationsphp">trunk/tests/pomo/test_translations.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkdatapomobad_npluralsmo"></a>
<div class="binary"><h4>Added: trunk/data/pomo/bad_nplurals.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/data/pomo/bad_nplurals.mo
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkdatapomobad_npluralspo"></a>
<div class="addfile"><h4>Added: trunk/data/pomo/bad_nplurals.po (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/data/pomo/bad_nplurals.po         (rev 0)
+++ trunk/data/pomo/bad_nplurals.po        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+msgid ""
+msgstr ""
+"Project-Id-Version: bbPress 1.0.4 alpha\n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: 2008-12-26 17:07+0100\n"
+"Last-Translator: Fernando Tellado <fernando.tellado@gmail.com>\n"
+"Language-Team: ayudawordpress.com <admin@ayudawordpress.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: spanish\n"
+"X-Poedit-Country: spain\n"
+"Plural-Forms: nplurals=2; plural=n !=1;\\n\n"
+
+msgid "%d forum"
+msgid_plural "%d forums"
+msgstr[0] "%d foro"
+msgstr[1] "%d foros"
</ins></span></pre></div>
<a id="trunkdatapomocontextmo"></a>
<div class="binary"><h4>Added: trunk/data/pomo/context.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/data/pomo/context.mo
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkdatapomode_DE28mo"></a>
<div class="binary"><h4>Added: trunk/data/pomo/de_DE-2.8.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/data/pomo/de_DE-2.8.mo
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkdatapomomopot"></a>
<div class="addfile"><h4>Added: trunk/data/pomo/mo.pot (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/data/pomo/mo.pot         (rev 0)
+++ trunk/data/pomo/mo.pot        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR WordPress
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: wp-polyglots@lists.automattic.com\n"
+"POT-Creation-Date: 2009-06-28 11:07+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: wp-admin/includes/continents-cities.php:7
+msgid "Africa"
+msgstr ""
+
+#: wp-admin/includes/continents-cities.php:8
+msgid "Abidjan"
+msgstr ""
</ins></span></pre></div>
<a id="trunkdatapomooverloadmo"></a>
<div class="binary"><h4>Added: trunk/data/pomo/overload.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/data/pomo/overload.mo
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkdatapomopluralmo"></a>
<div class="binary"><h4>Added: trunk/data/pomo/plural.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/data/pomo/plural.mo
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkdatapomosimplemo"></a>
<div class="binary"><h4>Added: trunk/data/pomo/simple.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/data/pomo/simple.mo
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkdatapomosimplepo"></a>
<div class="addfile"><h4>Added: trunk/data/pomo/simple.po (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/data/pomo/simple.po         (rev 0)
+++ trunk/data/pomo/simple.po        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,54 @@
</span><ins>+msgid ""
+msgstr ""
+"Project-Id-Version: WordPress 2.6-bleeding\n"
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
+
+msgid "moon"
+msgstr ""
+
+msgctxt "brum"
+msgid "strut"
+msgid_plural "struts"
+msgstr[0] "ztrut0"
+msgstr[1] "ztrut1"
+msgstr[2] "ztrut2"
+
+msgid ""
+"The first thing you need to do is tell Blogger to let WordPress access your "
+"account. You will be sent back here after providing authorization."
+msgstr "baba\n"
+"dyado"
+"gugu"
+
+msgctxt ""
+"con"
+"text"
+msgid ""
+"sing"
+"ular"
+msgid_plural ""
+"plu"
+"ral"
+msgstr[0] ""
+"trans"
+"lation0"
+msgstr[1] ""
+"trans"
+"lation1"
+msgstr[2] ""
+"translation2"
+
+
+
+# baba
+#: wp-admin/x.php:111 baba:333
+#. translators: buuu
+# brubru
+#, fuzzy
+#: baba
+msgid "a"
+msgstr ""
+
+msgid "a\""
+msgstr ""
+
</ins></span></pre></div>
<a id="trunkdatapomowindowslineendingspo"></a>
<div class="addfile"><h4>Added: trunk/data/pomo/windows-line-endings.po (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/data/pomo/windows-line-endings.po         (rev 0)
+++ trunk/data/pomo/windows-line-endings.po        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+msgid ""
+msgstr ""
+"Project-Id-Version: Windows 3.11\n"
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
+
+msgid "moon"
+msgstr "yuhu"
</ins></span></pre></div>
<a id="trunktestspomotest_mophp"></a>
<div class="addfile"><h4>Added: trunk/tests/pomo/test_mo.php (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/pomo/test_mo.php         (rev 0)
+++ trunk/tests/pomo/test_mo.php        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,143 @@
</span><ins>+<?php
+
+class WP_Test_MO extends WP_UnitTestCase {
+
+        function test_mo_simple() {
+                $mo = new MO();
+                $mo->import_from_file('data/pomo/simple.mo');
+                $this->assertEquals(array('Project-Id-Version' => 'WordPress 2.6-bleeding', 'Report-Msgid-Bugs-To' => 'wp-polyglots@lists.automattic.com'), $mo->headers);
+                $this->assertEquals(2, count($mo->entries));
+                $this->assertEquals(array('dyado'), $mo->entries['baba']->translations);
+                $this->assertEquals(array('yes'), $mo->entries["kuku\nruku"]->translations);
+        }
+
+        function test_mo_plural() {
+                $mo = new MO();
+                $mo->import_from_file('data/pomo/plural.mo');
+                $this->assertEquals(1, count($mo->entries));
+                $this->assertEquals(array("oney dragoney", "twoey dragoney", "manyey dragoney", "manyeyey dragoney", "manyeyeyey dragoney"), $mo->entries["one dragon"]->translations);
+
+                $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1));
+                $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', 2));
+                $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', -8));
+
+
+                $mo->set_header('Plural-Forms', 'nplurals=5; plural=0');
+                $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1));
+                $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 2));
+                $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', -8));
+
+                $mo->set_header('Plural-Forms', 'nplurals=5; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;');
+                $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1));
+                $this->assertEquals('manyey dragoney', $mo->translate_plural('one dragon', '%d dragons', 11));
+                $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', 3));
+
+                $mo->set_header('Plural-Forms', 'nplurals=2; plural=n !=1;');
+                $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1));
+                $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', 2));
+                $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', -8));
+        }
+
+        function test_mo_context() {
+                $mo = new MO();
+                $mo->import_from_file('data/pomo/context.mo');
+                $this->assertEquals(2, count($mo->entries));
+                $plural_entry = new Translation_Entry(array('singular' => 'one dragon', 'plural' => '%d dragons', 'translations' => array("oney dragoney", "twoey dragoney","manyey dragoney"), 'context' => 'dragonland'));
+                $this->assertEquals($plural_entry, $mo->entries[$plural_entry->key()]);
+                $this->assertEquals("dragonland", $mo->entries[$plural_entry->key()]->context);
+
+                $single_entry = new Translation_Entry(array('singular' => 'one dragon', 'translations' => array("oney dragoney"), 'context' => 'not so dragon'));
+                $this->assertEquals($single_entry, $mo->entries[$single_entry->key()]);
+                $this->assertEquals("not so dragon", $mo->entries[$single_entry->key()]->context);
+
+        }
+
+        function test_translations_merge() {
+                $host = new Translations();
+                $host->add_entry(new Translation_Entry(array('singular' => 'pink',)));
+                $host->add_entry(new Translation_Entry(array('singular' => 'green',)));
+                $guest = new Translations();
+                $guest->add_entry(new Translation_Entry(array('singular' => 'green',)));
+                $guest->add_entry(new Translation_Entry(array('singular' => 'red',)));
+                $host->merge_with($guest);
+                $this->assertEquals(3, count($host->entries));
+                $this->assertEquals(array(), array_diff(array('pink', 'green', 'red'), array_keys($host->entries)));
+        }
+
+        function test_export_mo_file() {
+                $entries = array();
+                $entries[] = new Translation_Entry(array('singular' => 'pink',
+                        'translations' => array('розов')));
+                $no_translation_entry = new Translation_Entry(array('singular' => 'grey'));
+                $entries[] = new Translation_Entry(array('singular' => 'green', 'plural' => 'greens',
+                        'translations' => array('зелен', 'зелени')));
+                $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'color',
+                        'translations' => array('червен')));
+                $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'bull',
+                        'translations' => array('бик')));
+                $entries[] = new Translation_Entry(array('singular' => 'maroon', 'plural' => 'maroons', 'context' => 'context',
+                        'translations' => array('пурпурен', 'пурпурни')));
+
+                $mo = new MO();
+                $mo->set_header('Project-Id-Version', 'Baba Project 1.0');
+                foreach($entries as $entry) {
+                        $mo->add_entry($entry);
+                }
+                $mo->add_entry($no_translation_entry);
+
+                $temp_fn = $this->temp_filename();
+                $mo->export_to_file($temp_fn);
+
+                $again = new MO();
+                $again->import_from_file($temp_fn);
+
+                $this->assertEquals(count($entries), count($again->entries));
+                foreach($entries as $entry) {
+                        $this->assertEquals($entry, $again->entries[$entry->key()]);
+                }
+        }
+
+        function test_export_should_not_include_empty_translations() {
+                $entries = array( );
+                $mo = new MO;
+                $mo->add_entry( array( 'singular' => 'baba', 'translations' => array( '', '' ) ) );
+
+                $temp_fn = $this->temp_filename();
+                $mo->export_to_file( $temp_fn );
+
+                $again = new MO();
+                $again->import_from_file($temp_fn);
+
+                $this->assertEquals( 0, count( $again->entries ) );
+        }
+
+        function test_nplurals_with_backslashn() {
+                $mo = new MO();
+                $mo->import_from_file('data/pomo/bad_nplurals.mo');
+                $this->assertEquals('%d foro', $mo->translate_plural('%d forum', '%d forums', 1));
+                $this->assertEquals('%d foros', $mo->translate_plural('%d forum', '%d forums', 2));
+                $this->assertEquals('%d foros', $mo->translate_plural('%d forum', '%d forums', -1));
+        }
+
+        function disabled_test_performance() {
+                $start = microtime(true);
+                $mo = new MO();
+                $mo->import_from_file('data/pomo/de_DE-2.8.mo');
+                // echo "\nPerformance: ".(microtime(true) - $start)."\n";
+        }
+
+        function test_overloaded_mb_functions() {
+                // skipIf() method skips the whole test case, not only this method
+                // that's why we are skipping it the stupid way
+                if ((ini_get("mbstring.func_overload") & 2) != 0) {
+                        $mo = new MO();
+                        $mo->import_from_file('data/pomo/overload.mo');
+                        $this->assertEquals(array('Табло'), $mo->entries['Dashboard']->translations);
+                }
+        }
+
+        function test_load_pot_file() {
+                $mo = new MO();
+                $this->assertEquals( false, $mo->import_from_file('data/pomo/mo.pot') );
+        }
+}
</ins></span></pre></div>
<a id="trunktestspomotest_noop_translationsphp"></a>
<div class="addfile"><h4>Added: trunk/tests/pomo/test_noop_translations.php (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/pomo/test_noop_translations.php         (rev 0)
+++ trunk/tests/pomo/test_noop_translations.php        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+<?php
+
+class WP_Test_NOOP_Translations extends WP_UnitTestCase {
+        function setUp() {
+                parent::setUp();
+                $this->noop = new NOOP_Translations;
+                $this->entry = new Translation_Entry( array( 'singular' => 'baba' ) );
+                $this->plural_entry = new Translation_Entry(array('singular' => 'dyado', 'plural' => 'dyados', 'translations' => array('dyadox', 'dyadoy')));
+        }
+
+        function test_get_header() {
+                $this->assertEquals( false, $this->noop->get_header( 'Content-Type' ) );
+        }
+
+        function test_add_entry() {
+                $this->noop->add_entry( $this->entry );
+                $this->assertEquals( array(), $this->noop->entries );
+        }
+
+        function test_set_header() {
+                $this->noop->set_header( 'header', 'value' );
+                $this->assertEquals( array(), $this->noop->headers );
+        }
+
+        function test_translate_entry() {
+                $this->noop->add_entry( $this->entry );
+                $this->assertEquals( false, $this->noop->translate_entry( $this->entry ) );
+        }
+
+        function test_translate() {
+                $this->noop->add_entry( $this->entry );
+                $this->assertEquals( 'baba', $this->noop->translate( 'baba' ) );
+        }
+
+        function test_plural() {
+                $this->noop->add_entry( $this->plural_entry );
+                $this->assertEquals( 'dyado', $this->noop->translate_plural( 'dyado', 'dyados', 1 ) );
+                $this->assertEquals( 'dyados', $this->noop->translate_plural( 'dyado', 'dyados', 11 ) );
+                $this->assertEquals( 'dyados', $this->noop->translate_plural( 'dyado', 'dyados', 0 ) );
+        }
+}
</ins></span></pre></div>
<a id="trunktestspomotest_pophp"></a>
<div class="addfile"><h4>Added: trunk/tests/pomo/test_po.php (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/pomo/test_po.php         (rev 0)
+++ trunk/tests/pomo/test_po.php        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,218 @@
</span><ins>+<?php
+
+class WP_Test_PO extends WP_UnitTestCase {
+        function setUp() {
+                require_once ABSPATH . '/wp-includes/pomo/po.php';
+                // not so random wordpress.pot string -- multiple lines
+                $this->mail = "Your new WordPress blog has been successfully set up at:
+
+%1\$s
+
+You can log in to the administrator account with the following information:
+
+Username: %2\$s
+Password: %3\$s
+
+We hope you enjoy your new blog. Thanks!
+
+--The WordPress Team
+http://wordpress.org/
+";
+        $this->po_mail = '""
+"Your new WordPress blog has been successfully set up at:\n"
+"\n"
+"%1$s\n"
+"\n"
+"You can log in to the administrator account with the following information:\n"
+"\n"
+"Username: %2$s\n"
+"Password: %3$s\n"
+"\n"
+"We hope you enjoy your new blog. Thanks!\n"
+"\n"
+"--The WordPress Team\n"
+"http://wordpress.org/\n"';
+                $this->a90 = str_repeat("a", 90);
+                $this->po_a90 = "\"$this->a90\"";
+ }
+
+        function test_prepend_each_line() {
+                $this->assertEquals('baba_', PO::prepend_each_line('', 'baba_'));
+                $this->assertEquals('baba_dyado', PO::prepend_each_line('dyado', 'baba_'));
+                $this->assertEquals("# baba\n# dyado\n# \n", PO::prepend_each_line("baba\ndyado\n\n", '# '));
+        }
+
+        function test_poify() {
+                //simple
+                $this->assertEquals('"baba"', PO::poify('baba'));
+                //long word
+                $this->assertEquals($this->po_a90, PO::poify($this->a90));
+                // tab
+                $this->assertEquals('"ba\tba"', PO::poify("ba\tba"));
+                // do not add leading empty string of one-line string ending on a newline
+                $this->assertEquals('"\\\\a\\\\n\\n"', PO::poify("\a\\n\n"));
+                // backslash
+                $this->assertEquals('"ba\\\\ba"', PO::poify('ba\\ba'));
+                // random wordpress.pot string
+                $src = 'Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.';
+                $this->assertEquals("\"Categories can be selectively converted to tags using the <a href=\\\"%s\\\">category to tag converter</a>.\"", PO::poify($src));
+
+                $this->assertEquals($this->po_mail, PO::poify($this->mail));
+        }
+
+        function test_unpoify() {
+                $this->assertEquals('baba', PO::unpoify('"baba"'));
+                $this->assertEquals("baba\ngugu", PO::unpoify('"baba\n"'."\t\t\t\n".'"gugu"'));
+                $this->assertEquals($this->a90, PO::unpoify($this->po_a90));
+                $this->assertEquals('\\t\\n', PO::unpoify('"\\\\t\\\\n"'));
+                // wordwrapped
+                $this->assertEquals('babadyado', PO::unpoify("\"\"\n\"baba\"\n\"dyado\""));
+                $this->assertEquals($this->mail, PO::unpoify($this->po_mail));
+        }
+
+        function test_export_entry() {
+                $entry = new Translation_Entry(array('singular' => 'baba'));
+                $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", PO::export_entry($entry));
+                // plural
+                $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas'));
+                $this->assertEquals('msgid "baba"
+msgid_plural "babas"
+msgstr[0] ""
+msgstr[1] ""', PO::export_entry($entry));
+                $entry = new Translation_Entry(array('singular' => 'baba', 'translator_comments' => "baba\ndyado"));
+                $this->assertEquals('# baba
+# dyado
+msgid "baba"
+msgstr ""', PO::export_entry($entry));
+                $entry = new Translation_Entry(array('singular' => 'baba', 'extracted_comments' => "baba"));
+                $this->assertEquals('#. baba
+msgid "baba"
+msgstr ""', PO::export_entry($entry));
+                $entry = new Translation_Entry(array(
+                        'singular' => 'baba',
+                        'extracted_comments' => "baba",
+                        'references' => range(1, 29)));
+                $this->assertEquals('#. baba
+#: 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
+msgid "baba"
+msgstr ""', PO::export_entry($entry));
+                $entry = new Translation_Entry(array('singular' => 'baba', 'translations' => array()));
+                $this->assertEquals("msgid \"baba\"\nmsgstr \"\"", PO::export_entry($entry));
+
+                $entry = new Translation_Entry(array('singular' => 'baba', 'translations' => array('куку', 'буку')));
+                $this->assertEquals("msgid \"baba\"\nmsgstr \"куку\"", PO::export_entry($entry));
+
+                $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку')));
+                $this->assertEquals('msgid "baba"
+msgid_plural "babas"
+msgstr[0] "кукубуку"', PO::export_entry($entry));
+
+                $entry = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку', 'кукуруку', 'бабаяга')));
+                $this->assertEquals('msgid "baba"
+msgid_plural "babas"
+msgstr[0] "кукубуку"
+msgstr[1] "кукуруку"
+msgstr[2] "бабаяга"', PO::export_entry($entry));
+                // context
+                $entry = new Translation_Entry(array('context' => 'ctxt', 'singular' => 'baba', 'plural' => 'babas', 'translations' => array('кукубуку', 'кукуруку', 'бабаяга'), 'flags' => array('fuzzy', 'php-format')));
+                $this->assertEquals('#, fuzzy, php-format
+msgctxt "ctxt"
+msgid "baba"
+msgid_plural "babas"
+msgstr[0] "кукубуку"
+msgstr[1] "кукуруку"
+msgstr[2] "бабаяга"', PO::export_entry($entry));
+ }
+
+        function test_export_entries() {
+                $entry = new Translation_Entry(array('singular' => 'baba',));
+                $entry2 = new Translation_Entry(array('singular' => 'dyado',));
+                $po = new PO();
+                $po->add_entry($entry);
+                $po->add_entry($entry2);
+                $this->assertEquals("msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export_entries());
+        }
+
+        function test_export_headers() {
+                $po = new PO();
+                $po->set_header('Project-Id-Version', 'WordPress 2.6-bleeding');
+                $po->set_header('POT-Creation-Date', '2008-04-08 18:00+0000');
+                $this->assertEquals("msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: WordPress 2.6-bleeding\\n\"\n\"POT-Creation-Date: 2008-04-08 18:00+0000\\n\"", $po->export_headers());
+        }
+
+        function test_export() {
+                $po = new PO();
+                $entry = new Translation_Entry(array('singular' => 'baba',));
+                $entry2 = new Translation_Entry(array('singular' => 'dyado',));
+                $po->set_header('Project-Id-Version', 'WordPress 2.6-bleeding');
+                $po->set_header('POT-Creation-Date', '2008-04-08 18:00+0000');
+                $po->add_entry($entry);
+                $po->add_entry($entry2);
+                $this->assertEquals("msgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export(false));
+                $this->assertEquals("msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: WordPress 2.6-bleeding\\n\"\n\"POT-Creation-Date: 2008-04-08 18:00+0000\\n\"\n\nmsgid \"baba\"\nmsgstr \"\"\n\nmsgid \"dyado\"\nmsgstr \"\"", $po->export());
+        }
+
+
+        function test_export_to_file() {
+                $po = new PO();
+                $entry = new Translation_Entry(array('singular' => 'baba',));
+                $entry2 = new Translation_Entry(array('singular' => 'dyado',));
+                $po->set_header('Project-Id-Version', 'WordPress 2.6-bleeding');
+                $po->set_header('POT-Creation-Date', '2008-04-08 18:00+0000');
+                $po->add_entry($entry);
+                $po->add_entry($entry2);
+
+                $temp_fn = $this->temp_filename();
+                $po->export_to_file($temp_fn, false);
+                $this->assertEquals($po->export(false), file_get_contents($temp_fn));
+
+                $temp_fn2 = $this->temp_filename();
+                $po->export_to_file($temp_fn2);
+                $this->assertEquals($po->export(), file_get_contents($temp_fn2));
+        }
+
+        function test_import_from_file() {
+                $po = new PO();
+                $res = $po->import_from_file('data/pomo/simple.po');
+                $this->assertEquals(true, $res);
+
+                $this->assertEquals(array('Project-Id-Version' => 'WordPress 2.6-bleeding', 'Plural-Forms' => 'nplurals=2; plural=n != 1;'), $po->headers);
+
+                $simple_entry = new Translation_Entry(array('singular' => 'moon',));
+                $this->assertEquals($simple_entry, $po->entries[$simple_entry->key()]);
+
+                $all_types_entry = new Translation_Entry(array('singular' => 'strut', 'plural' => 'struts', 'context' => 'brum',
+                        'translations' => array('ztrut0', 'ztrut1', 'ztrut2')));
+                $this->assertEquals($all_types_entry, $po->entries[$all_types_entry->key()]);
+
+                $multiple_line_entry = new Translation_Entry(array('singular' => 'The first thing you need to do is tell Blogger to let WordPress access your account. You will be sent back here after providing authorization.', 'translations' => array("baba\ndyadogugu")));
+                $this->assertEquals($multiple_line_entry, $po->entries[$multiple_line_entry->key()]);
+
+                $multiple_line_all_types_entry = new Translation_Entry(array('context' => 'context', 'singular' => 'singular',
+                        'plural' => 'plural', 'translations' => array('translation0', 'translation1', 'translation2')));
+                $this->assertEquals($multiple_line_all_types_entry, $po->entries[$multiple_line_all_types_entry->key()]);
+
+                $comments_entry = new Translation_Entry(array('singular' => 'a', 'translator_comments' => "baba\nbrubru",
+                        'references' => array('wp-admin/x.php:111', 'baba:333', 'baba'), 'extracted_comments' => "translators: buuu",
+                        'flags' => array('fuzzy')));
+                $this->assertEquals($comments_entry, $po->entries[$comments_entry->key()]);
+
+                $end_quote_entry = new Translation_Entry(array('singular' => 'a"'));
+                $this->assertEquals($end_quote_entry, $po->entries[$end_quote_entry->key()]);
+        }
+
+        function test_import_from_entry_file_should_give_false() {
+                $po = new PO();
+                $this->assertFalse( $po->import_from_file( 'data/pomo/empty.po' ) );
+        }
+
+        function test_import_from_file_with_windows_line_endings_should_work_as_with_unix_line_endings() {
+                $po = new PO();
+                $this->assertTrue( $po->import_from_file( 'data/pomo/windows-line-endings.po' ) );
+                $this->assertEquals( 1, count( $po->entries ) );
+        }
+
+        //TODO: add tests for bad files
+}
+?>
</ins></span></pre></div>
<a id="trunktestspomotest_translation_entryphp"></a>
<div class="addfile"><h4>Added: trunk/tests/pomo/test_translation_entry.php (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/pomo/test_translation_entry.php         (rev 0)
+++ trunk/tests/pomo/test_translation_entry.php        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+<?php
+
+class WP_Test_Translation_Entry extends WP_UnitTestCase {
+
+ function test_create_entry() {
+                // no singular => empty object
+                $entry = new Translation_Entry();
+                $this->assertNull($entry->singular);
+                $this->assertNull($entry->plural);
+                $this->assertFalse($entry->is_plural);
+                // args -> members
+                $entry = new Translation_Entry(array(
+                        'singular' => 'baba',
+                        'plural' => 'babas',
+                        'translations' => array('баба', 'баби'),
+                        'references' => 'should be array here',
+                        'flags' => 'baba',
+                ));
+                $this->assertEquals('baba', $entry->singular);
+                $this->assertEquals('babas', $entry->plural);
+                $this->assertTrue($entry->is_plural);
+                $this->assertEquals(array('баба', 'баби'), $entry->translations);
+                $this->assertEquals(array(), $entry->references);
+                $this->assertEquals(array(), $entry->flags);
+        }
+
+        function test_key() {
+                $entry_baba = new Translation_Entry(array('singular' => 'baba',));
+                $entry_dyado = new Translation_Entry(array('singular' => 'dyado',));
+                $entry_baba_ctxt = new Translation_Entry(array('singular' => 'baba', 'context' => 'x'));
+                $entry_baba_plural = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas'));
+                $this->assertEquals($entry_baba->key(), $entry_baba_plural->key());
+                $this->assertNotEquals($entry_baba->key(), $entry_baba_ctxt->key());
+                $this->assertNotEquals($entry_baba_plural->key(), $entry_baba_ctxt->key());
+                $this->assertNotEquals($entry_baba->key(), $entry_dyado->key());
+        }
+}
</ins></span></pre></div>
<a id="trunktestspomotest_translationsphp"></a>
<div class="addfile"><h4>Added: trunk/tests/pomo/test_translations.php (0 => 1106)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/pomo/test_translations.php         (rev 0)
+++ trunk/tests/pomo/test_translations.php        2012-10-31 23:28:48 UTC (rev 1106)
</span><span class="lines">@@ -0,0 +1,75 @@
</span><ins>+<?php
+class WP_Test_Translations extends WP_UnitTestCase {
+
+        function test_add_entry() {
+                $entry = new Translation_Entry(array('singular' => 'baba',));
+                $entry2 = new Translation_Entry(array('singular' => 'dyado',));
+                $empty = new Translation_Entry();
+                $po = new Translations();
+                $po->add_entry($entry);
+                $this->assertEquals(array($entry->key() => $entry), $po->entries);
+                // add the same entry more than once
+                // we do not need to test proper key generation here, see test_key()
+                $po->add_entry($entry);
+                $po->add_entry($entry);
+                $this->assertEquals(array($entry->key() => $entry), $po->entries);
+                $po->add_entry($entry2);
+                $this->assertEquals(array($entry->key() => $entry, $entry2->key() => $entry2), $po->entries);
+                // add empty entry
+                $this->assertEquals(false, $po->add_entry($empty));
+                $this->assertEquals(array($entry->key() => $entry, $entry2->key() => $entry2), $po->entries);
+
+                // give add_entry() the arguments and let it create the entry itself
+                $po = new Translations();
+                $po->add_entry(array('singular' => 'baba',));
+                $entries= array_values($po->entries);
+                $this->assertEquals($entry->key(), $entries[0]->key());
+        }
+
+        function test_translate() {
+                $entry1 = new Translation_Entry(array('singular' => 'baba', 'translations' => array('babax')));
+                $entry2 = new Translation_Entry(array('singular' => 'baba', 'translations' => array('babay'), 'context' => 'x'));
+                $domain = new Translations();
+                $domain->add_entry($entry1);
+                $domain->add_entry($entry2);
+                $this->assertEquals('babax', $domain->translate('baba'));
+                $this->assertEquals('babay', $domain->translate('baba', 'x'));
+                $this->assertEquals('baba', $domain->translate('baba', 'y'));
+                $this->assertEquals('babaz', $domain->translate('babaz'));
+        }
+
+        function test_translate_plural() {
+                $entry_incomplete = new Translation_Entry(array('singular' => 'baba', 'plural' => 'babas', 'translations' => array('babax')));
+                $entry_toomany = new Translation_Entry(array('singular' => 'wink', 'plural' => 'winks', 'translations' => array('winki', 'winka', 'winko')));
+                $entry_2 = new Translation_Entry(array('singular' => 'dyado', 'plural' => 'dyados', 'translations' => array('dyadox', 'dyadoy')));
+                $domain = new Translations();
+                $domain->add_entry($entry_incomplete);
+                $domain->add_entry($entry_toomany);
+                $domain->add_entry($entry_2);
+                $this->assertEquals('other', $domain->translate_plural('other', 'others', 1));
+                $this->assertEquals('others', $domain->translate_plural('other', 'others', 111));
+                // too few translations + cont logic
+                $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 2));
+                $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 0));
+                $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', -1));
+                $this->assertEquals('babas', $domain->translate_plural('baba', 'babas', 999));
+                // proper
+                $this->assertEquals('dyadox', $domain->translate_plural('dyado', 'dyados', 1));
+                $this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', 0));
+                $this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', 18881));
+                $this->assertEquals('dyadoy', $domain->translate_plural('dyado', 'dyados', -18881));
+        }
+
+        function test_digit_and_merge() {
+                $entry_digit_1 = new Translation_Entry(array('singular' => 1, 'translations' => array('1')));
+                $entry_digit_2 = new Translation_Entry(array('singular' => 2, 'translations' => array('2')));
+                $domain = new Translations();
+                $domain->add_entry($entry_digit_1);
+                $domain->add_entry($entry_digit_2);
+                $dummy_translation = new Translations;
+                $this->assertEquals( '1', $domain->translate( '1' ) );
+                $domain->merge_with( $dummy_translation );
+                $this->assertEquals( '1', $domain->translate( '1' ) );
+        }
+
+}
</ins></span></pre>
</div>
</div>
</body>
</html>