1
0
mirror of https://github.com/moparisthebest/wallabag synced 2025-01-30 23:00:20 -05:00

Use fixtures for tests

This commit is contained in:
Vincent Jousse 2013-11-24 22:48:05 +01:00
parent 43a934d560
commit 00ac1a58be
4 changed files with 56 additions and 2 deletions

View File

@ -1,9 +1,10 @@
<?php
namespace Poche\Tests\Functionals;
use Poche\Tests\Functionals\Fixtures;
class ApiTest extends PocheWebTestCase
{
public function testGetEntries()
public function testEmptyGetEntries()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/api/entries');
@ -18,6 +19,33 @@ class ApiTest extends PocheWebTestCase
)
);
$this->assertTrue($client->getResponse()->getContent() == '[]');
$this->assertEquals($client->getResponse()->getContent(), '[]');
//Load some entries
Fixtures::loadEntries($this->app['db']);
}
public function testGetEntries()
{
//Load some entries
Fixtures::loadEntries($this->app['db']);
$client = $this->createClient();
$crawler = $client->request('GET', '/api/entries');
$this->assertTrue($client->getResponse()->isOk());
// Assert that the "Content-Type" header is "application/json"
$this->assertTrue(
$client->getResponse()->headers->contains(
'Content-Type',
'application/json'
)
);
$this->assertEquals($client->getResponse()->getContent(),'{"id":"1","url":"http:\/\/deboutlesgens.com\/blog\/le-courage-de-vivre-consciemment\/","title":"Le courage de vivre consciemment","content":"Test content","updated":null,"status":null,"bookmark":"0","fetched":"1","user_id":"1"}');
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Poche\Tests\Functionals;
class Fixtures
{
public static function loadUsers($db) {
$db->query("INSERT INTO users (id, username) values (1, 'poche_test');");
}
public static function loadEntries($db) {
$db->query("INSERT INTO entries (id, url, title, content, user_id) values (1, 'http://deboutlesgens.com/blog/le-courage-de-vivre-consciemment/', 'Le courage de vivre consciemment','Test content', 1);");
}
}

View File

@ -1,12 +1,16 @@
<?php
namespace Poche\Tests\Functionals;
use Poche\Tests\Functionals\Fixtures;
use Silex\WebTestCase;
use Poche\Schema;
class PocheWebTestCase extends WebTestCase
{
protected $app;
public function createApplication()
{
require __DIR__.'/../../app/app.php';
@ -22,6 +26,10 @@ class PocheWebTestCase extends WebTestCase
Schema::dropTables($app['db']);
Schema::createTables($app['db']);
Fixtures::loadUsers($app['db']);
$this->app = $app;
return $app;
}
}

View File

@ -1,3 +1,4 @@
<?php
require __DIR__.'/../../vendor/autoload.php';
require __DIR__.'/Fixtures.php';
require __DIR__.'/PocheWebTestCase.php';