<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('see cookie exist and be redirect to paper if input correct password');
$I->amOnPage('/password');
$I->fillField('#password', '123456');
$I->click('Login');
$I->seeCookie('password');
$I->amOnPage('/password');
<?php

$I = new SeleniumTester($scenario);
$I->wantTo('perform actions and see result');
$I->amOnUrl('http://localhost/~hab/test/web/app_dev.php');
$I->see('Hello World!');
$I->fillField('username', 'hamza');
$I->click('submit');
//$I->seeCurrentUrlEquals('/~hab/test/web/app_dev.php/testform');
//$I->seeInCurrentUrl('/testform');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('be redirect to login, cause I have wrong cookie');
$I->setCookie('password', 'ofcousethisisawrongcookie');
$I->amOnPage('/password');
$I->seeCurrentUrlEquals('/password/login');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('see the paper if non password protected');
$I->amOnPage('/test');
$I->seeCurrentUrlEquals('/test');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('make sure no one could log out if not having correct cookie');
$I->setCookie('password', 'anotherwrongcookie');
$I->amOnPage('/password');
$I->sendPOST('http://manhgiay.dev/password/logOut');
$I->seeCurrentUrlEquals('/password/login');
$I->resetCookie('password');
$I->sendPOST('http://manhgiay.dev/password/logOut');
$I->seeCurrentUrlEquals('/password/login');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('content will be updated if having correct cookie');
$I->amOnPage('/password');
$I->fillField('#password', '123456');
$I->click('Login');
$I->fillField('#content', 'Some demo text that will make all the way to database');
$I->wait(2);
$I->seeInDatabase('manhgiays', ['slug' => 'password', 'content' => 'Some demo text that will make all the way to database']);
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('Ensure cannot change password if cookie not correct');
$I->setCookie('password', 'thewrongpassword');
$I->amOnPage('/password');
$I->sendPOST('http://manhgiay.dev/password/updatePassword', ['password' => 'password']);
$I->seeCurrentUrlEquals('/password/login');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('be redirect to login and lost cookie if choose to remove password');
$I->amOnPage('/password');
$I->fillField('#password', '123456');
$I->click('Login');
$I->click('Remove Password');
$I->acceptPopup();
$I->seeCurrentUrlEquals('/password');
$I->wait(1);
$I->dontSee('Remove Password');
$I->dontSeeCookie('password');
##Now let put back password together
$I->click('Add Password?');
$I->typeInPopup('123456');
$I->acceptPopup();
$I->typeInPopup('123456');
$I->acceptPopup();
$I->wait(1);
$I->seeCurrentUrlEquals('/password');
$I->see('Remove Password');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('be redirected to login page if input wrong password');
$I->amOnPage('/password');
$I->fillField('#password', 'thewrongpassword');
$I->click('Login');
$I->seeCurrentUrlEquals('/password/login');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('be redirect to login, because paper have password protected');
$I->amOnPage('/password');
$I->seeCurrentUrlEquals('/password/login');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('see cookie be deleted and redirect to login if log out and having correct cookie');
$I->amOnPage('/password');
$I->fillField('#password', '123456');
$I->click('Login');
$I->seeCurrentUrlEquals('/password');
$I->click('Log Out');
$I->wait(1);
$I->dontSeeCookie('password');
$I->seeCurrentUrlEquals('/password/login');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('ensure no way to update content without a correct cookie');
$I->amOnPage('/password');
$I->seeCurrentUrlEquals('/password/login');
$I->sendPOST('http://manhgiay.dev/password/updateContent', ['content' => 'This will not made it to database']);
$I->seeInDatabase('manhgiays', ['content' => ""]);
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('be redirected to show if access login page with correct cookie');
$I->amOnPage('/password');
$I->seeCurrentUrlEquals('/password/login');
$I->fillField('#password', '123456');
$I->click('Login');
$I->seeCurrentUrlEquals('/password');
$I->amOnPage('/password/login');
$I->seeCurrentUrlEquals('/password');
<?php

$I = new SeleniumTester($scenario);
$I->am('a guest');
$I->wantTo('guarantee no one can remove password if not having correct cookie');
$I->amOnPage('/password');
$I->setCookie('password', 'yetAnotherWrongCookie');
$I->sendPOST('http://manhgiay.dev/password/removePassword');
$I->seeCurrentUrlEquals('/password/login');
$I->resetCookie('password');
$I->sendPOST('http://manhgiay.dev/password/removePassword');
$I->seeCurrentUrlEquals('/password/login');