diff options
author | Lev Lazinskiy <lev@circleci.com> | 2016-06-08 19:02:46 -0700 |
---|---|---|
committer | Lev Lazinskiy <lev@circleci.com> | 2016-06-08 19:02:46 -0700 |
commit | 7464607195bb84b2a7b6f1e2ad3b208fe37dc336 (patch) | |
tree | 1e61e6aade07ffcf5877c57e219100a276e75409 | |
parent | 216a8c66471c323cab4ea32cc4cdb0a5027ba6ff (diff) |
Add acceptance tests
Basic Framework for working with Selenium with PHPUnit and Firefox.
Future acceptance tests just need to extend Base.php and implement
various flows that we wish to test.
-rw-r--r-- | tests/acceptance.xml | 13 | ||||
-rw-r--r-- | tests/acceptance/Base.php | 18 | ||||
-rw-r--r-- | tests/acceptance/UserAuthenticationTest.php | 86 |
3 files changed, 117 insertions, 0 deletions
diff --git a/tests/acceptance.xml b/tests/acceptance.xml new file mode 100644 index 00000000..a161f9ec --- /dev/null +++ b/tests/acceptance.xml @@ -0,0 +1,13 @@ +<phpunit stopOnError="true" stopOnFailure="true" colors="true"> + <testsuites> + <testsuite name="Kanboard"> + <directory>acceptance</directory> + </testsuite> + </testsuites> + <php> + <const name="SELENIUM_HOST" value="localhost" /> + <const name="SELENIUM_PORT" value="4444" /> + <const name="DEFAULT_BROWSER" value="firefox" /> + <const name="KANBOARD_APP_URL" value="http://localhost:8001" /> + </php> +</phpunit> diff --git a/tests/acceptance/Base.php b/tests/acceptance/Base.php new file mode 100644 index 00000000..e8684a9b --- /dev/null +++ b/tests/acceptance/Base.php @@ -0,0 +1,18 @@ +<?php + +class Base extends PHPUnit_Extensions_Selenium2TestCase +{ + + public function setUp() + { + $this->setHost(SELENIUM_HOST); + $this->setPort((integer) SELENIUM_PORT); + $this->setBrowserUrl(KANBOARD_APP_URL); + $this->setBrowser(DEFAULT_BROWSER); + } + + public function tearDown() + { + $this->stop(); + } +} diff --git a/tests/acceptance/UserAuthenticationTest.php b/tests/acceptance/UserAuthenticationTest.php new file mode 100644 index 00000000..3313e050 --- /dev/null +++ b/tests/acceptance/UserAuthenticationTest.php @@ -0,0 +1,86 @@ +<?php + +require_once __DIR__.'/Base.php'; + +class UserAuthenticationTest extends Base +{ + + public function validLoginInputsProvider() + { + $inputs[] = [ + [ + 'username' => 'admin', + 'password' => 'admin', + ] + ]; + + return $inputs; + } + + public function invalidLoginInputsProvider() + { + $inputs[] = [ + [ + 'username' => 'wrong_username', + 'password' => 'wrong_password', + ] + ]; + + return $inputs; + } + + /** + * @dataProvider validLoginInputsProvider + */ + public function testValidLogin(array $inputs) + { + $this->url('/'); + $this->assertContains('Login', $this->title()); + + $form = $this->byTag('form'); + foreach ($inputs as $input => $value) { + $form->byName($input)->value($value); + } + $form->submit(); + + $content = $this->byClassName('sidebar')->text(); + $this->assertContains($inputs['username'], $content); + } + + /** + * @dataProvider invalidLoginInputsProvider + */ + public function testInvalidLogin(array $inputs) + { + $this->url('/'); + + // Test wrong username with correct password + $form = $this->byTag('form'); + $form->byName('username')->value($inputs['username']); + $form->byName('password')->value('admin'); + $form->submit(); + + $content = $this->byTag('body')->text(); + $this->assertContains('Bad username or password', $content); + + // Test wrong password with correct username + $form = $this->byTag('form'); + $form->byName('username')->value('admin'); + $form->byName('password')->value($inputs['password']); + $form->submit(); + + $content = $this->byTag('body')->text(); + $this->assertContains('Bad username or password', $content); + + // Test wrong username and password + $form = $this->byTag('form'); + $form->byName('username')->value($inputs['username']); + $form->byName('password')->value($inputs['password']); + $form->submit(); + + $content = $this->byTag('body')->text(); + $this->assertContains('Bad username or password', $content); + + + } +} |