From 5b96b5fce7283ebd52f88ef6daa3c8233a7df1ec Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 7 May 2012 10:39:49 -0400 Subject: [ticket/10837] Removed tearDownAfterClass() from extension_controller_test.php PHPBB3-10837 --- tests/functional/extension_controller_test.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 4ee0e68718..e9409d9d3f 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -65,15 +65,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } } - public static function tearDownAfterClass() - { - $phpbb_root_path = self::$config['phpbb_functional_path']; - - // @todo delete the fixtures from the $phpbb_root_path board - // Note that it might be best to find a public domain function - // and port it into here instead of writing it from scratch - } - public function setUp() { parent::setUp(); -- cgit v1.2.1 From 5693036bf9237ad54e62425faf6ab16907cc7ea9 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Fri, 22 Jun 2012 18:39:02 +0100 Subject: [ticket/10941] Added functional tests for the fileupload class NOTE: test_form_upload() is broken. Uploading files via Symfony fails to retain $_FILES['fileupload']['type'] even if it set explicitely. This appears to be a bug in Symfony. Since the current version of filespec::is_image() relies on the mimetype, these tests will __fail__. filespec::is_image() has been fixed in https://github.com/phpbb/phpbb3/pull/833 however. PHPBB3-10941 --- tests/functional/fileupload_test.php | 86 +++++++++++++++++++++ tests/functional/fixtures/files/empty.png | 0 .../fixtures/files/illegal-extension.bif | Bin 0 -> 519 bytes tests/functional/fixtures/files/too-large.png | Bin 0 -> 284717 bytes tests/functional/fixtures/files/valid.jpg | Bin 0 -> 554 bytes 5 files changed, 86 insertions(+) create mode 100644 tests/functional/fileupload_test.php create mode 100644 tests/functional/fixtures/files/empty.png create mode 100644 tests/functional/fixtures/files/illegal-extension.bif create mode 100644 tests/functional/fixtures/files/too-large.png create mode 100644 tests/functional/fixtures/files/valid.jpg (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php new file mode 100644 index 0000000000..ff62bad7bd --- /dev/null +++ b/tests/functional/fileupload_test.php @@ -0,0 +1,86 @@ +add_lang('posting'); + $this->login(); + + // Test 1: Invalid extension + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'illegal-extension.bif'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('p.error')->count()); + + // Test 2: Empty file + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'empty.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('p.error')->count()); + + // Test 3: File too large + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'too-large.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('div#message')->count()); + + // Test 4: Valid file + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'valid.jpg'); + $crawler = $this->client->submit($form); + $this->assertEquals(0, $crawler->filter('p.error')->count()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); + } + + public function test_remote_upload() + { + // Only doing this within the functional framework because we need a + // URL + global $config; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + // Test 1: Invalid extension + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.gif'); + $this->assertEquals(1, sizeof($file->error)); + + // Test 2: Non-existant file + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.jpg'); + $this->assertEquals(1, sizeof($file->error)); + + // Test 3: File too large + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(1, sizeof($file->error)); + + // Test 4: Successful upload + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } +} diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bif new file mode 100644 index 0000000000..3cd5038e38 Binary files /dev/null and b/tests/functional/fixtures/files/illegal-extension.bif differ diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.png new file mode 100644 index 0000000000..ed4b0abd80 Binary files /dev/null and b/tests/functional/fixtures/files/too-large.png differ diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpg new file mode 100644 index 0000000000..95a87ddbdf Binary files /dev/null and b/tests/functional/fixtures/files/valid.jpg differ -- cgit v1.2.1 From 1233544c4a280e4392af448df654b5263e8c35db Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 25 Jun 2012 00:23:02 +0100 Subject: [ticket/10941] Marked broken test as incomplete PHPBB3-10941 --- tests/functional/fileupload_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index ff62bad7bd..c06f7d94d7 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -14,6 +14,7 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case { public function test_form_upload() { + $this->markTestIncomplete(); $path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); $this->login(); -- cgit v1.2.1 From 82ca2c8b08ca8c21b358ee8c862c639a5944977d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 30 Jun 2012 10:41:54 +0100 Subject: [ticket/10941] Minor adjustments as per PR comments Added some comments clarifying globals and lowercased fixture filenames PHPBB3-10941 --- tests/functional/fileupload_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index c06f7d94d7..bbcc0c37c9 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -51,8 +51,14 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case public function test_remote_upload() { + // Note: we cannot check for the actual value of the error messages + // since they are passed through the translator which will result in + // blank strings within this test framework. + // Only doing this within the functional framework because we need a // URL + + // Global $config required by unique_id global $config; if (!is_array($config)) @@ -83,5 +89,7 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->filename)); + + $config = array(); } } -- cgit v1.2.1 From 59a7b10f1471ccd652d152578b6d027dcbc3fa7f Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 2 Jul 2012 22:44:33 +0100 Subject: [ticket/10941] Added a comment explaining the incomplete test PHPBB3-10941 --- tests/functional/fileupload_test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index bbcc0c37c9..1c40041cc5 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -14,7 +14,13 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case { public function test_form_upload() { + // This test is marked as incomplete due to an apparent bug in the + // symfony framework which causes it to lose the mimetype of any file + // uploaded. Since filespec::is_image() relies on the mimetype, all + // image uploads fail. filespec::is_image() is fixed in: + // https://github.com/phpbb/phpbb3/pull/833 $this->markTestIncomplete(); + $path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); $this->login(); -- cgit v1.2.1 From 19405a7f47ea6d63eaf1cde3053c6b158c7b4dba Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 00:32:50 +0100 Subject: [ticket/10941] Now actually checks for the value of errors. Uses phpbb_mock_lang to return the key used when setting errors to allow that key to be checked for during tests rather than just checking if any error was set. PHPBB3-10941 --- tests/functional/fileupload_test.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index 1c40041cc5..ee89836c45 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -57,15 +57,12 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case public function test_remote_upload() { - // Note: we cannot check for the actual value of the error messages - // since they are passed through the translator which will result in - // blank strings within this test framework. - // Only doing this within the functional framework because we need a // URL // Global $config required by unique_id - global $config; + // Global $user required by fileupload::remote_upload + global $config, $user; if (!is_array($config)) { @@ -75,20 +72,23 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; + $user = new phpbb_mock_user(); + $user->lang = new phpbb_mock_lang(); + // Test 1: Invalid extension $upload = new fileupload('', array('jpg'), 100); $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('URL_INVALID',$file->error[0]); // Test 2: Non-existant file $upload = new fileupload('', array('jpg'), 100); $file = $upload->remote_upload('http://example.com/image.jpg'); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); // Test 3: File too large $upload = new fileupload('', array('gif'), 100); $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); // Test 4: Successful upload $upload = new fileupload('', array('gif'), 1000); @@ -97,5 +97,6 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $this->assertTrue(file_exists($file->filename)); $config = array(); + $user = null; } } -- cgit v1.2.1 From 61d74007a4b728f67c672561a8dd907e64de3070 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 02:03:26 +0100 Subject: [ticket/10941] Minor typo fixes Removed superfluous $user = null; that was left over from refactoring. PHPBB3-10941 --- tests/functional/fileupload_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index ee89836c45..44bb22da8f 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -78,7 +78,7 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case // Test 1: Invalid extension $upload = new fileupload('', array('jpg'), 100); $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals('URL_INVALID',$file->error[0]); + $this->assertEquals('URL_INVALID', $file->error[0]); // Test 2: Non-existant file $upload = new fileupload('', array('jpg'), 100); -- cgit v1.2.1 From a4717ef525969427aac77eb077f28ee2d587126c Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 00:46:09 +0100 Subject: [ticket/10941] Removed the incomplete mark as is_image is fixed Had to remove one of the tests due to a small limitation with the functional testing framework. May mark the test as incomplete again pending further comments. PHPBB3-10941 --- tests/functional/fileupload_test.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index 44bb22da8f..2abf81c457 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -14,13 +14,6 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case { public function test_form_upload() { - // This test is marked as incomplete due to an apparent bug in the - // symfony framework which causes it to lose the mimetype of any file - // uploaded. Since filespec::is_image() relies on the mimetype, all - // image uploads fail. filespec::is_image() is fixed in: - // https://github.com/phpbb/phpbb3/pull/833 - $this->markTestIncomplete(); - $path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); $this->login(); @@ -30,21 +23,23 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'illegal-extension.bif'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('p.error')->count()); + $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); // Test 2: Empty file $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'empty.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('p.error')->count()); + $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); // Test 3: File too large - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + // Cannot be tested by an admin account which this functional framework + // provides + /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'too-large.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count()); + $this->assertEquals(1, $crawler->filter('div#message')->count());*/ // Test 4: Valid file $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); -- cgit v1.2.1 From b65f08dd95de07405ed7f19fd980ca7d09925406 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 01:22:26 +0100 Subject: [ticket/10941] Rearranged tests into their own classes or methods PHPBB3-10941 --- tests/functional/fileupload_test.php | 97 ----------------------------- tests/functional/fileupload_test_form.php | 62 ++++++++++++++++++ tests/functional/fileupload_test_remote.php | 71 +++++++++++++++++++++ 3 files changed, 133 insertions(+), 97 deletions(-) delete mode 100644 tests/functional/fileupload_test.php create mode 100644 tests/functional/fileupload_test_form.php create mode 100644 tests/functional/fileupload_test_remote.php (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php deleted file mode 100644 index 2abf81c457..0000000000 --- a/tests/functional/fileupload_test.php +++ /dev/null @@ -1,97 +0,0 @@ -add_lang('posting'); - $this->login(); - - // Test 1: Invalid extension - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'illegal-extension.bif'); - $crawler = $this->client->submit($form); - $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); - - // Test 2: Empty file - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'empty.png'); - $crawler = $this->client->submit($form); - $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); - - // Test 3: File too large - // Cannot be tested by an admin account which this functional framework - // provides - /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'too-large.png'); - $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count());*/ - - // Test 4: Valid file - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'valid.jpg'); - $crawler = $this->client->submit($form); - $this->assertEquals(0, $crawler->filter('p.error')->count()); - $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); - } - - public function test_remote_upload() - { - // Only doing this within the functional framework because we need a - // URL - - // Global $config required by unique_id - // Global $user required by fileupload::remote_upload - global $config, $user; - - if (!is_array($config)) - { - $config = array(); - } - - $config['rand_seed'] = ''; - $config['rand_seed_last_update'] = time() + 600; - - $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); - - // Test 1: Invalid extension - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals('URL_INVALID', $file->error[0]); - - // Test 2: Non-existant file - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.jpg'); - $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); - - // Test 3: File too large - $upload = new fileupload('', array('gif'), 100); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals('WRONG_FILESIZE', $file->error[0]); - - // Test 4: Successful upload - $upload = new fileupload('', array('gif'), 1000); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals(0, sizeof($file->error)); - $this->assertTrue(file_exists($file->filename)); - - $config = array(); - $user = null; - } -} diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php new file mode 100644 index 0000000000..48fa75ca4b --- /dev/null +++ b/tests/functional/fileupload_test_form.php @@ -0,0 +1,62 @@ +path = __DIR__ . '/fixtures/files/'; + $this->add_lang('posting'); + $this->login(); + } + + public function test_empty_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'empty.png'); + $crawler = $this->client->submit($form); + $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); + } + + public function test_invalid_extension() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'illegal-extension.bif'); + $crawler = $this->client->submit($form); + $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); + } + + public function test_too_large() + { + // Cannot be tested by an admin account which this functional framework + // provides + /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'too-large.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('div#message')->count());*/ + } + + public function test_valid_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'valid.jpg'); + $crawler = $this->client->submit($form); + $this->assertEquals(0, $crawler->filter('p.error')->count()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); + } +} diff --git a/tests/functional/fileupload_test_remote.php b/tests/functional/fileupload_test_remote.php new file mode 100644 index 0000000000..ac55a078d4 --- /dev/null +++ b/tests/functional/fileupload_test_remote.php @@ -0,0 +1,71 @@ +lang = new phpbb_mock_lang(); + } + + protected function tearDown() + { + global $config, $user; + $user = null; + $config = array(); + } + + public function test_invalid_extension() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.gif'); + $this->assertEquals('URL_INVALID', $file->error[0]); + } + + public function test_non_existant() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.jpg'); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); + } + + public function test_successful_upload() + { + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } + + public function test_too_large() + { + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } +} -- cgit v1.2.1 From 9f3a02d4755409407a26bf75324ac0a8a15d87e2 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 00:10:41 +0100 Subject: [ticket/10941] Removed manual includes of mock classes Also marked a test as incomplete even though this appears to be ignored when actually running the tests. PHPBB3-10941 --- tests/functional/fileupload_test_form.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php index 48fa75ca4b..87979e6a68 100644 --- a/tests/functional/fileupload_test_form.php +++ b/tests/functional/fileupload_test_form.php @@ -43,11 +43,12 @@ class phpbb_functional_fileupload_test_form extends phpbb_functional_test_case { // Cannot be tested by an admin account which this functional framework // provides - /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $this->markTestIncomplete(); + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'too-large.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count());*/ + $this->assertEquals(1, $crawler->filter('div#message')->count()); } public function test_valid_file() -- cgit v1.2.1 From 6a1c686025067bc570921bf2618415a2f284b647 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 00:36:03 +0100 Subject: [ticket/10941] Moved comment into markTestIncomplete parameter PHPBB3-10941 --- tests/functional/fileupload_test_form.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php index 87979e6a68..2413cd01d2 100644 --- a/tests/functional/fileupload_test_form.php +++ b/tests/functional/fileupload_test_form.php @@ -41,9 +41,7 @@ class phpbb_functional_fileupload_test_form extends phpbb_functional_test_case public function test_too_large() { - // Cannot be tested by an admin account which this functional framework - // provides - $this->markTestIncomplete(); + $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'too-large.png'); -- cgit v1.2.1 From e0b63df6a4bb7d039e414ac3548ac9fb2e3a8358 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:18:04 +0100 Subject: [ticket/10941] Renamed classes and filenames so that tests run Also fixed some minor issues that weren't flagged before because the tests were being ignored. PHPBB3-10941 --- tests/functional/fileupload_form_test.php | 62 +++++++++++++++++++++++++ tests/functional/fileupload_remote_test.php | 72 +++++++++++++++++++++++++++++ tests/functional/fileupload_test_form.php | 61 ------------------------ tests/functional/fileupload_test_remote.php | 71 ---------------------------- 4 files changed, 134 insertions(+), 132 deletions(-) create mode 100644 tests/functional/fileupload_form_test.php create mode 100644 tests/functional/fileupload_remote_test.php delete mode 100644 tests/functional/fileupload_test_form.php delete mode 100644 tests/functional/fileupload_test_remote.php (limited to 'tests/functional') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php new file mode 100644 index 0000000000..3e1ba71a71 --- /dev/null +++ b/tests/functional/fileupload_form_test.php @@ -0,0 +1,62 @@ +path = __DIR__ . '/fixtures/files/'; + $this->add_lang('posting'); + $this->login(); + } + + public function test_empty_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'empty.png'); + $crawler = $this->client->submit($form); + $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); + } + + public function test_invalid_extension() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'illegal-extension.bif'); + $crawler = $this->client->submit($form); + $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); + } + + public function test_too_large() + { + $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'too-large.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('div#message')->count()); + } + + public function test_valid_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'valid.jpg'); + $crawler = $this->client->submit($form); + $this->assertEquals(0, $crawler->filter('p.error')->count()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); + } +} diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php new file mode 100644 index 0000000000..0deb79acf6 --- /dev/null +++ b/tests/functional/fileupload_remote_test.php @@ -0,0 +1,72 @@ +lang = new phpbb_mock_lang(); + } + + public function tearDown() + { + global $config, $user; + $user = null; + $config = array(); + } + + public function test_invalid_extension() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.gif'); + $this->assertEquals('URL_INVALID', $file->error[0]); + } + + public function test_non_existant() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.jpg'); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); + } + + public function test_successful_upload() + { + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } + + public function test_too_large() + { + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } +} diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php deleted file mode 100644 index 2413cd01d2..0000000000 --- a/tests/functional/fileupload_test_form.php +++ /dev/null @@ -1,61 +0,0 @@ -path = __DIR__ . '/fixtures/files/'; - $this->add_lang('posting'); - $this->login(); - } - - public function test_empty_file() - { - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($this->path . 'empty.png'); - $crawler = $this->client->submit($form); - $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); - } - - public function test_invalid_extension() - { - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($this->path . 'illegal-extension.bif'); - $crawler = $this->client->submit($form); - $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); - } - - public function test_too_large() - { - $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'too-large.png'); - $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count()); - } - - public function test_valid_file() - { - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($this->path . 'valid.jpg'); - $crawler = $this->client->submit($form); - $this->assertEquals(0, $crawler->filter('p.error')->count()); - $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); - } -} diff --git a/tests/functional/fileupload_test_remote.php b/tests/functional/fileupload_test_remote.php deleted file mode 100644 index ac55a078d4..0000000000 --- a/tests/functional/fileupload_test_remote.php +++ /dev/null @@ -1,71 +0,0 @@ -lang = new phpbb_mock_lang(); - } - - protected function tearDown() - { - global $config, $user; - $user = null; - $config = array(); - } - - public function test_invalid_extension() - { - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals('URL_INVALID', $file->error[0]); - } - - public function test_non_existant() - { - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.jpg'); - $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); - } - - public function test_successful_upload() - { - $upload = new fileupload('', array('gif'), 1000); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals(0, sizeof($file->error)); - $this->assertTrue(file_exists($file->filename)); - } - - public function test_too_large() - { - $upload = new fileupload('', array('gif'), 100); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals('WRONG_FILESIZE', $file->error[0]); - } -} -- cgit v1.2.1 From 8d43a6e851bb6caceed6ab3b8a66ffb106c7317d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:24:29 +0100 Subject: [ticket/10941] Replaced use of English with language system PHPBB3-10941 --- tests/functional/fileupload_form_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 3e1ba71a71..abccd6f987 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -28,7 +28,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($this->path . 'empty.png'); $crawler = $this->client->submit($form); - $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); + $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text()); } public function test_invalid_extension() @@ -37,7 +37,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($this->path . 'illegal-extension.bif'); $crawler = $this->client->submit($form); - $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); + $this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text()); } public function test_too_large() -- cgit v1.2.1 From c8059cf7e70ab19f0fad21a7d42d1720392883a7 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:29:56 +0100 Subject: [ticket/10941] Fixed form test test_too_large PHPBB3-10941 --- tests/functional/fileupload_form_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/functional') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index abccd6f987..6ba55eeba7 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -45,9 +45,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'too-large.png'); + $form['fileupload']->upload($this->path . 'too-large.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count()); + $this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text()); } public function test_valid_file() -- cgit v1.2.1