Skip to content

Commit

Permalink
Adding automatic tests and trying to fix finnish language
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Feb 22, 2015
1 parent 77e0d7f commit 8bc16cf
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 112 deletions.
4 changes: 2 additions & 2 deletions src/lang/fi/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

'ago' => ':time sitten',
'from_now' => ':time tästä hetkestä',
'after' => '',
'before' => '',
'after' => ':time sen jälkeen',
'before' => ':time ennen',
'year' => '1 vuosi|:count vuotta',
'month' => '1 kuukausi|:count kuukautta',
'week' => '1 viikko|:count viikkoa',
Expand Down
14 changes: 7 additions & 7 deletions src/lang/ro/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
'from_now' => ':time de acum',
'after' => 'peste :time',
'before' => 'acum :time',
'year' => 'un an|:count ani',
'month' => 'o luna|:count luni',
'week' => 'o saptamana|:count saptamani',
'day' => 'o zi|:count zile',
'hour' => 'o ora|:count ore',
'year' => 'un an|:count ani|:count ani',
'month' => 'o luna|:count luni|:count luni',
'week' => 'o saptamana|:count saptamani|:count saptamani',
'day' => 'o zi|:count zile|:count zile',
'hour' => 'o ora|:count ore|:count ore',
'minute' => 'un minut|:count minute|:count minute',
'second' => 'o secunda|:count secunde',
'second' => 'o secunda|:count secunde|:count secunde',

'january' => 'ianuarie',
'february' => 'februarie',
Expand All @@ -45,4 +45,4 @@
'saturday' => 'sambata',
'sunday' => 'duminica',

);
);
175 changes: 175 additions & 0 deletions tests/AutomaticTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php

use Jenssegers\Date\Date;
use Jenssegers\Date\Translator;
use Symfony\Component\Translation\MessageSelector;

class AutomaticTest extends PHPUnit_Framework_TestCase {

public function setUp()
{
$this->languages = array_slice(scandir('src/lang'), 2);
}

public function testTranslatesMonths()
{
$months = array(
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december'
);

foreach ($this->languages as $language)
{
$translations = include "src/lang/$language/date.php";

foreach ($months as $month)
{
$date = new Date("1 $month");
$date->setLocale($language);

$this->assertTrue(isset($translations[$month]));
$this->assertEquals($translations[$month], $date->format('F'), "Language: $language"); // Full
$this->assertEquals(substr($translations[$month], 0 , 3), $date->format('M'), "Language: $language"); // Short
}
}
}

public function testTranslatesDays()
{
$days = array(
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday'
);

foreach ($this->languages as $language)
{
$translations = include "src/lang/$language/date.php";

foreach ($days as $day)
{
$date = new Date($day);
$date->setLocale($language);

$this->assertTrue(isset($translations[$day]));
$this->assertEquals($translations[$day], $date->format('l'), "Language: $language"); // Full
$this->assertEquals(substr($translations[$day], 0 , 3), $date->format('D'), "Language: $language"); // Short
}
}
}

public function testTranslatesDiffForHumans()
{
$items = array(
'ago',
'from_now',
'after',
'before',
'year',
'month',
'week',
'day',
'hour',
'minute',
'second'
);

foreach ($this->languages as $language)
{
$translations = include "src/lang/$language/date.php";

foreach ($items as $item)
{
$this->assertTrue(isset($translations[$item]), "Language: $language >> $item");

if ( ! $translations[$item])
{
echo "\nWARNING! '$item' not set for language $language";
continue;
}

if (in_array($item, array('ago', 'from_now', 'after', 'before')))
{
$this->assertContains(':time', $translations[$item], "Language: $language");
}
else
{
$this->assertContains(':count', $translations[$item], "Language: $language");
}
}
}
}

public function testTranslatesCounts()
{
$items = array(
'ago',
'from_now',
'after',
'before',
'year',
'month',
'week',
'day',
'hour',
'minute',
'second'
);

foreach ($this->languages as $language)
{
if (in_array($language, array('ar')))
{
echo "\nWARNING! Not running automatic test for $language\n";
continue;
}

$translations = include "src/lang/$language/date.php";

$translator = Date::getTranslator();
$translator->setLocale($language);

foreach ($items as $item)
{
$this->assertTrue(isset($translations[$item]), "Language: $language >> $item");

if ( ! $translations[$item])
{
echo "\nWARNING! '$item' not set for language $language\n";
continue;
}

for ($i = 0; $i <= 60; $i++)
{
if (in_array($item, array('ago', 'from_now', 'after', 'before')))
{
$translation = $translator->choice("date::date.$item", $i, array('time' => $i));
$this->assertNotNull($translation, "Language: $language ($i)");
$this->assertNotContains(':time', $translation, "Language: $language ($i)");
}
else
{
$translation = $translator->choice("date::date.$item", $i);
$this->assertNotNull($translation, "Language: $language ($i)");
$this->assertNotContains(':count', $translation, "Language: $language ($i)");
}
}
}
}
}

}
103 changes: 0 additions & 103 deletions tests/TranslationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,107 +72,4 @@ public function testCustomSuffix()
$this->assertSame("vor 5 Sekunden", $date->ago());
}

public function testTranslatesMonths()
{
$months = array(
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december'
);

foreach ($this->languages as $language)
{
$translations = include "src/lang/$language/date.php";

foreach ($months as $month)
{
$date = new Date("1 $month");
$date->setLocale($language);

$this->assertTrue(isset($translations[$month]));
$this->assertEquals($translations[$month], $date->format('F'), "Language: $language"); // Full
$this->assertEquals(substr($translations[$month], 0 , 3), $date->format('M'), "Language: $language"); // Short
}
}
}

public function testTranslatesDays()
{
$days = array(
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday'
);

foreach ($this->languages as $language)
{
$translations = include "src/lang/$language/date.php";

foreach ($days as $day)
{
$date = new Date($day);
$date->setLocale($language);

$this->assertTrue(isset($translations[$day]));
$this->assertEquals($translations[$day], $date->format('l'), "Language: $language"); // Full
$this->assertEquals(substr($translations[$day], 0 , 3), $date->format('D'), "Language: $language"); // Short
}
}
}

public function testTranslatesDiffForHumans()
{
$items = array(
'ago',
'from_now',
'after',
'before',
'year',
'month',
'week',
'day',
'hour',
'minute',
'second'
);

foreach ($this->languages as $language)
{
$translations = include "src/lang/$language/date.php";

foreach ($items as $item)
{
$this->assertTrue(isset($translations[$item]), "Language: $language >> $item");

if ( ! $translations[$item])
{
echo "\nWARNING! '$item' not set for language $language";
continue;
}

if (in_array($item, array('ago', 'from_now', 'after', 'before')))
{
$this->assertContains(':time', $translations[$item], "Language: $language");
}
else
{
$this->assertContains(':count', $translations[$item], "Language: $language");
}
}
}
}

}

0 comments on commit 8bc16cf

Please sign in to comment.