* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); require_once(dirname(__FILE__).'/../mock/sfGridMock.class.php'); $t = new lime_test(53, new lime_output_color()); // Iterator interface $t->diag('Iterator interface'); $f = new sfGridFormatterHtml(new sfGridMock()); $i = 0; foreach ($f as $key => $row) { $t->is($key, $i, 'sfGridFormatterHtml implements the Iterator interface'); $t->isa_ok($row, 'sfGridFormatterHtmlRow', 'sfGridFormatterHtml implements the Iterator interface'); $t->is($row->getIndex(), $i, 'sfGridFormatterHtml implements the Iterator interface'); ++$i; } $f = new sfGridFormatterHtml(new sfGridMock(array('id', 'name'), 0)); $t->is(count(iterator_to_array($f)), 0, 'sfGridFormatterHtml implements the Iterator interface'); // Countable interface $t->diag('Countable interface'); $f = new sfGridFormatterHtml(new sfGridMock()); $t->is(count($f), 9, 'sfGridFormatterHtml implements the Countable interface'); // ->renderColumnHead() $t->diag('->renderColumnHead()'); $f = new sfGridFormatterHtml($g = new sfGridMock()); $t->is($f->renderColumnHead('id'), 'Id', '->renderColumnHead() returns the head of a column'); $t->is($f->renderColumnHead('name'), 'Name', '->renderColumnHead() returns the head of a column'); $g->setSortable('id'); try { $f->renderColumnHead('id'); $t->fail('->renderColumnHead() throws a "LogicException" if the given column is set to sortable, but no URI has been set'); } catch (LogicException $e) { $t->pass('->renderColumnHead() throws a "LogicException" if the given column is set to sortable, but no URI has been set'); } $g->setUri('http://test.com'); $t->is($f->renderColumnHead('id'), 'Id', '->renderColumnHead() returns the head of a column'); $g->setSort('id', 'asc'); $t->is($f->renderColumnHead('id'), 'Id', '->renderColumnHead() returns the head of a column'); $g->setSort('id', 'desc'); $t->is($f->renderColumnHead('id'), 'Id', '->renderColumnHead() returns the head of a column'); // Bernhard, this fails now, since I loose all parameters (by design). // Do you think this is required! (do you need the parameters), I store // parameters in the user-session, and don't set them in the URL //$g->setUri('http://test.com?param=value&sort=column&type=desc'); //$t->is($f->renderColumnHead('id'), 'Id', '->renderColumnHead() returns the head of a column'); $f = new sfGridFormatterHtml(new sfGridMock(array('name'))); try { $f->renderColumnHead('id'); $t->fail('->renderColumnHead() throws a "LogicException" if the given column has not been configured'); } catch (LogicException $e) { $t->pass('->renderColumnHead() throws a "LogicException" if the given column has not been configured'); } // ->renderHead() $t->diag('->renderHead()'); $f = new sfGridFormatterHtml(new sfGridMock()); $output = << Id Name EOF; $t->is($f->renderHead(), $output, '->renderHead() returns the head of the HTML table'); $f = new sfGridFormatterHtml(new sfGridMock(array('name'))); $output = << Name EOF; $t->is($f->renderHead(), $output, '->renderHead() includes only configured columns'); // ->renderPager() $t->diag('->renderPager()'); $g = new sfGridMock(); $g->getPager()->setMaxPerPage(2); $f = new sfGridFormatterHtml($g); try { $f->renderPager(); $t->fail('->renderPager() throws a "LogicException" if no URI has been set'); } catch (LogicException $e) { $t->pass('->renderPager() throws a "LogicException" if no URI has been set'); } // Bernhard, again I strip the parameters with setUri $g->setUri('http://test.com?param=value&page=100'); $output = << 1 2 3 4 5 » »| EOF; $t->is($f->renderPager(), $output, '->renderPager() renders the pager'); $g->setUri('http://test.com'); $output = << 1 2 3 4 5 » »| EOF; $t->is($f->renderPager(), $output, '->renderPager() renders the pager'); $g->getPager()->setPage(2); $output = << « 1 2 3 4 5 » »| EOF; $t->is($f->renderPager(), $output, '->renderPager() renders the pager'); $g->getPager()->setPage(4); $output = << « 1 2 3 4 5 » EOF; $t->is($f->renderPager(), $output, '->renderPager() renders the pager'); $g->getPager()->setPage(5); $output = << « 1 2 3 4 5 EOF; $t->is($f->renderPager(), $output, '->renderPager() renders the pager'); // ->renderFoot() $t->diag('->renderFoot()'); $g = new sfGridMock(); $g->setUri('http://test.com'); $f = new sfGridFormatterHtml($g); $output = << 9 results EOF; $t->is($f->renderFoot(), $output, '->renderFoot() renders the foot of the HTML table'); $g->getPager()->setMaxPerPage(2); $pager = sfGridFormatterHtml::indent($f->renderPager(), 2); $output = << $pager 9 results (page 1 of 5) EOF; $t->is($f->renderFoot(), $output, '->renderFoot() renders the foot of the HTML table'); $g->getPager()->setPage(2); $pager = sfGridFormatterHtml::indent($f->renderPager(), 2); $output = << $pager 9 results (page 2 of 5) EOF; $t->is($f->renderFoot(), $output, '->renderFoot() renders the foot of the HTML table'); $f = new sfGridFormatterHtml(new sfGridMock(array('name'))); $output = << 9 results EOF; $t->is($f->renderFoot(), $output, '->renderFoot() includes only the configured columns'); $f = new sfGridFormatterHtml(new sfGridMock(array('id', 'name'), 1)); $output = << 1 results EOF; $t->is($f->renderFoot(), $output, '->renderFoot() renders the number of results'); $f = new sfGridFormatterHtml(new sfGridMock(array('id', 'name'), 0)); $output = << 0 results EOF; $t->is($f->renderFoot(), $output, '->renderFoot() renders the number of results'); // ->renderBody() $t->diag('->renderBody()'); $f = new sfGridFormatterHtml(new sfGridMock()); $output = << 1 Fabien 2 Francois 3 Jonathan 4 Fabian 5 Kris 6 Nicolas 7 Fabian 8 Dustin 9 Carl EOF; $t->is($f->renderBody(), $output, '->renderBody() returns the body of the HTML table'); $f = new sfGridFormatterHtml(new sfGridMock(array('name'))); $output = << Fabien Francois Jonathan Fabian Kris Nicolas Fabian Dustin Carl EOF; $t->is($f->renderBody(), $output, '->renderBody() includes only configured columns'); // ->render() $t->diag('->render()'); $f = new sfGridFormatterHtml(new sfGridMock()); $output = $f->renderHead().$f->renderFoot().$f->renderBody(); $t->is($f->render(), $output, '->render() returns the content of the HTML table');