ExampleNodeTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Tests\Behat\Gherkin\Node;
  3. use Behat\Gherkin\Node\ExampleTableNode;
  4. use Behat\Gherkin\Node\OutlineNode;
  5. use Behat\Gherkin\Node\PyStringNode;
  6. use Behat\Gherkin\Node\StepNode;
  7. use Behat\Gherkin\Node\TableNode;
  8. class ExampleNodeTest extends \PHPUnit_Framework_TestCase
  9. {
  10. public function testCreateExampleSteps()
  11. {
  12. $steps = array(
  13. $step1 = new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
  14. $step2 = new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
  15. $step3 = new StepNode('Blimey!', 'I open homepage', array(), null, 'When'),
  16. $step4 = new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'),
  17. );
  18. $table = new ExampleTableNode(array(
  19. array('name', 'email'),
  20. array('everzet', 'ever.zet@gmail.com'),
  21. array('example', 'example@example.com')
  22. ), 'Examples');
  23. $outline = new OutlineNode(null, array(), $steps, $table, null, null);
  24. $examples = $outline->getExamples();
  25. $this->assertCount(4, $steps = $examples[0]->getSteps());
  26. $this->assertEquals('Gangway!', $steps[0]->getType());
  27. $this->assertEquals('Gangway!', $steps[0]->getKeyword());
  28. $this->assertEquals('Given', $steps[0]->getKeywordType());
  29. $this->assertEquals('I am everzet', $steps[0]->getText());
  30. $this->assertEquals('Aye!', $steps[1]->getType());
  31. $this->assertEquals('Aye!', $steps[1]->getKeyword());
  32. $this->assertEquals('And', $steps[1]->getKeywordType());
  33. $this->assertEquals('my email is ever.zet@gmail.com', $steps[1]->getText());
  34. $this->assertEquals('Blimey!', $steps[2]->getType());
  35. $this->assertEquals('Blimey!', $steps[2]->getKeyword());
  36. $this->assertEquals('When', $steps[2]->getKeywordType());
  37. $this->assertEquals('I open homepage', $steps[2]->getText());
  38. $this->assertCount(4, $steps = $examples[1]->getSteps());
  39. $this->assertEquals('Gangway!', $steps[0]->getType());
  40. $this->assertEquals('Gangway!', $steps[0]->getKeyword());
  41. $this->assertEquals('Given', $steps[0]->getKeywordType());
  42. $this->assertEquals('I am example', $steps[0]->getText());
  43. $this->assertEquals('Aye!', $steps[1]->getType());
  44. $this->assertEquals('Aye!', $steps[1]->getKeyword());
  45. $this->assertEquals('And', $steps[1]->getKeywordType());
  46. $this->assertEquals('my email is example@example.com', $steps[1]->getText());
  47. $this->assertEquals('Blimey!', $steps[2]->getType());
  48. $this->assertEquals('Blimey!', $steps[2]->getKeyword());
  49. $this->assertEquals('When', $steps[2]->getKeywordType());
  50. $this->assertEquals('I open homepage', $steps[2]->getText());
  51. }
  52. public function testCreateExampleStepsWithArguments()
  53. {
  54. $steps = array(
  55. $step1 = new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
  56. $step2 = new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
  57. $step3 = new StepNode('Blimey!', 'I open:', array(
  58. new PyStringNode(array('page: <url>'), null)
  59. ), null, 'When'),
  60. $step4 = new StepNode('Let go and haul', 'website should recognise me', array(
  61. new TableNode(array(array('page', '<url>')))
  62. ), null, 'Then'),
  63. );
  64. $table = new ExampleTableNode(array(
  65. array('name', 'email', 'url'),
  66. array('everzet', 'ever.zet@gmail.com', 'homepage'),
  67. array('example', 'example@example.com', 'other page')
  68. ), 'Examples');
  69. $outline = new OutlineNode(null, array(), $steps, $table, null, null);
  70. $examples = $outline->getExamples();
  71. $steps = $examples[0]->getSteps();
  72. $args = $steps[2]->getArguments();
  73. $this->assertEquals('page: homepage', $args[0]->getRaw());
  74. $args = $steps[3]->getArguments();
  75. $this->assertEquals('| page | homepage |', $args[0]->getTableAsString());
  76. }
  77. }