aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2013-10-11 17:40:16 +0200
committerAndreas Fischer <bantu@phpbb.com>2013-10-11 17:40:16 +0200
commit2050a39da793b9ed219beed868ec86ebade423f6 (patch)
tree78d20feb7ccc0a0230653aac1518272328d157a5 /tests/functional
parent659236a32f58946a501d3fb9f04ba83ed91ef369 (diff)
downloadforums-2050a39da793b9ed219beed868ec86ebade423f6.tar
forums-2050a39da793b9ed219beed868ec86ebade423f6.tar.gz
forums-2050a39da793b9ed219beed868ec86ebade423f6.tar.bz2
forums-2050a39da793b9ed219beed868ec86ebade423f6.tar.xz
forums-2050a39da793b9ed219beed868ec86ebade423f6.zip
[feature/plupload/integration] Integration of Plupload
This commit is a highly-refactored and up-to-date version of Fyorl's work which was part of his Google Summer of Code 2012 project "Attachment Improvements". PHPBB3-10929
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/fileupload_form_test.php19
-rw-r--r--tests/functional/plupload_test.php149
2 files changed, 168 insertions, 0 deletions
diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php
index 998c402fa3..ad01d7b2df 100644
--- a/tests/functional/fileupload_form_test.php
+++ b/tests/functional/fileupload_form_test.php
@@ -22,6 +22,25 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
$this->login();
}
+ public function tearDown()
+ {
+ $iterator = new DirectoryIterator(__DIR__ . '/../../phpBB/files/');
+ foreach ($iterator as $fileinfo)
+ {
+ if (
+ $fileinfo->isDot()
+ || $fileinfo->isDir()
+ || $fileinfo->getFilename() === 'index.htm'
+ || $fileinfo->getFilename() === '.htaccess'
+ )
+ {
+ continue;
+ }
+
+ unlink($fileinfo->getPathname());
+ }
+ }
+
private function upload_file($filename, $mimetype)
{
$file = array(
diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php
new file mode 100644
index 0000000000..6dd9224839
--- /dev/null
+++ b/tests/functional/plupload_test.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+/**
+ * @group functional
+ */
+class phpbb_functional_plupload_test extends phpbb_functional_test_case
+{
+ const CHUNKS = 4;
+ private $path;
+
+ protected function set_extension_group_permission($val)
+ {
+ $db = $this->get_db();
+ $query = "
+ UPDATE phpbb_extension_groups
+ SET allow_in_pm = '$val'
+ WHERE group_name = 'IMAGES'
+ ";
+ $db->sql_query($query);
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->set_extension_group_permission(1);
+ $this->path = __DIR__ . '/fixtures/files/';
+ $this->add_lang('posting');
+ $this->login();
+ }
+
+ public function tearDown()
+ {
+ $this->set_extension_group_permission(0);
+ $iterator = new DirectoryIterator(__DIR__ . '/../../phpBB/files/');
+ foreach ($iterator as $fileinfo)
+ {
+ if (
+ $fileinfo->isDot()
+ || $fileinfo->isDir()
+ || $fileinfo->getFilename() === 'index.htm'
+ || $fileinfo->getFilename() === '.htaccess'
+ )
+ {
+ continue;
+ }
+
+ unlink($fileinfo->getPathname());
+ }
+ }
+
+ public function get_urls()
+ {
+ return array(
+ array('posting.php?mode=reply&f=2&t=1'),
+ array('ucp.php?i=pm&mode=compose'),
+ );
+ }
+
+ /**
+ * @dataProvider get_urls
+ */
+ public function test_chunked_upload($url)
+ {
+ $chunk_size = ceil(filesize($this->path . 'valid.jpg') / self::CHUNKS);
+ $handle = fopen($this->path . 'valid.jpg', 'rb');
+
+ for ($i = 0; $i < self::CHUNKS; $i++)
+ {
+ $chunk = fread($handle, $chunk_size);
+ file_put_contents($this-> path . 'chunk', $chunk);
+
+ $file = array(
+ 'tmp_name' => $this->path . 'chunk',
+ 'name' => 'blob',
+ 'type' => 'application/octet-stream',
+ 'size' => strlen($chunk),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ self::$client->setServerParameter('HTTP_X_PHPBB_USING_PLUPLOAD', '1');
+
+ $crawler = self::$client->request(
+ 'POST',
+ $url . '&sid=' . $this->sid,
+ array(
+ 'chunk' => $i,
+ 'chunks' => self::CHUNKS,
+ 'name' => md5('valid') . '.jpg',
+ 'real_filename' => 'valid.jpg',
+ 'add_file' => $this->lang('ADD_FILE'),
+ ),
+ array('fileupload' => $file),
+ array('X-PHPBB-USING-PLUPLOAD' => '1')
+ );
+
+ if ($i < self::CHUNKS - 1)
+ {
+ $this->assertContains('{"jsonrpc":"2.0","id":"id","result":null}', self::$client->getResponse()->getContent());
+ }
+ else
+ {
+ $response = json_decode(self::$client->getResponse()->getContent(), true);
+ $this->assertEquals('valid.jpg', $response[0]['real_filename']);
+ }
+
+ unlink($this->path . 'chunk');
+ }
+
+ fclose($handle);
+ }
+
+ /**
+ * @dataProvider get_urls
+ */
+ public function test_normal_upload($url)
+ {
+ $file = array(
+ 'tmp_name' => $this->path . 'valid.jpg',
+ 'name' => 'valid.jpg',
+ 'type' => 'image/jpeg',
+ 'size' => filesize($this->path . 'valid.jpg'),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $crawler = self::$client->request(
+ 'POST',
+ $url . '&sid=' . $this->sid,
+ array(
+ 'chunk' => '0',
+ 'chunks' => '1',
+ 'name' => md5('valid') . '.jpg',
+ 'real_filename' => 'valid.jpg',
+ 'add_file' => $this->lang('ADD_FILE'),
+ ),
+ array('fileupload' => $file),
+ array('X-PHPBB-USING-PLUPLOAD' => '1')
+ );
+
+ $response = json_decode(self::$client->getResponse()->getContent(), true);
+ $this->assertEquals('valid.jpg', $response[0]['real_filename']);
+ }
+}