Last active
August 29, 2015 14:26
-
-
Save henriqueutsch/4b8d424ae9b082ff40be to your computer and use it in GitHub Desktop.
Testes no Windows rodando páginas PHP - Teste com ruby, test/unit e mechanize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "browser.php"; | |
date_default_timezone_set('America/Sao_Paulo'); | |
$campos[] = ''; | |
$valores[] = ''; | |
foreach ($_POST as $key => $value) { | |
if(gettype($value) == 'array') | |
{ | |
$temp=""; | |
foreach($value as $check) { | |
$temp = "{$temp},{$check}"; | |
$temp = ltrim ($temp, ','); | |
} | |
$value = $temp; | |
} | |
// echo $key . ' => ' . utf8_decode($value); | |
$campos[] = $key; | |
$valores[] = $value; | |
// echo "<br>"; | |
} | |
array_pop($valores); | |
array_pop($campos); | |
// print_r($valores); | |
// echo "<br>"; | |
// print_r($campos); | |
// echo "<br>"; | |
$campos2 = implode(",", $campos); | |
$campos2 = ltrim ($campos2, ','); | |
$valores2 = implode("','", $valores); | |
$valores2 = ltrim ($valores2, "',"); | |
echo "Email enviado"; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Mechanize</title> | |
</head> | |
<body> | |
<form action="envia.php" method="POST"> | |
<label for="">Nome:</label><br> | |
<input type="text" name="nome"><br> | |
<label for="">Telefone:</label><br> | |
<input type="text" name="telefone"><br> | |
<label for="">E-mail:</label><br> | |
<input type="text" name="email"><br> | |
<label for="">Mensagem:</label><br> | |
<input type="text" name="mensagem"><br> | |
<input type="submit" value="ENVIAR"> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ruby 2.1.6 | |
gem install mechanize | |
Rodar direto no sublime text | |
https://github.com/ehamiter/ST2-Color-Console | |
https://github.com/maltize/sublime-text-2-ruby-tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
require 'Test/Unit' | |
class LoginTest < Test::Unit::TestCase | |
def test_login | |
mechanize = Mechanize.new | |
page = mechanize.get('http://127.0.0.1/mechanize/index.php') | |
form = page.forms.first | |
form['nome'] = 'Henrique Utsch Test' | |
form['telefone'] = '3111111111' | |
form['email'] = '[email protected]' | |
# msg = LoremIpsum.lorem_ipsum(paragraphs: 4) | |
msg = 'teste' | |
form['mensagem'] = msg | |
page = form.submit | |
assert_equal 'Email enviado', page.content | |
# p page.content | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outra opção:
https://laracasts.com/series/intuitive-integration-testing
Para rodar no windows:
http://stackoverflow.com/questions/25549177/change-composer-global-path-windows