This commit is contained in:
2020-10-06 14:27:47 +07:00
commit 586be80cf6
16613 changed files with 3274099 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
<?php
namespace Tests\Behat\Gherkin\Node;
use Behat\Gherkin\Node\ExampleTableNode;
use Behat\Gherkin\Node\OutlineNode;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\StepNode;
use Behat\Gherkin\Node\TableNode;
class ExampleNodeTest extends \PHPUnit_Framework_TestCase
{
public function testCreateExampleSteps()
{
$steps = array(
$step1 = new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
$step2 = new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
$step3 = new StepNode('Blimey!', 'I open homepage', array(), null, 'When'),
$step4 = new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'),
);
$table = new ExampleTableNode(array(
array('name', 'email'),
array('everzet', 'ever.zet@gmail.com'),
array('example', 'example@example.com')
), 'Examples');
$outline = new OutlineNode(null, array(), $steps, $table, null, null);
$examples = $outline->getExamples();
$this->assertCount(4, $steps = $examples[0]->getSteps());
$this->assertEquals('Gangway!', $steps[0]->getType());
$this->assertEquals('Gangway!', $steps[0]->getKeyword());
$this->assertEquals('Given', $steps[0]->getKeywordType());
$this->assertEquals('I am everzet', $steps[0]->getText());
$this->assertEquals('Aye!', $steps[1]->getType());
$this->assertEquals('Aye!', $steps[1]->getKeyword());
$this->assertEquals('And', $steps[1]->getKeywordType());
$this->assertEquals('my email is ever.zet@gmail.com', $steps[1]->getText());
$this->assertEquals('Blimey!', $steps[2]->getType());
$this->assertEquals('Blimey!', $steps[2]->getKeyword());
$this->assertEquals('When', $steps[2]->getKeywordType());
$this->assertEquals('I open homepage', $steps[2]->getText());
$this->assertCount(4, $steps = $examples[1]->getSteps());
$this->assertEquals('Gangway!', $steps[0]->getType());
$this->assertEquals('Gangway!', $steps[0]->getKeyword());
$this->assertEquals('Given', $steps[0]->getKeywordType());
$this->assertEquals('I am example', $steps[0]->getText());
$this->assertEquals('Aye!', $steps[1]->getType());
$this->assertEquals('Aye!', $steps[1]->getKeyword());
$this->assertEquals('And', $steps[1]->getKeywordType());
$this->assertEquals('my email is example@example.com', $steps[1]->getText());
$this->assertEquals('Blimey!', $steps[2]->getType());
$this->assertEquals('Blimey!', $steps[2]->getKeyword());
$this->assertEquals('When', $steps[2]->getKeywordType());
$this->assertEquals('I open homepage', $steps[2]->getText());
}
public function testCreateExampleStepsWithArguments()
{
$steps = array(
$step1 = new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
$step2 = new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
$step3 = new StepNode('Blimey!', 'I open:', array(
new PyStringNode(array('page: <url>'), null)
), null, 'When'),
$step4 = new StepNode('Let go and haul', 'website should recognise me', array(
new TableNode(array(array('page', '<url>')))
), null, 'Then'),
);
$table = new ExampleTableNode(array(
array('name', 'email', 'url'),
array('everzet', 'ever.zet@gmail.com', 'homepage'),
array('example', 'example@example.com', 'other page')
), 'Examples');
$outline = new OutlineNode(null, array(), $steps, $table, null, null);
$examples = $outline->getExamples();
$steps = $examples[0]->getSteps();
$args = $steps[2]->getArguments();
$this->assertEquals('page: homepage', $args[0]->getRaw());
$args = $steps[3]->getArguments();
$this->assertEquals('| page | homepage |', $args[0]->getTableAsString());
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Tests\Behat\Gherkin\Node;
use Behat\Gherkin\Node\ExampleTableNode;
use Behat\Gherkin\Node\OutlineNode;
use Behat\Gherkin\Node\StepNode;
class OutlineNodeTest extends \PHPUnit_Framework_TestCase
{
public function testCreatesExamplesForExampleTable()
{
$steps = array(
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'),
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'),
);
$table = new ExampleTableNode(array(
array('name', 'email'),
array('everzet', 'ever.zet@gmail.com'),
array('example', 'example@example.com')
), 'Examples');
$outline = new OutlineNode(null, array(), $steps, $table, null, null);
$this->assertCount(2, $examples = $outline->getExamples());
$this->assertEquals(1, $examples[0]->getLine());
$this->assertEquals(2, $examples[1]->getLine());
$this->assertEquals(array('name' => 'everzet', 'email' => 'ever.zet@gmail.com'), $examples[0]->getTokens());
$this->assertEquals(array('name' => 'example', 'email' => 'example@example.com'), $examples[1]->getTokens());
}
public function testCreatesEmptyExamplesForEmptyExampleTable()
{
$steps = array(
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'),
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'),
);
$table = new ExampleTableNode(array(
array('name', 'email')
), 'Examples');
$outline = new OutlineNode(null, array(), $steps, $table, null, null);
$this->assertCount(0, $examples = $outline->getExamples());
}
public function testCreatesEmptyExamplesForNoExampleTable()
{
$steps = array(
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'),
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'),
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'),
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'),
);
$table = new ExampleTableNode(array(), 'Examples');
$outline = new OutlineNode(null, array(), $steps, $table, null, null);
$this->assertCount(0, $examples = $outline->getExamples());
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Tests\Behat\Gherkin\Node;
use Behat\Gherkin\Node\PyStringNode;
class PyStringNodeTest extends \PHPUnit_Framework_TestCase
{
public function testGetStrings()
{
$str = new PyStringNode(array('line1', 'line2', 'line3'), 0);
$this->assertEquals(array('line1', 'line2', 'line3'), $str->getStrings());
}
public function testGetRaw()
{
$str = new PyStringNode(array('line1', 'line2', 'line3'), 0);
$expected = <<<STR
line1
line2
line3
STR;
$this->assertEquals($expected, $str->getRaw());
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Tests\Behat\Gherkin\Node;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\StepNode;
use Behat\Gherkin\Node\TableNode;
class StepNodeTest extends \PHPUnit_Framework_TestCase
{
public function testThatStepCanHaveOnlyOneArgument()
{
$this->setExpectedException('Behat\Gherkin\Exception\NodeException');
new StepNode('Gangway!', 'I am on the page:', array(
new PyStringNode(array('one', 'two'), 11),
new TableNode(array(array('one', 'two'))),
), 10, 'Given');
}
}

View File

@@ -0,0 +1,269 @@
<?php
namespace Tests\Behat\Gherkin\Node;
use Behat\Gherkin\Node\TableNode;
class TableNodeTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Behat\Gherkin\Exception\NodeException
*/
public function testConstructorExpectsSameNumberOfColumnsInEachRow()
{
new TableNode(array(
array('username', 'password'),
array('everzet'),
array('antono', 'pa$sword')
));
}
public function constructorTestDataProvider() {
return array(
'One-dimensional array' => array(
array('everzet', 'antono')
),
'Three-dimensional array' => array(
array(array(array('everzet', 'antono')))
)
);
}
/**
* @dataProvider constructorTestDataProvider
* @expectedException \Behat\Gherkin\Exception\NodeException
* @expectedExceptionMessage Table is not two-dimensional.
*/
public function testConstructorExpectsTwoDimensionalArrays($table)
{
new TableNode($table);
}
public function testHashTable()
{
$table = new TableNode(array(
array('username', 'password'),
array('everzet', 'qwerty'),
array('antono', 'pa$sword')
));
$this->assertEquals(
array(
array('username' => 'everzet', 'password' => 'qwerty')
, array('username' => 'antono', 'password' => 'pa$sword')
),
$table->getHash()
);
$table = new TableNode(array(
array('username', 'password'),
array('', 'qwerty'),
array('antono', ''),
array('', '')
));
$this->assertEquals(
array(
array('username' => '', 'password' => 'qwerty'),
array('username' => 'antono', 'password' => ''),
array('username' => '', 'password' => ''),
),
$table->getHash()
);
}
public function testIterator()
{
$table = new TableNode(array(
array('username', 'password'),
array('', 'qwerty'),
array('antono', ''),
array('', ''),
));
$this->assertEquals(
array(
array('username' => '', 'password' => 'qwerty'),
array('username' => 'antono', 'password' => ''),
array('username' => '', 'password' => ''),
),
iterator_to_array($table)
);
}
public function testRowsHashTable()
{
$table = new TableNode(array(
array('username', 'everzet'),
array('password', 'qwerty'),
array('uid', '35'),
));
$this->assertEquals(
array('username' => 'everzet', 'password' => 'qwerty', 'uid' => '35'),
$table->getRowsHash()
);
}
public function testLongRowsHashTable()
{
$table = new TableNode(array(
array('username', 'everzet', 'marcello'),
array('password', 'qwerty', '12345'),
array('uid', '35', '22')
));
$this->assertEquals(array(
'username' => array('everzet', 'marcello'),
'password' => array('qwerty', '12345'),
'uid' => array('35', '22')
), $table->getRowsHash());
}
public function testGetRows()
{
$table = new TableNode(array(
array('username', 'password'),
array('everzet', 'qwerty'),
array('antono', 'pa$sword')
));
$this->assertEquals(array(
array('username', 'password'),
array('everzet', 'qwerty'),
array('antono', 'pa$sword')
), $table->getRows());
}
public function testGetLines()
{
$table = new TableNode(array(
5 => array('username', 'password'),
10 => array('everzet', 'qwerty'),
13 => array('antono', 'pa$sword')
));
$this->assertEquals(array(5, 10, 13), $table->getLines());
}
public function testGetRow()
{
$table = new TableNode(array(
array('username', 'password'),
array('everzet', 'qwerty'),
array('antono', 'pa$sword')
));
$this->assertEquals(array('username', 'password'), $table->getRow(0));
$this->assertEquals(array('antono', 'pa$sword'), $table->getRow(2));
}
public function testGetColumn()
{
$table = new TableNode(array(
array('username', 'password'),
array('everzet', 'qwerty'),
array('antono', 'pa$sword')
));
$this->assertEquals(array('username', 'everzet', 'antono'), $table->getColumn(0));
$this->assertEquals(array('password', 'qwerty', 'pa$sword'), $table->getColumn(1));
$table = new TableNode(array(
array('username'),
array('everzet'),
array('antono')
));
$this->assertEquals(array('username', 'everzet', 'antono'), $table->getColumn(0));
}
public function testGetRowWithLineNumbers()
{
$table = new TableNode(array(
5 => array('username', 'password'),
10 => array('everzet', 'qwerty'),
13 => array('antono', 'pa$sword')
));
$this->assertEquals(array('username', 'password'), $table->getRow(0));
$this->assertEquals(array('antono', 'pa$sword'), $table->getRow(2));
}
public function testGetTable()
{
$table = new TableNode($a = array(
5 => array('username', 'password'),
10 => array('everzet', 'qwerty'),
13 => array('antono', 'pa$sword')
));
$this->assertEquals($a, $table->getTable());
}
public function testGetRowLine()
{
$table = new TableNode(array(
5 => array('username', 'password'),
10 => array('everzet', 'qwerty'),
13 => array('antono', 'pa$sword')
));
$this->assertEquals(5, $table->getRowLine(0));
$this->assertEquals(13, $table->getRowLine(2));
}
public function testGetRowAsString()
{
$table = new TableNode(array(
5 => array('username', 'password'),
10 => array('everzet', 'qwerty'),
13 => array('antono', 'pa$sword')
));
$this->assertEquals('| username | password |', $table->getRowAsString(0));
$this->assertEquals('| antono | pa$sword |', $table->getRowAsString(2));
}
public function testGetTableAsString()
{
$table = new TableNode(array(
5 => array('id', 'username', 'password'),
10 => array('42', 'everzet', 'qwerty'),
13 => array('2', 'antono', 'pa$sword')
));
$expected = <<<TABLE
| id | username | password |
| 42 | everzet | qwerty |
| 2 | antono | pa\$sword |
TABLE;
$this->assertEquals($expected, $table->getTableAsString());
}
public function testFromList()
{
$table = TableNode::fromList(array(
'everzet',
'antono'
));
$expected = new TableNode(array(
array('everzet'),
array('antono'),
));
$this->assertEquals($expected, $table);
}
/**
* @expectedException \Behat\Gherkin\Exception\NodeException
*/
public function testGetTableFromListWithMultidimensionalArrayArgument()
{
TableNode::fromList(array(
array(1, 2, 3),
array(4, 5, 6)
));
}
}