-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests for extract command (#134)
* Adding test for extract command * Added more tests * Improve gitignore for test files * Applied changes from StyleCI * Added test for Status command * Allow user to specify xliff_version * Applied changes from StyleCI * Bugfix * Make sure to boot kernel * Removed unused import
- Loading branch information
Showing
11 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PHP Translation package. | ||
* | ||
* (c) PHP Translation team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Translation\Bundle\Tests\Functional\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Translation\Bundle\Command\ExtractCommand; | ||
use Translation\Bundle\Model\Metadata; | ||
use Translation\Bundle\Tests\Functional\BaseTestCase; | ||
|
||
class ExtractCommandTest extends BaseTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yml'); | ||
|
||
file_put_contents(__DIR__.'/../app/Resources/translations/messages.sv.xlf', <<<'XML' | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US"> | ||
<file id="messages.en_US"> | ||
<unit id="xx1"> | ||
<segment> | ||
<source>translated.heading</source> | ||
<target>My translated heading</target> | ||
</segment> | ||
</unit> | ||
<unit id="xx2"> | ||
<segment> | ||
<source>translated.paragraph0</source> | ||
<target>My translated paragraph0</target> | ||
</segment> | ||
</unit> | ||
<unit id="xx3"> | ||
<notes> | ||
<note category="file-source" priority="1">foobar.html.twig:9</note> | ||
</notes> | ||
<segment> | ||
<source>translated.paragraph1</source> | ||
<target>My translated paragraph1</target> | ||
</segment> | ||
</unit> | ||
<unit id="xx4"> | ||
<segment> | ||
<source>not.in.source</source> | ||
<target>This is not in the source code</target> | ||
</segment> | ||
</unit> | ||
</file> | ||
</xliff> | ||
|
||
XML | ||
); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$this->bootKernel(); | ||
$application = new Application($this->kernel); | ||
|
||
$application->add(new ExtractCommand()); | ||
|
||
$command = $application->find('translation:extract'); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute([ | ||
'command' => $command->getName(), | ||
'configuration' => 'app', | ||
'locale' => 'sv', | ||
]); | ||
|
||
// the output of the command in the console | ||
$output = $commandTester->getDisplay(); | ||
|
||
// Make sure we have 4 new messages | ||
$this->assertRegExp('|New messages +4|s', $output); | ||
$this->assertRegExp('|Total defined messages +8|s', $output); | ||
|
||
$container = $this->getContainer(); | ||
$config = $container->get('php_translation.configuration_manager')->getConfiguration('app'); | ||
$catalogues = $container->get('php_translation.catalogue_fetcher')->getCatalogues($config, ['sv']); | ||
|
||
$catalogue = $catalogues[0]; | ||
$this->assertEquals('My translated heading', $catalogue->get('translated.heading'), 'Translated strings MUST NOT disappear.'); | ||
|
||
// Test meta, source-location | ||
$meta = new Metadata($catalogue->getMetadata('translated.paragraph1')); | ||
$this->assertFalse($meta->getState() === 'new'); | ||
foreach ($meta->getSourceLocations() as $sourceLocation) { | ||
$this->assertNotEquals('foobar.html.twig', $sourceLocation['path']); | ||
} | ||
|
||
$meta = new Metadata($catalogue->getMetadata('not.in.source')); | ||
$this->assertTrue($meta->getState() === 'obsolete'); | ||
|
||
$meta = new Metadata($catalogue->getMetadata('translated.title')); | ||
$this->assertTrue($meta->getState() === 'new'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PHP Translation package. | ||
* | ||
* (c) PHP Translation team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Translation\Bundle\Tests\Functional\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Translation\Bundle\Command\StatusCommand; | ||
use Translation\Bundle\Tests\Functional\BaseTestCase; | ||
|
||
class StatusCommandTest extends BaseTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yml'); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$this->bootKernel(); | ||
$application = new Application($this->kernel); | ||
|
||
$application->add(new StatusCommand()); | ||
|
||
$command = $application->find('translation:status'); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute([ | ||
'command' => $command->getName(), | ||
'configuration' => 'app', | ||
'locale' => 'en', | ||
'--json' => true, | ||
]); | ||
|
||
// the output of the command in the console | ||
$output = $commandTester->getDisplay(); | ||
$data = json_decode($output, true); | ||
|
||
$this->assertArrayHasKey('en', $data); | ||
$this->assertArrayHasKey('messages', $data['en']); | ||
$this->assertArrayHasKey('_total', $data['en']); | ||
|
||
$total = $data['en']['_total']; | ||
$this->assertArrayHasKey('defined', $total); | ||
$this->assertArrayHasKey('new', $total); | ||
$this->assertArrayHasKey('obsolete', $total); | ||
$this->assertArrayHasKey('approved', $total); | ||
$this->assertEquals(2, $total['defined']); | ||
$this->assertEquals(1, $total['new']); | ||
$this->assertEquals(0, $total['obsolete']); | ||
$this->assertEquals(1, $total['approved']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
messages.sv.xlf | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters