FrameworksTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. use Codeception\Util\Stub;
  3. require_once __DIR__ . '/TestsForWeb.php';
  4. /**
  5. * @group appveyor
  6. */
  7. class FrameworksTest extends TestsForWeb
  8. {
  9. /**
  10. * @var \Codeception\Lib\Framework
  11. */
  12. protected $module;
  13. public function setUp()
  14. {
  15. $this->module = new \Codeception\Module\UniversalFramework(make_container());
  16. }
  17. public function testHttpAuth()
  18. {
  19. $this->module->amOnPage('/auth');
  20. $this->module->see('Unauthorized');
  21. $this->module->amHttpAuthenticated('davert', 'password');
  22. $this->module->amOnPage('/auth');
  23. $this->module->dontSee('Unauthorized');
  24. $this->module->see("Welcome, davert");
  25. $this->module->amHttpAuthenticated('davert', '123456');
  26. $this->module->amOnPage('/auth');
  27. $this->module->see('Forbidden');
  28. }
  29. public function testExceptionIsThrownOnRedirectToExternalUrl()
  30. {
  31. $this->setExpectedException('\Codeception\Exception\ExternalUrlException');
  32. $this->module->amOnPage('/external_url');
  33. $this->module->click('Next');
  34. }
  35. public function testMoveBackOneStep()
  36. {
  37. $this->module->amOnPage('/iframe');
  38. $this->module->switchToIframe('content');
  39. $this->module->seeCurrentUrlEquals('/info');
  40. $this->module->click('Ссылочка');
  41. $this->module->seeCurrentUrlEquals('/');
  42. $this->module->moveBack();
  43. $this->module->seeCurrentUrlEquals('/info');
  44. $this->module->click('Sign in!');
  45. $this->module->seeCurrentUrlEquals('/login');
  46. }
  47. public function testMoveBackTwoSteps()
  48. {
  49. $this->module->amOnPage('/iframe');
  50. $this->module->switchToIframe('content');
  51. $this->module->seeCurrentUrlEquals('/info');
  52. $this->module->click('Ссылочка');
  53. $this->module->seeCurrentUrlEquals('/');
  54. $this->module->moveBack(2);
  55. $this->module->seeCurrentUrlEquals('/iframe');
  56. }
  57. public function testMoveBackThrowsExceptionIfNumberOfStepsIsInvalid()
  58. {
  59. $this->module->amOnPage('/iframe');
  60. $this->module->switchToIframe('content');
  61. $this->module->seeCurrentUrlEquals('/info');
  62. $this->module->click('Ссылочка');
  63. $this->module->seeCurrentUrlEquals('/');
  64. $invalidValues = [0, -5, 1.5, 'a', 3];
  65. foreach ($invalidValues as $invalidValue) {
  66. try {
  67. $this->module->moveBack($invalidValue);
  68. $this->fail('Expected to get exception here');
  69. } catch (\InvalidArgumentException $e) {
  70. codecept_debug('Exception: ' . $e->getMessage());
  71. }
  72. }
  73. }
  74. public function testCreateSnapshotOnFail()
  75. {
  76. $module = Stub::construct(get_class($this->module), [make_container()], [
  77. '_savePageSource' => Stub::once(function ($filename) {
  78. $this->assertEquals(codecept_log_dir('Codeception.Module.UniversalFramework.looks.like..test.fail.html'), $filename);
  79. }),
  80. ]);
  81. $module->amOnPage('/');
  82. $cest = new \Codeception\Test\Cest($this->module, 'looks:like::test', 'demo1Cest.php');
  83. $module->_failed($cest, new PHPUnit_Framework_AssertionFailedError());
  84. }
  85. }