forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FrameworkBundle] Functional tests, to test functional test simulated…
… file uploads
- Loading branch information
Showing
11 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AppKernel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...FrameworkBundle/Tests/Functional/Bundle/FileUploadBundle/Controller/DefaultController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...fony/Bundle/FrameworkBundle/Tests/Functional/Bundle/FileUploadBundle/FileUploadBundle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
3 changes: 3 additions & 0 deletions
3
...dle/FrameworkBundle/Tests/Functional/Bundle/FileUploadBundle/Resources/config/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FileUploadBundle_homepage: | ||
pattern: /submit | ||
defaults: { _controller: FileUploadBundle:Default:index } |
1 change: 1 addition & 0 deletions
1
...rkBundle/Tests/Functional/Bundle/FileUploadBundle/Resources/views/Default/index.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ files }} File |
17 changes: 17 additions & 0 deletions
17
...undle/Tests/Functional/Bundle/FileUploadBundle/Tests/Controller/DefaultControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/UploadTestCase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/config/default.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
imports: | ||
- { resource: framework.yml } | ||
- { resource: twig.yml } |
12 changes: 12 additions & 0 deletions
12
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/config/framework.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
2 changes: 2 additions & 0 deletions
2
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/config/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
_food_risc_account_admin: | ||
resource: "@FileUploadBundle/Resources/config/routing.yml" |
7 changes: 7 additions & 0 deletions
7
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/config/twig.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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% |