public function translationTestDataProvider() { $data = array(); $translator = $this->getTranslator(); $parser = $this->getParser(); $finder = new Finder(); $i18ns = $finder->files()->name('*.xliff')->in(__DIR__ . '/../Fixtures/i18n'); foreach ($i18ns as $i18n) { $language = basename($i18n, '.xliff'); $translator->addResource('xliff', $i18n, $language, 'gherkin'); $etalon = array(); $features = array(); foreach ($this->getTranslatedKeywords('Feature', $language) as $featureNum => $featureKeyword) { $gherkin = "# language: {$language}"; $lineNum = 1; $feature = new Node\FeatureNode(null, null, null, ++$lineNum); $feature->setLanguage($language); $feature->setKeyword($featureKeyword); $feature->setTitle($title = "title of the feature N{$featureNum}"); $feature->setDescription($description = "some\nfeature\ndescription"); $gherkin .= "\n{$featureKeyword}: {$title}"; $gherkin .= "\n{$description}"; $lineNum += 3; $stepKeywords = $this->getTranslatedKeywords('Given|When|Then|And|But', $language); $backgroundKeywords = $this->getTranslatedKeywords('Background', $language); $examplesKeywords = $this->getTranslatedKeywords('Examples', $language); // Background $backgroundKeyword = $backgroundKeywords[0]; $background = new Node\BackgroundNode(null, ++$lineNum); $background->setKeyword($backgroundKeyword); $feature->setBackground($background); $gherkin .= "\n{$backgroundKeyword}:"; foreach ($stepKeywords as $stepNum => $stepKeyword) { $step = new Node\StepNode($stepKeyword, $text = "text of the step N{$stepNum}", ++$lineNum); $background->addStep($step); $gherkin .= "\n{$stepKeyword} {$text}"; } // Scenarios foreach ($this->getTranslatedKeywords('Scenario', $language) as $scenarioNum => $scenarioKeyword) { $scenario = new Node\ScenarioNode($title = "title of the scenario N{$scenarioNum}", ++$lineNum); $scenario->setKeyword($scenarioKeyword); $feature->addScenario($scenario); $gherkin .= "\n{$scenarioKeyword}: {$title}"; foreach ($stepKeywords as $stepNum => $stepKeyword) { $step = new Node\StepNode($stepKeyword, $text = "text of the step N{$stepNum}", ++$lineNum); $scenario->addStep($step); $gherkin .= "\n{$stepKeyword} {$text}"; } } // Scenario Outlines foreach ($this->getTranslatedKeywords('Scenario Outline', $language) as $outlineNum => $outlineKeyword) { $outline = new Node\OutlineNode($title = "title of the outline N{$outlineNum}", ++$lineNum); $outline->setKeyword($outlineKeyword); $feature->addScenario($outline); $gherkin .= "\n{$outlineKeyword}: {$title}"; $stepKeyword = $stepKeywords[0]; $step = new Node\StepNode($stepKeyword, $text = "text of the step <num>", ++$lineNum); $outline->addStep($step); $gherkin .= "\n{$stepKeyword} {$text}"; $examplesKeyword = $examplesKeywords[0]; $examples = new Node\TableNode(); $examples->setKeyword($examplesKeyword); $examples->addRow(array('num')); $examples->addRow(array(2)); $outline->setExamples($examples); $gherkin .= "\n{$examplesKeyword}:"; $gherkin .= "\n | num |"; $gherkin .= "\n | 2 |"; $lineNum += 3; } $etalon[] = $feature; $features[] = $this->getParser()->parse($gherkin); } $data[] = array($language, $etalon, $features); } return $data; }
public function translationTestDataProvider() { $keywords = $this->getKeywords(); $lexer = new Lexer($keywords); $parser = new Parser($lexer); $dumper = new KeywordsDumper($keywords); $data = array(); foreach ($this->getKeywordsArray() as $lang => $i18nKeywords) { $features = array(); foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) { $line = 1; if ('en' !== $lang) { $line = 2; } $feature = new Node\FeatureNode('Internal operations', <<<DESC In order to stay secret As a secret organization We need to be able to erase past agents' memory DESC , $lang . '_' . ($transNum + 1) . '.feature', $line); $feature->setLanguage($lang); $feature->setKeyword($featureKeyword); $line += 5; $background = new Node\BackgroundNode(null, $line); $keywords = explode('|', $i18nKeywords['background']); $background->setKeyword($keywords[0]); $line += 1; $line = $this->addSteps($background, $i18nKeywords['given'], 'there is agent A', $line); $line = $this->addSteps($background, $i18nKeywords['and'], 'there is agent B', $line); $feature->setBackground($background); $line += 1; foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) { $scenario = new Node\ScenarioNode('Erasing agent memory', $line); $scenario->setKeyword($scenarioKeyword); $line += 1; $line = $this->addSteps($scenario, $i18nKeywords['given'], 'there is agent J', $line); $line = $this->addSteps($scenario, $i18nKeywords['and'], 'there is agent K', $line); $line = $this->addSteps($scenario, $i18nKeywords['when'], 'I erase agent K\'s memory', $line); $line = $this->addSteps($scenario, $i18nKeywords['then'], 'there should be agent J', $line); $line = $this->addSteps($scenario, $i18nKeywords['but'], 'there should not be agent K', $line); $feature->addScenario($scenario); $line += 1; } foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) { $outline = new Node\OutlineNode('Erasing other agents\' memory', $line); $outline->setKeyword($outlineKeyword); $line += 1; $line = $this->addSteps($outline, $i18nKeywords['given'], 'there is agent <agent1>', $line); $line = $this->addSteps($outline, $i18nKeywords['and'], 'there is agent <agent2>', $line); $line = $this->addSteps($outline, $i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line); $line = $this->addSteps($outline, $i18nKeywords['then'], 'there should be agent <agent1>', $line); $line = $this->addSteps($outline, $i18nKeywords['but'], 'there should not be agent <agent2>', $line); $line += 1; $outline->setExamples($examples = new Node\TableNode(<<<TABLE | agent1 | agent2 | | D | M | TABLE )); $keywords = explode('|', $i18nKeywords['examples']); $examples->setKeyword($keywords[0]); $line += 3; $feature->addScenario($outline); $line += 1; } $features[] = $feature; } $dumped = $dumper->dump($lang, false); $parsed = array(); try { foreach ($dumped as $num => $dumpedFeature) { $parsed[] = $parser->parse($dumpedFeature, $lang . '_' . ($num + 1) . '.feature'); } } catch (\Exception $e) { throw new \Exception($e->getMessage() . ":\n" . $dumped, 0, $e); } $data[] = array($lang, $features, $parsed); } return $data; }