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') 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