From b7b0b0ccc3fbf92324948e8c5e616a3e06343600 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 13:43:53 +0200 Subject: [PATCH] [ticket/11538] Make sure group color can't exceed maximum of 6 characters In order to prevent future issues with this, a basic set of functional tests for the UCP groups manage page have been added. PHPBB3-11538 --- phpBB/includes/ucp/ucp_groups.php | 10 +++++ tests/functional/ucp_groups_test.php | 61 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/functional/ucp_groups_test.php diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index d62dbb1866..c1db19774a 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -597,6 +597,16 @@ class ucp_groups if (!sizeof($error)) { + // Make sure maximum length of 6 of group color is not exceeded + if (strpos($submit_ary['colour'], '#') === 0) + { + $submit_ary['colour'] = substr($submit_ary['colour'], 1, 6); + } + else + { + $submit_ary['colour'] = substr($submit_ary['colour'], 0, 6); + } + // Only set the rank, colour, etc. if it's changed or if we're adding a new // group. This prevents existing group members being updated if no changes // were made. diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php new file mode 100644 index 0000000000..010727cb55 --- /dev/null +++ b/tests/functional/ucp_groups_test.php @@ -0,0 +1,61 @@ +login(); + $this->add_lang(array('ucp', 'acp/groups')); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['group_colour']->setValue('#AA0000'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('AA0000', $values['group_colour']); + $form['group_colour']->setValue('AA0000'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('AA0000', $values['group_colour']); + $form['group_colour']->setValue('AA0000v'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('AA0000', $values['group_colour']); + $form['group_colour']->setValue('vAA0000'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('vAA000', $values['group_colour']); + } +}