Skip to content

Commit

Permalink
Small tweek after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
geekwright committed Feb 4, 2018
1 parent a4c1ba3 commit 9474d05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PoInitSmarty.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PoInitSmarty extends PoInitAbstract
* @param \Smarty $smarty a fully initialize Smarty 3 instance
* @param PoFile|null $poFile a PoFile object to be used in msginit
*/
public function __construct(\Smarty $smarty, PoFile $poFile = null)
public function __construct(\Smarty $smarty, ?PoFile $poFile = null)
{
$this->smarty = $smarty;
$this->poFile = $poFile;
Expand Down
23 changes: 23 additions & 0 deletions tests/PoFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,27 @@ public function testWritePoFileException()
$this->expectException('Geekwright\Po\Exceptions\FileNotWritableException');
$pofile->writePoFile($filename);
}

public function testParsePoSourceWithInvalidLines()
{
$inputData = file_get_contents(__DIR__ . '/files/fr.po');
$inputData .=<<<EOT
This is a bogus line.
# what did it do?
EOT;
$exceptionOccured = false;
try {
$this->object->parsePoSource($inputData);
} catch (\Geekwright\Po\Exceptions\UnrecognizedInputException $e) {
$exceptionOccured = true;
}
//print_r($this->object);
self::assertTrue($exceptionOccured);
$badLines = $this->object->unrecognizedInput;
self::assertTrue(\is_array($badLines));
self::assertTrue(0 < count($badLines));
}
}
14 changes: 14 additions & 0 deletions tests/PoInitSmartyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,18 @@ public function testMsginitString_error()
$this->expectException('\SmartyCompilerException');
$this->object->msginitString($template, basename(__FILE__));
}

public function testMsginitString_noPoFile()
{
$smarty = new \Smarty;
$smarty->addPluginsDir(__DIR__ . '/smarty/plugins');
$object = new PoInitSmarty($smarty);
$template = '{_ msgid="My String"}';

$object->msginitString($template, basename(__FILE__));
$entries = $object->getPoFile()->getEntries();
/** @var \Geekwright\Po\PoEntry $entry */
$entry = $entries['My String'];
$this->assertEquals('My String', $entry->get(PoTokens::MESSAGE));
}
}

0 comments on commit 9474d05

Please sign in to comment.