Main.php
<?php
namespace Phad\Test;
/**
* Used for testing code that's written in the documentation
*
*/
class Main extends \Phad\Tester {
public function testPagination(){
$p = $this->phad();
$page_was = $_GET['page'] ?? false;
$data = $this->makeStandardBlogTable();
$this->test("Pagination has first page and does NOT have second page");
$_GET['page'] = 0;
$item = $p->item('Other/Paginate',[]).'';
$this->str_contains(
$item,
$data[0]['title'],
$data[1]['title']
);
$this->str_not_contains(
$item,
$data[2]['title'],
$data[3]['title']
);
$this->test("Pagination has secondd page and does NOT have first page");
$_GET['page'] = 1;
$item = $p->item('Other/Paginate',[]).'';
$this->str_contains(
$item,
$data[2]['title'],
$data[3]['title']
);
$this->str_not_contains(
$item,
$data[0]['title'],
$data[1]['title']
);
if ($page_was===false)unset($_GET['page']);
else $_GET['page'] = $page_was;
}
public function testPassing_object(){
$p = $this->phad();
$page_was = $_GET['page'] ?? false;
$data = $this->makeStandardBlogTable();
$obj1 = (object)['title'=>'Custom Made Object', 'body'=>'Custom made object body'];
$obj2 = (object)['title'=>'Second Custom Object', 'body'=>'Body of Second OBJECT'];
$row3 = ['title'=>'Row title', 'body' => 'Row body'];
$this->test("Passing `_object` as an arg");
$_GET['page'] = 0;
$item = $p->item('Form/SimpleBlog',
[ '_object' => $obj1 ]).'';
$this->str_contains(
$item,
$obj1->title,
$obj1->body
);
$this->test("Passing `_object` as the row content for one row");
$_GET['page'] = 0;
$item = $p->item('Form/SimpleBlog',
['Blog' =>
['_object' => $obj1]
]).'';
$this->str_contains(
$item,
$obj1->title,
$obj1->body
);
$this->test("Passing `_object` as the row content for rows in a list");
$_GET['page'] = 0;
$item = $p->item('Form/SimpleBlog',
['BlogList' =>
[
['_object' => $obj1],
$row3,
['_object' => $obj2],
]
]).'';
$this->str_contains(
$item,
$obj1->title,
$obj1->body
);
$this->str_contains(
$item,
$obj2->title,
$obj2->body
);
$this->str_contains(
$item,
$row3['title'],
$row3['body'],
);
}
public function testBlackHole(){
$bh = new \Phad\BlackHole();
ob_start();
try {
$prop = $bh->property;
$prop2 = $bh->property_two;
$ret = $bh->method();
$ret2 = $bh->method_two();
$arr = $bh['some_arg'];
$arr2 = $bh['some_other_arg'];
$bh['a'] = 'b';
$bh['c'] = 'd';
unset($bh['c']);
$bh->f = 'f';
$bh->d = 'd';
} catch (\Exception $e){
echo $e->getMessage();
}
$c = ob_get_clean();
$this->test("There was no output (error or otherwise) from black hole object");
$this->compare_raw('', $c);
$this->test("There are no props on BH");
$this->compare_raw([], get_object_vars($bh));
}
}