ContentTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Basic;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class ContentTest extends TestCase
  5. {
  6. public function testOuterHtml()
  7. {
  8. $this->getSession()->visit($this->pathTo('/index.html'));
  9. $element = $this->getAssertSession()->elementExists('css', '.travers');
  10. $this->assertEquals(
  11. "<div class=\"travers\">\n <div class=\"sub\">el1</div>\n".
  12. " <div class=\"sub\">el2</div>\n <div class=\"sub\">\n".
  13. " <a href=\"some_url\">some <strong>deep</strong> url</a>\n".
  14. " </div>\n </div>",
  15. $element->getOuterHtml()
  16. );
  17. }
  18. public function testDumpingEmptyElements()
  19. {
  20. $this->getSession()->visit($this->pathTo('/index.html'));
  21. $element = $this->getAssertSession()->elementExists('css', '#empty');
  22. $this->assertEquals(
  23. 'An empty <em></em> tag should be rendered with both open and close tags.',
  24. trim($element->getHtml())
  25. );
  26. }
  27. /**
  28. * @dataProvider getAttributeDataProvider
  29. */
  30. public function testGetAttribute($attributeName, $attributeValue)
  31. {
  32. $this->getSession()->visit($this->pathTo('/index.html'));
  33. $element = $this->getSession()->getPage()->findById('attr-elem['.$attributeName.']');
  34. $this->assertNotNull($element);
  35. $this->assertSame($attributeValue, $element->getAttribute($attributeName));
  36. }
  37. public function getAttributeDataProvider()
  38. {
  39. return array(
  40. array('with-value', 'some-value'),
  41. array('without-value', ''),
  42. array('with-empty-value', ''),
  43. array('with-missing', null),
  44. );
  45. }
  46. public function testJson()
  47. {
  48. $this->getSession()->visit($this->pathTo('/json.php'));
  49. $this->assertContains(
  50. '{"key1":"val1","key2":234,"key3":[1,2,3]}',
  51. $this->getSession()->getPage()->getContent()
  52. );
  53. }
  54. public function testHtmlDecodingNotPerformed()
  55. {
  56. $session = $this->getSession();
  57. $webAssert = $this->getAssertSession();
  58. $session->visit($this->pathTo('/html_decoding.html'));
  59. $page = $session->getPage();
  60. $span = $webAssert->elementExists('css', 'span');
  61. $input = $webAssert->elementExists('css', 'input');
  62. $expectedHtml = '<span custom-attr="&amp;">some text</span>';
  63. $this->assertContains($expectedHtml, $page->getHtml(), '.innerHTML is returned as-is');
  64. $this->assertContains($expectedHtml, $page->getContent(), '.outerHTML is returned as-is');
  65. $this->assertEquals('&', $span->getAttribute('custom-attr'), '.getAttribute value is decoded');
  66. $this->assertEquals('&', $input->getAttribute('value'), '.getAttribute value is decoded');
  67. $this->assertEquals('&', $input->getValue(), 'node value is decoded');
  68. }
  69. }