Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request minkphp#561 from stof/webassert_usage
Browse files Browse the repository at this point in the history
Replaced most null safeguards in tests with usages of WebAssert
  • Loading branch information
stof committed May 19, 2014
2 parents 8d8b852 + 4f16fa0 commit 1f11bbd
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 151 deletions.
13 changes: 4 additions & 9 deletions driver-testsuite/tests/Basic/ContentTest.php
Expand Up @@ -10,10 +10,7 @@ public function testOuterHtml()
{ {
$this->getSession()->visit($this->pathTo('/index.html')); $this->getSession()->visit($this->pathTo('/index.html'));


$page = $this->getSession()->getPage(); $element = $this->getAssertSession()->elementExists('css', '.travers');
$element = $page->find('css', '.travers');

$this->assertNotNull($element);


$this->assertEquals( $this->assertEquals(
"<div class=\"travers\">\n <div class=\"sub\">el1</div>\n". "<div class=\"travers\">\n <div class=\"sub\">el1</div>\n".
Expand Down Expand Up @@ -59,14 +56,12 @@ public function testJson()
public function testHtmlDecodingNotPerformed() public function testHtmlDecodingNotPerformed()
{ {
$session = $this->getSession(); $session = $this->getSession();
$webAssert = $this->getAssertSession();
$session->visit($this->pathTo('/html_decoding.html')); $session->visit($this->pathTo('/html_decoding.html'));
$page = $session->getPage(); $page = $session->getPage();


$span = $page->find('css', 'span'); $span = $webAssert->elementExists('css', 'span');
$input = $page->find('css', 'input'); $input = $webAssert->elementExists('css', 'input');

$this->assertNotNull($span);
$this->assertNotNull($input);


$expectedHtml = '<span custom-attr="&amp;">some text</span>'; $expectedHtml = '<span custom-attr="&amp;">some text</span>';
$this->assertContains($expectedHtml, $page->getHtml(), '.innerHTML is returned as-is'); $this->assertContains($expectedHtml, $page->getHtml(), '.innerHTML is returned as-is');
Expand Down
9 changes: 5 additions & 4 deletions driver-testsuite/tests/Basic/CookieTest.php
Expand Up @@ -148,19 +148,20 @@ public function testHttpOnlyCookieIsDeleted()
public function testSessionPersistsBetweenRequests() public function testSessionPersistsBetweenRequests()
{ {
$this->getSession()->visit($this->pathTo('/session_test.php')); $this->getSession()->visit($this->pathTo('/session_test.php'));
$this->assertNotNull($node = $this->getSession()->getPage()->find('css', '#session-id')); $webAssert = $this->getAssertSession();
$node = $webAssert->elementExists('css', '#session-id');
$sessionId = $node->getText(); $sessionId = $node->getText();


$this->getSession()->visit($this->pathTo('/session_test.php')); $this->getSession()->visit($this->pathTo('/session_test.php'));
$this->assertNotNull($node = $this->getSession()->getPage()->find('css', '#session-id')); $node = $webAssert->elementExists('css', '#session-id');
$this->assertEquals($sessionId, $node->getText()); $this->assertEquals($sessionId, $node->getText());


$this->getSession()->visit($this->pathTo('/session_test.php?login')); $this->getSession()->visit($this->pathTo('/session_test.php?login'));
$this->assertNotNull($node = $this->getSession()->getPage()->find('css', '#session-id')); $node = $webAssert->elementExists('css', '#session-id');
$this->assertNotEquals($sessionId, $newSessionId = $node->getText()); $this->assertNotEquals($sessionId, $newSessionId = $node->getText());


$this->getSession()->visit($this->pathTo('/session_test.php')); $this->getSession()->visit($this->pathTo('/session_test.php'));
$this->assertNotNull($node = $this->getSession()->getPage()->find('css', '#session-id')); $node = $webAssert->elementExists('css', '#session-id');
$this->assertEquals($newSessionId, $node->getText()); $this->assertEquals($newSessionId, $node->getText());
} }
} }
11 changes: 4 additions & 7 deletions driver-testsuite/tests/Basic/IFrameTest.php
Expand Up @@ -9,22 +9,19 @@ class IFrameTest extends TestCase
public function testIFrame() public function testIFrame()
{ {
$this->getSession()->visit($this->pathTo('/iframe.html')); $this->getSession()->visit($this->pathTo('/iframe.html'));
$page = $this->getSession()->getPage(); $webAssert = $this->getAssertSession();


$el = $page->find('css', '#text'); $el = $webAssert->elementExists('css', '#text');
$this->assertNotNull($el);
$this->assertSame('Main window div text', $el->getText()); $this->assertSame('Main window div text', $el->getText());


$this->getSession()->switchToIFrame('subframe'); $this->getSession()->switchToIFrame('subframe');


$el = $page->find('css', '#text'); $el = $webAssert->elementExists('css', '#text');
$this->assertNotNull($el);
$this->assertSame('iFrame div text', $el->getText()); $this->assertSame('iFrame div text', $el->getText());


$this->getSession()->switchToIFrame(); $this->getSession()->switchToIFrame();


$el = $page->find('css', '#text'); $el = $webAssert->elementExists('css', '#text');
$this->assertNotNull($el);
$this->assertSame('Main window div text', $el->getText()); $this->assertSame('Main window div text', $el->getText());
} }
} }
8 changes: 3 additions & 5 deletions driver-testsuite/tests/Basic/VisibilityTest.php
Expand Up @@ -9,12 +9,10 @@ class VisibilityTest extends TestCase
public function testVisibility() public function testVisibility()
{ {
$this->getSession()->visit($this->pathTo('/js_test.html')); $this->getSession()->visit($this->pathTo('/js_test.html'));
$webAssert = $this->getAssertSession();


$clicker = $this->getSession()->getPage()->find('css', '.elements div#clicker'); $clicker = $webAssert->elementExists('css', '.elements div#clicker');
$invisible = $this->getSession()->getPage()->find('css', '#invisible'); $invisible = $webAssert->elementExists('css', '#invisible');

$this->assertNotNull($clicker);
$this->assertNotNull($invisible);


$this->assertFalse($invisible->isVisible()); $this->assertFalse($invisible->isVisible());
$this->assertTrue($clicker->isVisible()); $this->assertTrue($clicker->isVisible());
Expand Down
11 changes: 4 additions & 7 deletions driver-testsuite/tests/Form/CheckboxTest.php
Expand Up @@ -49,15 +49,12 @@ public function testSetValue()
public function testCheckboxMultiple() public function testCheckboxMultiple()
{ {
$this->getSession()->visit($this->pathTo('/multicheckbox_form.html')); $this->getSession()->visit($this->pathTo('/multicheckbox_form.html'));
$webAssert = $this->getAssertSession();


$page = $this->getSession()->getPage(); $this->assertEquals('Multicheckbox Test', $webAssert->elementExists('css', 'h1')->getText());
$this->assertEquals('Multicheckbox Test', $page->find('css', 'h1')->getText());


$updateMail = $page->find('css', '[name="mail_types[]"][value="update"]'); $updateMail = $webAssert->elementExists('css', '[name="mail_types[]"][value="update"]');
$spamMail = $page->find('css', '[name="mail_types[]"][value="spam"]'); $spamMail = $webAssert->elementExists('css', '[name="mail_types[]"][value="spam"]');

$this->assertNotNull($updateMail);
$this->assertNotNull($spamMail);


$this->assertTrue($updateMail->getValue()); $this->assertTrue($updateMail->getValue());
$this->assertFalse($spamMail->getValue()); $this->assertFalse($spamMail->getValue());
Expand Down
91 changes: 39 additions & 52 deletions driver-testsuite/tests/Form/GeneralTest.php
Expand Up @@ -23,14 +23,12 @@ public function testBasicForm()
{ {
$this->getSession()->visit($this->pathTo('/basic_form.html')); $this->getSession()->visit($this->pathTo('/basic_form.html'));


$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$this->assertEquals('Basic Form Page', $page->find('css', 'h1')->getText()); $this->assertEquals('Basic Form Page', $webAssert->elementExists('css', 'h1')->getText());


$firstname = $page->findField('first_name'); $firstname = $webAssert->fieldExists('first_name');
$lastname = $page->findField('lastn'); $lastname = $webAssert->fieldExists('lastn');

$this->assertNotNull($firstname);
$this->assertNotNull($lastname);


$this->assertEquals('Firstname', $firstname->getValue()); $this->assertEquals('Firstname', $firstname->getValue());
$this->assertEquals('Lastname', $lastname->getValue()); $this->assertEquals('Lastname', $lastname->getValue());
Expand All @@ -52,9 +50,9 @@ public function testBasicForm()
$page->findButton('Save')->click(); $page->findButton('Save')->click();


if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Anket for Konstantin', $page->find('css', 'h1')->getText()); $this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText());
$this->assertEquals('Firstname: Konstantin', $page->find('css', '#first')->getText()); $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
$this->assertEquals('Lastname: Kudryashov', $page->find('css', '#last')->getText()); $this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText());
} }
} }


Expand All @@ -66,15 +64,15 @@ public function testFormSubmitWays($submitVia)
$session = $this->getSession(); $session = $this->getSession();
$session->visit($this->pathTo('/basic_form.html')); $session->visit($this->pathTo('/basic_form.html'));
$page = $session->getPage(); $page = $session->getPage();
$webAssert = $this->getAssertSession();


$firstname = $page->findField('first_name'); $firstname = $webAssert->fieldExists('first_name');
$this->assertNotNull($firstname);
$firstname->setValue('Konstantin'); $firstname->setValue('Konstantin');


$page->findButton($submitVia)->click(); $page->findButton($submitVia)->click();


if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Firstname: Konstantin', $page->find('css', '#first')->getText()); $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
} else { } else {
$this->fail('Form was never submitted'); $this->fail('Form was never submitted');
} }
Expand All @@ -95,13 +93,13 @@ public function testFormSubmit()
$session = $this->getSession(); $session = $this->getSession();
$session->visit($this->pathTo('/basic_form.html')); $session->visit($this->pathTo('/basic_form.html'));


$page = $session->getPage(); $webAssert = $this->getAssertSession();
$page->findField('first_name')->setValue('Konstantin'); $webAssert->fieldExists('first_name')->setValue('Konstantin');


$page->find('xpath', 'descendant-or-self::form[1]')->submit(); $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();


if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Firstname: Konstantin', $page->find('css', '#first')->getText()); $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
}; };
} }


