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
87
88
89
90
91
92
93
94
95
<?php
use Codeception\Util\Stub;
require_once __DIR__ . '/TestsForWeb.php';
/**
* @group appveyor
*/
class FrameworksTest extends TestsForWeb
{
/**
* @var \Codeception\Lib\Framework
*/
protected $module;
public function setUp()
{
$this->module = new \Codeception\Module\UniversalFramework(make_container());
}
public function testHttpAuth()
{
$this->module->amOnPage('/auth');
$this->module->see('Unauthorized');
$this->module->amHttpAuthenticated('davert', 'password');
$this->module->amOnPage('/auth');
$this->module->dontSee('Unauthorized');
$this->module->see("Welcome, davert");
$this->module->amHttpAuthenticated('davert', '123456');
$this->module->amOnPage('/auth');
$this->module->see('Forbidden');
}
public function testExceptionIsThrownOnRedirectToExternalUrl()
{
$this->setExpectedException('\Codeception\Exception\ExternalUrlException');
$this->module->amOnPage('/external_url');
$this->module->click('Next');
}
public function testMoveBackOneStep()
{
$this->module->amOnPage('/iframe');
$this->module->switchToIframe('content');
$this->module->seeCurrentUrlEquals('/info');
$this->module->click('Ссылочка');
$this->module->seeCurrentUrlEquals('/');
$this->module->moveBack();
$this->module->seeCurrentUrlEquals('/info');
$this->module->click('Sign in!');
$this->module->seeCurrentUrlEquals('/login');
}
public function testMoveBackTwoSteps()
{
$this->module->amOnPage('/iframe');
$this->module->switchToIframe('content');
$this->module->seeCurrentUrlEquals('/info');
$this->module->click('Ссылочка');
$this->module->seeCurrentUrlEquals('/');
$this->module->moveBack(2);
$this->module->seeCurrentUrlEquals('/iframe');
}
public function testMoveBackThrowsExceptionIfNumberOfStepsIsInvalid()
{
$this->module->amOnPage('/iframe');
$this->module->switchToIframe('content');
$this->module->seeCurrentUrlEquals('/info');
$this->module->click('Ссылочка');
$this->module->seeCurrentUrlEquals('/');
$invalidValues = [0, -5, 1.5, 'a', 3];
foreach ($invalidValues as $invalidValue) {
try {
$this->module->moveBack($invalidValue);
$this->fail('Expected to get exception here');
} catch (\InvalidArgumentException $e) {
codecept_debug('Exception: ' . $e->getMessage());
}
}
}
public function testCreateSnapshotOnFail()
{
$module = Stub::construct(get_class($this->module), [make_container()], [
'_savePageSource' => \Codeception\Stub\Expected::once(function ($filename) {
$this->assertEquals(codecept_log_dir('Codeception.Module.UniversalFramework.looks.like..test.fail.html'), $filename);
}),
]);
$module->amOnPage('/');
$cest = new \Codeception\Test\Cest($this->module, 'looks:like::test', 'demo1Cest.php');
$module->_failed($cest, new \PHPUnit\Framework\AssertionFailedError());
}
}