Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FrameworkBundle] Functional tests, to test functional test simulated file uploads #1891

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AppKernel.php
@@ -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';
}
}
@@ -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)));
}
}
@@ -0,0 +1,9 @@
<?php

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

use Symfony\Component\HttpKernel\Bundle\Bundle;

class FileUploadBundle extends Bundle
{
}
@@ -0,0 +1,3 @@
FileUploadBundle_homepage:
pattern: /submit
defaults: { _controller: FileUploadBundle:Default:index }
@@ -0,0 +1 @@
{{ files }} File
@@ -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);
}
}
@@ -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()));
}

}
@@ -0,0 +1,3 @@
imports:
- { resource: framework.yml }
- { resource: twig.yml }
@@ -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"
@@ -0,0 +1,2 @@
_food_risc_account_admin:
resource: "@FileUploadBundle/Resources/config/routing.yml"
@@ -0,0 +1,7 @@
framework:
templating:
engines: [twig, php]

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