Expand All @@ -110,29 +108,29 @@ public function testFormSubmitWithoutButton()
$session = $this->getSession(); $session = $this->getSession();
$session->visit($this->pathTo('/form_without_button.html')); $session->visit($this->pathTo('/form_without_button.html'));


$page = $session->getPage(); $webAssert = $this->getAssertSession();
$page->findField('first_name')->setValue('Konstantin'); $webAssert->fieldExists('first_name')->setValue('Konstantin');


$page->find('xpath', 'descendant-or-self::form[1]')->submit(); $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();


if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) { if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
$this->assertEquals('Firstname: Konstantin', $page->find('css', '#first')->getText()); $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
}; };
} }


public function testBasicGetForm() public function testBasicGetForm()
{ {
$this->getSession()->visit($this->pathTo('/basic_get_form.php')); $this->getSession()->visit($this->pathTo('/basic_get_form.php'));
$webAssert = $this->getAssertSession();


$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$this->assertEquals('Basic Get Form Page', $page->find('css', 'h1')->getText()); $this->assertEquals('Basic Get Form Page', $webAssert->elementExists('css', 'h1')->getText());


$search = $page->findField('q'); $search = $webAssert->fieldExists('q');
$this->assertNotNull($search);
$search->setValue('some#query'); $search->setValue('some#query');
$page->pressButton('Find'); $page->pressButton('Find');


$this->assertNotNull($div = $page->find('css', 'div')); $div = $webAssert->elementExists('css', 'div');
$this->assertEquals('some#query', $div->getText()); $this->assertEquals('some#query', $div->getText());
} }


