Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
tests for Pagination and Gettext
Browse files Browse the repository at this point in the history
  • Loading branch information
maniolek committed Jan 8, 2015
1 parent 928070c commit e2183b7
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Tag/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Vegas\Tag\Pagination;
use Vegas\Test\TestCase;
use Vegas\Tests\Stub\Models\FakeModel;
use Vegas\Tests\Stub\Models\FakePaginatorModel;

class RequestMock
{
Expand Down Expand Up @@ -116,6 +117,36 @@ public function testRender()
$this->assertSame(2, $page->current);
$this->assertSame(10, count($page->items));
$this->assertSame(2, $page->total_pages);


}

public function testOffset()
{
$pagination = new Pagination($this->di);

for($i = 1; $i <= 20; $i++) {
$model = new FakePaginatorModel;
$model->fake_field = $i;
$model->save();
}

$paginator = new Mongo(array(
'db' => $this->di->get('mongo'),
'modelName' => '\Vegas\Tests\Stub\Models\FakePaginatorModel',
'query' => [],
'page' => 5,
'limit' => 2
));

$this->assertEquals(
'<ul class="pagination"><li class="prev"><a href="/?page=4">Previous</a></li><li class=""><a href="/?page=1">1</a></li><li class=""><a href="/?page=2">2</a></li><li class=""><a href="/?page=3">3</a></li><li class=""><a href="/?page=4">4</a></li><li class="active"><a href="/?page=5">5</a></li><li class=""><a href="/?page=6">6</a></li><li class=""><a href="/?page=7">7</a></li><li class="more"><a href="/?page=5">...</a></li><li class=""><a href="/?page=9">9</a></li><li class=""><a href="/?page=10">10</a></li><li class="next"><a href="/?page=6">Next</a></li></ul>',
$pagination->render($paginator->getPaginate(), ['middle_offset' => 2])
);

foreach (FakePaginatorModel::find() as $robot) {
$robot->delete();
}
}

public function testArguments()
Expand Down
137 changes: 137 additions & 0 deletions tests/Translate/GettextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* This file is part of Vegas package
*
* @author Arkadiusz Ostrycharz <aostrycharz@amsterdam-standard.pl>
* @copyright Amsterdam Standard Sp. Z o.o.
* @homepage http://vegas-cmf.github.io
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Vegas\Tests\Tag;

use Vegas\Paginator\Adapter\Mongo;
use Vegas\Tag\Pagination;
use Vegas\Test\TestCase;
use Vegas\Tests\Stub\Models\FakeModel;
use Vegas\Tests\Stub\Models\FakePaginatorModel;
use Vegas\Translate\Adapter\Gettext;


class GettextTest extends TestCase
{
public function testNotArrayArgument()
{
try {
$gettext = new Gettext('not_an_array');
throw new \Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Phalcon\Translate\Exception', $ex);
}

}

public function testLocaleArgument()
{
try {
$gettext = new Gettext(array());
throw new \Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Phalcon\Translate\Exception', $ex);
}

}

public function testDomainArgument()
{
try {
$gettext = new Gettext(array('locale' => 'en_US'));
throw new \Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Phalcon\Translate\Exception', $ex);
}

}

public function testDomainDirectoryArgument()
{
try {
$gettext = new Gettext(array(
'locale' => 'en_US',
'directory' => '/tmp'
));
throw new \Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Phalcon\Translate\Exception', $ex);
}

}

public function testDomainFileArgument()
{
try {
$gettext = new Gettext(array(
'locale' => 'en_US',
'file' => 'tmp.data'
));
throw new \Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Phalcon\Translate\Exception', $ex);
}

}

public function testDomainNotArrayArgument()
{
try {
$gettext = new Gettext(array(
'locale' => 'en_US',
'file' => 'tmp.data',
'directory' => '/tmp',
'domains' => 'not_an_array'

));
throw new \Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Phalcon\Translate\Exception', $ex);
}

}

public function testDomainArrayArgument()
{
try {
$gettext = new Gettext(array(
'locale' => 'en_US',
'file' => 'tmp.data',
'directory' => '/tmp',
'domains' => array(
'domain1', 'domain2'
)

));
throw new \Vegas\Exception('This exception');

} catch (\Exception $ex) {
$this->assertInstanceOf('\Vegas\Exception', $ex);
}
}

public function testDomainFileAsArrayArgument()
{
try {
$gettext = new Gettext(array(
'locale' => 'en_US',
'file' => array('tmp.data'),
'directory' => '/tmp'

));
throw new \Vegas\Exception('Not this exception.');
} catch (\Exception $ex) {
$this->assertInstanceOf('\Vegas\Exception', $ex);
}

}

}

0 comments on commit e2183b7

Please sign in to comment.