public function testTwigBoltFormsUploads() { $app = $this->getApp(); $this->getExtension($app)->config['uploads']['base_directory'] = sys_get_temp_dir(); $this->getExtension($app)->config['testing_form']['uploads']['subdirectory'] = 'testing_form'; $app['request'] = Request::create('/'); $boltforms = new BoltForms($app); $boltforms->makeForm('testing_form'); $fields = $this->formValues(); $boltforms->addFieldArray('testing_form', $fields); $app['boltforms'] = $boltforms; $twigExt = new BoltFormsExtension($app); // Invalid directory $html = $twigExt->twigBoltFormsUploads('koala'); $this->assertInstanceOf('\\Twig_Markup', $html); $this->assertSame('<p><strong>Invalid upload directory</strong></p>', (string) $html); // Valid $tmpDir = sys_get_temp_dir() . '/testing_form'; $srcFile = EXTENSION_TEST_ROOT . '/tests/data/bolt-logo.png'; $fs = new Filesystem(); if (!$fs->exists($tmpDir)) { $fs->mkdir($tmpDir); } $fs->copy($srcFile, "{$tmpDir}/bolt-logo.png", true); $html = $twigExt->twigBoltFormsUploads('testing_form'); $this->assertInstanceOf('\\Twig_Markup', $html); $this->assertRegExp('#<a href="/boltforms/download\\?file=bolt-logo.png">bolt-logo.png</a>#', (string) $html); }