Expand All @@ -150,27 +148,19 @@ public function testAdvancedForm()


$this->getSession()->visit($this->pathTo('/advanced_form.html')); $this->getSession()->visit($this->pathTo('/advanced_form.html'));


$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$this->assertEquals('ADvanced Form Page', $page->find('css', 'h1')->getText()); $this->assertEquals('ADvanced Form Page', $webAssert->elementExists('css', 'h1')->getText());


$firstname = $page->findField('first_name'); $firstname = $webAssert->fieldExists('first_name');
$lastname = $page->findField('lastn'); $lastname = $webAssert->fieldExists('lastn');
$email = $page->findField('Your email:'); $email = $webAssert->fieldExists('Your email:');
$select = $page->findField('select_number'); $select = $webAssert->fieldExists('select_number');
$sex = $page->findField('sex'); $sex = $webAssert->fieldExists('sex');
$maillist = $page->findField('mail_list'); $maillist = $webAssert->fieldExists('mail_list');
$agreement = $page->findField('agreement'); $agreement = $webAssert->fieldExists('agreement');
$notes = $page->findField('notes'); $notes = $webAssert->fieldExists('notes');
$about = $page->findField('about'); $about = $webAssert->fieldExists('about');

$this->assertNotNull($firstname);
$this->assertNotNull($lastname);
$this->assertNotNull($email);
$this->assertNotNull($select);
$this->assertNotNull($sex);
$this->assertNotNull($maillist);
$this->assertNotNull($agreement);
$this->assertNotNull($notes);


