Repository navigation
Expand file tree
/
Copy pathStepTest.php
More file actions
86 lines (69 loc) · 3.2 KB
/
Copy pathStepTest.php
File metadata and controls
86 lines (69 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
use Facebook\WebDriver\WebDriverBy;
use Codeception\Util\Locator;
class StepTest extends \PHPUnit_Framework_TestCase
{
/**
* @param $args
* @return Codeception\Step
*/
protected function getStep($args)
{
return $this->getMockBuilder('\Codeception\Step')->setConstructorArgs($args)->setMethods(null)->getMock();
}
public function testGetArguments()
{
$by = WebDriverBy::cssSelector('.something');
$step = $this->getStep([null, [$by]]);
$this->assertEquals('"' . Locator::humanReadableString($by) . '"', $step->getArgumentsAsString());
$step = $this->getStep([null, [['just', 'array']]]);
$this->assertEquals('["just","array"]', $step->getArgumentsAsString());
$step = $this->getStep([null, [function(){}]]);
$this->assertEquals('"Closure"', $step->getArgumentsAsString());
$step = $this->getStep([null, [[$this, 'testGetArguments']]]);
$this->assertEquals('["StepTest","testGetArguments"]', $step->getArgumentsAsString());
$step = $this->getStep([null, [['PDO', 'getAvailableDrivers']]]);
$this->assertEquals('["PDO","getAvailableDrivers"]', $step->getArgumentsAsString());
}
public function testGetHtml()
{
$step = $this->getStep(['Do some testing', ['arg1', 'arg2']]);
$this->assertSame('I do some testing <span style="color: #732E81">"arg1","arg2"</span>', $step->getHtml());
$step = $this->getStep(['Do some testing', []]);
$this->assertSame('I do some testing', $step->getHtml());
}
public function testLongArguments()
{
$step = $this->getStep(['have in database', [str_repeat('a', 2000)]]);
$output = $step->toString(200);
$this->assertLessThan(201, strlen($output), 'Output is too long: ' . $output);
$step = $this->getStep(['have in database', [str_repeat('a', 100), str_repeat('b', 100)]]);
$output = $step->toString(50);
$this->assertEquals(50, strlen($output), 'Incorrect length of output: ' . $output);
$this->assertEquals('have in database "aaaaaaaaaaa...","bbbbbbbbbbb..."', $output);
$step = $this->getStep(['have in database', [1, str_repeat('b', 100)]]);
$output = $step->toString(50);
$this->assertEquals('have in database 1,"bbbbbbbbbbbbbbbbbbbbbbbbbb..."', $output);
$step = $this->getStep(['have in database', [str_repeat('b', 100), 1]]);
$output = $step->toString(50);
$this->assertEquals('have in database "bbbbbbbbbbbbbbbbbbbbbbbbbb...",1', $output);
}
public function testArrayAsArgument()
{
$step = $this->getStep(['see array', [[1,2,3], 'two']]);
$output = $step->toString(200);
$this->assertEquals('see array [1,2,3],"two"', $output);
}
public function testSingleQuotedStringAsArgument()
{
$step = $this->getStep(['see array', [[1,2,3], "'two'"]]);
$output = $step->toString(200);
$this->assertEquals('see array [1,2,3],"\'two\'"', $output);
}
public function testSeeUppercaseText()
{
$step = $this->getStep(['see', ['UPPER CASE']]);
$output = $step->toString(200);
$this->assertEquals('see "UPPER CASE"', $output);
}
}