Html5Test.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Form;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class Html5Test extends TestCase
  5. {
  6. public function testHtml5FormInputAttribute()
  7. {
  8. $this->getSession()->visit($this->pathTo('/html5_form.html'));
  9. $page = $this->getSession()->getPage();
  10. $webAssert = $this->getAssertSession();
  11. $firstName = $webAssert->fieldExists('first_name');
  12. $lastName = $webAssert->fieldExists('last_name');
  13. $this->assertEquals('not set', $lastName->getValue());
  14. $firstName->setValue('John');
  15. $lastName->setValue('Doe');
  16. $this->assertEquals('Doe', $lastName->getValue());
  17. $page->pressButton('Submit in form');
  18. if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
  19. $out = <<<OUT
  20. 'first_name' = 'John',
  21. 'last_name' = 'Doe',
  22. OUT;
  23. $this->assertContains($out, $page->getContent());
  24. $this->assertNotContains('other_field', $page->getContent());
  25. }
  26. }
  27. public function testHtml5FormRadioAttribute()
  28. {
  29. $this->getSession()->visit($this->pathTo('html5_radio.html'));
  30. $page = $this->getSession()->getPage();
  31. $radio = $this->findById('sex_f');
  32. $otherRadio = $this->findById('sex_invalid');
  33. $this->assertEquals('f', $radio->getValue());
  34. $this->assertEquals('invalid', $otherRadio->getValue());
  35. $radio->selectOption('m');
  36. $this->assertEquals('m', $radio->getValue());
  37. $this->assertEquals('invalid', $otherRadio->getValue());
  38. $page->pressButton('Submit in form');
  39. $out = <<<OUT
  40. 'sex' = 'm',
  41. OUT;
  42. $this->assertContains($out, $page->getContent());
  43. }
  44. public function testHtml5FormButtonAttribute()
  45. {
  46. $this->getSession()->visit($this->pathTo('/html5_form.html'));
  47. $page = $this->getSession()->getPage();
  48. $webAssert = $this->getAssertSession();
  49. $firstName = $webAssert->fieldExists('first_name');
  50. $lastName = $webAssert->fieldExists('last_name');
  51. $firstName->setValue('John');
  52. $lastName->setValue('Doe');
  53. $page->pressButton('Submit outside form');
  54. if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
  55. $out = <<<OUT
  56. 'first_name' = 'John',
  57. 'last_name' = 'Doe',
  58. 'submit_button' = 'test',
  59. OUT;
  60. $this->assertContains($out, $page->getContent());
  61. }
  62. }
  63. public function testHtml5FormOutside()
  64. {
  65. $this->getSession()->visit($this->pathTo('/html5_form.html'));
  66. $page = $this->getSession()->getPage();
  67. $page->fillField('other_field', 'hello');
  68. $page->pressButton('Submit separate form');
  69. if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
  70. $out = <<<OUT
  71. 'other_field' = 'hello',
  72. OUT;
  73. $this->assertContains($out, $page->getContent());
  74. $this->assertNotContains('first_name', $page->getContent());
  75. }
  76. }
  77. public function testHtml5Types()
  78. {
  79. $this->getSession()->visit($this->pathTo('html5_types.html'));
  80. $page = $this->getSession()->getPage();
  81. $page->fillField('url', 'http://mink.behat.org/');
  82. $page->fillField('email', 'mink@example.org');
  83. $page->fillField('number', '6');
  84. $page->fillField('search', 'mink');
  85. $page->fillField('date', '2014-05-19');
  86. $page->fillField('color', '#ff00aa');
  87. $page->pressButton('Submit');
  88. $out = <<<OUT
  89. 'color' = '#ff00aa',
  90. 'date' = '2014-05-19',
  91. 'email' = 'mink@example.org',
  92. 'number' = '6',
  93. 'search' = 'mink',
  94. 'submit_button' = 'Submit',
  95. 'url' = 'http://mink.behat.org/',
  96. OUT;
  97. $this->assertContains($out, $page->getContent());
  98. }
  99. }