$this->assertEquals('Firstname', $firstname->getValue()); $this->assertEquals('Firstname', $firstname->getValue());
$this->assertEquals('Lastname', $lastname->getValue()); $this->assertEquals('Lastname', $lastname->getValue());
Expand Down Expand Up @@ -236,15 +226,12 @@ public function testMultiInput()
{ {
$this->getSession()->visit($this->pathTo('/multi_input_form.html')); $this->getSession()->visit($this->pathTo('/multi_input_form.html'));
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$this->assertEquals('Multi input Test', $page->find('css', 'h1')->getText()); $webAssert = $this->getAssertSession();

$this->assertEquals('Multi input Test', $webAssert->elementExists('css', 'h1')->getText());
$first = $page->findField('First');
$second = $page->findField('Second');
$third = $page->findField('Third');


$this->assertNotNull($first); $first = $webAssert->fieldExists('First');
$this->assertNotNull($second); $second = $webAssert->fieldExists('Second');
$this->assertNotNull($third); $third = $webAssert->fieldExists('Third');


$this->assertEquals('tag1', $first->getValue()); $this->assertEquals('tag1', $first->getValue());
$this->assertSame('tag2', $second->getValue()); $this->assertSame('tag2', $second->getValue());
Expand Down
22 changes: 7 additions & 15 deletions driver-testsuite/tests/Form/Html5Test.php
Expand Up @@ -10,12 +10,10 @@ public function testHtml5FormInputAttribute()
{ {
$this->getSession()->visit($this->pathTo('/html5_form.html')); $this->getSession()->visit($this->pathTo('/html5_form.html'));
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$webAssert = $this->getAssertSession();


$firstName = $page->findField('first_name'); $firstName = $webAssert->fieldExists('first_name');
$lastName = $page->findField('last_name'); $lastName = $webAssert->fieldExists('last_name');

$this->assertNotNull($firstName);
$this->assertNotNull($lastName);


$this->assertEquals('not set', $lastName->getValue()); $this->assertEquals('not set', $lastName->getValue());
$firstName->setValue('John'); $firstName->setValue('John');
Expand Down Expand Up @@ -63,12 +61,10 @@ public function testHtml5FormButtonAttribute()
{ {
$this->getSession()->visit($this->pathTo('/html5_form.html')); $this->getSession()->visit($this->pathTo('/html5_form.html'));
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$webAssert = $this->getAssertSession();


$firstName = $page->findField('first_name'); $firstName = $webAssert->fieldExists('first_name');
$lastName = $page->findField('last_name'); $lastName = $webAssert->fieldExists('last_name');

$this->assertNotNull($firstName);
$this->assertNotNull($lastName);


$firstName->setValue('John'); $firstName->setValue('John');
$lastName->setValue('Doe'); $lastName->setValue('Doe');
Expand All @@ -90,11 +86,7 @@ public function testHtml5FormOutside()
$this->getSession()->visit($this->pathTo('/html5_form.html')); $this->getSession()->visit($this->pathTo('/html5_form.html'));
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();


$field = $page->findField('other_field'); $page->fillField('other_field', 'hello');

$this->assertNotNull($field);

$field->setValue('hello');


$page->pressButton('Submit separate form'); $page->pressButton('Submit separate form');


Expand Down
26 changes: 10 additions & 16 deletions driver-testsuite/tests/Form/SelectTest.php
Expand Up @@ -9,16 +9,13 @@ class SelectTest extends TestCase
public function testMultiselect() public function testMultiselect()
{ {
$this->getSession()->visit($this->pathTo('/multiselect_form.html')); $this->getSession()->visit($this->pathTo('/multiselect_form.html'));
$webAssert = $this->getAssertSession();
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$this->assertEquals('Multiselect Test', $page->find('css', 'h1')->getText()); $this->assertEquals('Multiselect Test', $webAssert->elementExists('css', 'h1')->getText());


$select = $page->findField('select_number'); $select = $webAssert->fieldExists('select_number');
$multiSelect = $page->findField('select_multiple_numbers[]'); $multiSelect = $webAssert->fieldExists('select_multiple_numbers[]');
$secondMultiSelect = $page->findField('select_multiple_values[]'); $secondMultiSelect = $webAssert->fieldExists('select_multiple_values[]');

$this->assertNotNull($select);
$this->assertNotNull($multiSelect);
$this->assertNotNull($secondMultiSelect);


$this->assertEquals('20', $select->getValue()); $this->assertEquals('20', $select->getValue());
$this->assertSame(array(), $multiSelect->getValue()); $this->assertSame(array(), $multiSelect->getValue());
Expand Down Expand Up @@ -65,13 +62,12 @@ public function testMultiselect()
public function testElementSelectedStateCheck($selectName, $optionValue, $optionText) public function testElementSelectedStateCheck($selectName, $optionValue, $optionText)
{ {
$session = $this->getSession(); $session = $this->getSession();
$webAssert = $this->getAssertSession();
$session->visit($this->pathTo('/multiselect_form.html')); $session->visit($this->pathTo('/multiselect_form.html'));
$select = $session->getPage()->findField($selectName); $select = $webAssert->fieldExists($selectName);
$this->assertNotNull($select);


$optionValueEscaped = $session->getSelectorsHandler()->xpathLiteral($optionValue); $optionValueEscaped = $session->getSelectorsHandler()->xpathLiteral($optionValue);
$option = $select->find('named', array('option', $optionValueEscaped)); $option = $webAssert->elementExists('named', array('option', $optionValueEscaped));
$this->assertNotNull($option);


$this->assertFalse($option->isSelected()); $this->assertFalse($option->isSelected());
$select->selectOption($optionText); $select->selectOption($optionText);
Expand All @@ -90,8 +86,7 @@ public function testSetValueSingleSelect()
{ {
$session = $this->getSession(); $session = $this->getSession();
$session->visit($this->pathTo('/multiselect_form.html')); $session->visit($this->pathTo('/multiselect_form.html'));
$select = $session->getPage()->findField('select_number'); $select = $this->getAssertSession()->fieldExists('select_number');
$this->assertNotNull($select);


$select->setValue('10'); $select->setValue('10');
$this->assertEquals('10', $select->getValue()); $this->assertEquals('10', $select->getValue());
Expand All @@ -101,8 +96,7 @@ public function testSetValueMultiSelect()
{ {
$session = $this->getSession(); $session = $this->getSession();
$session->visit($this->pathTo('/multiselect_form.html')); $session->visit($this->pathTo('/multiselect_form.html'));
$select = $session->getPage()->findField('select_multiple_values[]'); $select = $this->getAssertSession()->fieldExists('select_multiple_values[]');
$this->assertNotNull($select);


$select->setValue(array('1', '2')); $select->setValue(array('1', '2'));
$this->assertEquals(array('1', '2'), $select->getValue()); $this->assertEquals(array('1', '2'), $select->getValue());
Expand Down

0 comments on commit 1f11bbd

Please sign in to comment.