Skip to content

Commit

Permalink
[FrameworkBundle] Functional tests, to test functional test simulated…
Browse files Browse the repository at this point in the history
… file uploads
  • Loading branch information
johnwards committed Aug 2, 2011
1 parent e136718 commit 20abbdc
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Component\HttpKernel\Util\Filesystem;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
private $config;

public function __construct($config)
{
parent::__construct('test', true);

$fs = new Filesystem();
if (!$fs->isAbsolutePath($config)) {
$config = __DIR__.'/config/'.$config;
}

if (!file_exists($config)) {
throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
}

$this->config = $config;
}

public function registerBundles()
{
return array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\FileUploadBundle\FileUploadBundle(),
);
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->config);
}

public function getCacheDir()
{
return sys_get_temp_dir().'/FrameworkBundle';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\FileUploadBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class DefaultController extends Controller
{

public function indexAction()
{
$files = $this->get('request')->files->all();

return $this->render('FileUploadBundle:Default:index.html.twig', array('files' => count($files)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\FileUploadBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class FileUploadBundle extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FileUploadBundle_homepage:
pattern: /submit
defaults: { _controller: FileUploadBundle:Default:index }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ files }} File
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\FileUploadBundle\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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class UploadTestCase extends WebTestCase
{
static protected function createKernel(array $options = array())
{
return new AppKernel(
isset($options['config']) ? $options['config'] : 'default.yml'
);
}

/**
* The point of this is to send this file to the upload file
*
* The route should respond with the number of files sent to it. In this case 1.
*
* @return void
*/
public function testUploadFile()
{
$client = $this->createClient();
$crawler = $client->request(
'POST',
'/submit',
array('name' => 'Fabien'),
array('photo' => __FILE__)
);
$this->assertEquals("1 File", $crawler->text());
$this->assertEquals(1, count($client->getRequest()->files->all()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
imports:
- { resource: framework.yml }
- { resource: twig.yml }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
framework:
secret: test
test: ~
session:
storage_id: session.storage.filesystem
form: true
csrf_protection: true
validation:
enabled: true
enable_annotations: true
router:
resource: "%kernel.root_dir%/config/routing.yml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_food_risc_account_admin:
resource: "@FileUploadBundle/Resources/config/routing.yml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
framework:
templating:
engines: [twig, php]

twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%

0 comments on commit 20abbdc

Please sign in to comment.