<?php
namespace Phad\Test\Main;
/**
* Every method here should be referenced by an @claim() in the documentation.
*
* if any of these tests are ever failing, BE SURE TO UPDATE DOCS!!!
*
* Search for '@claim(TestName)' in the code base (do not include the word 'test').
*/
class Claims extends \Phad\Tester {
public function testFormDefaultBlackHoleNodes(){
$phad = $this->phad();
$item = $phad->item('Documentation/Form/BlackHoleWithDefaultDeny');
$this->test("When Default data node is access=false, and black hole is present, form renders");
$this->str_contains($item.'',
"BEFORE FORM",
"AFTER FORM"
);
$this->str_contains($item.'',
'<label>Body</label><br>',
'<textarea name="body" maxlength="2000" minlength="50"></textarea><br><br>'
);
$item = $phad->item('Documentation/Form/OnlyDefaultDeny');
$this->test("When default data node is access=false, and no other data node present, form does not render");
$this->str_not_contains($item.'',
'<label>Body</label><br>',
'<textarea name="body" maxlength="2000" minlength="50"></textarea><br><br>'
);
$this->str_contains($item.'',
"BEFORE FORM",
"AFTER FORM"
);
}
public function testGET_id_Behavior(){
$phad = $this->phad();
$this->makeIDBlogTable();
$not_found_msg = "Blog Post Not Found";
$this->test("Ensure data is loaded and form is working when GET[id] is valid");
$_GET['id'] = 1;
$found = $phad->item('Documentation/Form/FormWithWrongIDis404');
$this->str_contains($found, '"Dog"', "Ruff</textarea>");
$this->str_not_contains($found, $not_found_msg);
$this->test("Ensure 404 error displays and form does not print when GET[id] has no matching rows");
$_GET['id']=9997;
$not_found = $phad->item('Documentation/Form/FormWithWrongIDis404');
$this->compare($not_found_msg, trim($not_found));
unset($_GET['id']);
$this->test("Ensure Blank form displays when GET[id] is not set");
unset($_GET['id']);
$not_set = $phad->item('Documentation/Form/FormWithWrongIDis404');
$this->str_contains($not_set, 'value=""', 'minlength="50"></textarea>');
$this->str_not_contains($not_set, $not_found_msg);
$this->test("Ensure Blank form displays when GET[id] is set and NULL");
$_GET['id'] = null;
$null_id = $phad->item('Documentation/Form/FormWithWrongIDis404');
$this->str_contains($not_set, 'value=""', 'minlength="50"></textarea>');
$this->str_not_contains($not_set, $not_found_msg);
$this->test("Ensure Blank form displays when passing `id` explicitly passed but GET[id] is unset");
unset($_GET['id']);
$passed_id_no_get = $phad->item('Documentation/Form/FormWithWrongIDis404', ['id'=>1]);
$this->str_contains($not_set, 'value=""', 'minlength="50"></textarea>');
$this->str_not_contains($not_set, $not_found_msg);
unset($_GET['id']);
}
public function testFormWithInputNameAndProp(){
$phad = $this->phad();
$this->makeIDBlogTable();
$not_found_msg = "Blog Post Not Found";
$this->test("1: name attr works. 2: name+prop yields prop as value. 3: prop-only does not get processed");
$_GET['id'] = 1;
$form = $phad->item('Documentation/Form/InputWithNameAndProp');
$this->str_contains($form,
'maxlength="75" value="Dog"',
'maxlength="70" value="prop(Dog)',
'prop="real_title" maxlength="65"',
);
}
public function testSubmitFormWithInputNameAndProp(){
echo "\n\nTHIS TEST NEEDS ATTENTION\n\n";
$this->disable();
//return;
$phad = $this->phad();
$_SERVER['HTTP_HOST'] = null;
$this->makeIDBlogTable();
$not_found_msg = "Blog Post Not Found";
$this->test("... todo ...");
$_GET['id'] = 1;
$form = $phad->item('Documentation/Form/SubmitInputWithPropAndName', ['title_alone' => 'TEST passed title alone']);
$_POST['title_alone'] = 'TEST POST TITLE';
$_POST['title_and_prop'] = 'TEST POST TITLE WITH PROP';
$v = $form->submit();
var_dump($v);
unset($_POST['title']);
return;
}
}