First take on unit tests.

Creates an event and compares the the input data with the database.

Ticket #28
This commit is contained in:
Tim Schumacher 2016-06-26 13:48:47 +02:00
parent fc138fb910
commit e44e7b6423
10 changed files with 1491 additions and 82 deletions

View file

@ -24,6 +24,7 @@ class AppKernel extends Kernel
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();
}
return $bundles;

View file

@ -12,7 +12,7 @@ echo '> PHP is using the following php.ini file:'.PHP_EOL;
if ($iniPath) {
echo_style('green', ' '.$iniPath);
} else {
echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!');
echo_style('yellow', ' WARNING: No configuration file (php.ini) used by PHP!');
}
echo PHP_EOL.PHP_EOL;

View file

@ -14,3 +14,13 @@ web_profiler:
swiftmailer:
disable_delivery: true
liip_functional_test: ~
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db

View file

@ -20,11 +20,9 @@
</testsuite>
</testsuites>
<!--
<php>
<server name="KERNEL_DIR" value="/path/to/your/app/" />
<server name="KERNEL_DIR" value="../app/" />
</php>
-->
<filter>
<whitelist>

View file

@ -39,7 +39,10 @@
"sabre/vobject": "^4.1"
},
"require-dev": {
"sensio/generator-bundle": "~3.0"
"sensio/generator-bundle": "~3.0",
"phpunit/phpunit": "^5.4",
"liip/functional-test-bundle": "^1.6",
"doctrine/doctrine-fixtures-bundle": "^2.3"
},
"scripts": {
"post-root-package-install": [

1412
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -176,5 +176,5 @@
</div>
</div>
<input type="submit" class="ui button green" value="Speichern"/>
<input type="submit" class="ui button green" name="save" value="Speichern"/>
</form>

View file

@ -1,17 +0,0 @@
<?php
namespace Hackspace\Bundle\CalciferBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/hello/Fabien');
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
}
}

View file

@ -2,54 +2,80 @@
namespace Hackspace\Bundle\CalciferBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Doctrine\ORM\EntityRepository;
use Hackspace\Bundle\CalciferBundle\Entity\Event;
use Liip\FunctionalTestBundle\Test\WebTestCase;
class EventControllerTest extends WebTestCase
{
/*
public function testCompleteScenario()
{
// Create a new client to browse the application
$client = static::createClient();
// Create a new entry in the database
$crawler = $client->request('GET', '//');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET //");
$crawler = $client->click($crawler->selectLink('Create a new entry')->link());
private function initClient() {
$this->loadFixtures([]);
// Fill in the form and submit it
$form = $crawler->selectButton('Create')->form(array(
'hackspace_bundle_calciferbundle_event[field_name]' => 'Test',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check data in the show view
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
// Edit the entity
$crawler = $client->click($crawler->selectLink('Edit')->link());
$form = $crawler->selectButton('Update')->form(array(
'hackspace_bundle_calciferbundle_event[field_name]' => 'Foo',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check the element contains an attribute with value equals "Foo"
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
// Delete the entity
$client->submit($crawler->selectButton('Delete')->form());
$crawler = $client->followRedirect();
// Check the entity has been delete on the list
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
$client = static::makeClient();
return $client;
}
*/
public function testEmptyListing() {
$client = $this->initClient();
$crawler = $client->request('GET', '/');
$this->assertStatusCode(200, $client);
}
public function testPostEventForm()
{
$client = $this->initClient();
$url = $client->getContainer()->get('router')->generate('_new');
$crawler = $client->request('GET', $url);
$this->assertStatusCode(200, $client);
$form = $crawler->selectButton('save')->form();
$now = new \DateTime();
$now->setTime(0,0,0);
$dateformat = "Y-m-d H:i";
$startdate = clone $now;
$startdate->add(new \DateInterval("P1D"));
$enddate = clone $now;
$enddate->add(new \DateInterval("P1DT2H"));
$form['startdate'] = $startdate->format("Y-m-d H:i");
$form['enddate'] = $enddate->format("Y-m-d H:i");
$form['summary'] = "Testevent";
$form['url'] = "https://calcifer.datenknoten.me";
$form["location"] = "Krautspace";
$form["location_lat"] = 1;
$form["location_lon"] = 2;
$form["tags"] = "foo,bar,krautspace";
$form["description"] = "Testdescription";
$crawler = $client->submit($form);
$this->assertStatusCode(302, $client);
$target = $client->getResponse()->headers->get('location');
$slug = explode("/",$target)[2];
$this->assertGreaterThan(0,strlen($slug));
$em = $this->getContainer()->get('doctrine')->getManager();
/** @var EntityRepository $repo */
$repo = $em->getRepository('CalciferBundle:Event');
/** @var Event $entity */
$entity = $repo->findOneBy(['slug' => $slug]);
$this->assertInstanceOf('Hackspace\Bundle\CalciferBundle\Entity\Event', $entity);
$this->assertTrue($startdate == $entity->startdate, "Startdate equal");
$this->assertTrue($enddate == $entity->enddate, "Enddate equal");
$this->assertTrue($form["summary"]->getValue() == $entity->summary, "Summary equal");
$this->assertTrue($form["url"]->getValue() == $entity->url, "URL equal");
$this->assertTrue($form["description"]->getValue() == $entity->description, "Description equal");
}
}

View file

@ -74,7 +74,9 @@ $minorProblems = $symfonyRequirements->getFailedRecommendations();
<p>Major problems have been detected and <strong>must</strong> be fixed before continuing:</p>
<ol>
<?php foreach ($majorProblems as $problem): ?>
<li><?php echo $problem->getHelpHtml() ?></li>
<li><?php echo $problem->getTestMessage() ?>
<p class="help"><em><?php echo $problem->getHelpHtml() ?></em></p>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
@ -87,7 +89,9 @@ $minorProblems = $symfonyRequirements->getFailedRecommendations();
</p>
<ol>
<?php foreach ($minorProblems as $problem): ?>
<li><?php echo $problem->getHelpHtml() ?></li>
<li><?php echo $problem->getTestMessage() ?>
<p class="help"><em><?php echo $problem->getHelpHtml() ?></em></p>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>