From ff4b78dde5c4c3b2c6bd15d121b7d4d025a7c037 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 3 Aug 2014 10:34:09 -0500 Subject: [PATCH 1/3] Add functional test --- tests/functional/google_analytics_test.php | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/functional/google_analytics_test.php diff --git a/tests/functional/google_analytics_test.php b/tests/functional/google_analytics_test.php new file mode 100644 index 0000000..3acfa94 --- /dev/null +++ b/tests/functional/google_analytics_test.php @@ -0,0 +1,81 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +*/ + +namespace phpbb\googleanalytics\tests\functional; + +/** +* @group functional +*/ +class google_analytics_test extends \phpbb_functional_test_case +{ + protected $sample_ga_code = 'UA-000000-00'; + + /** + * Define the extensions to be tested + * + * @return array vendor/name of extension(s) to test + * @access static + */ + static protected function setup_extensions() + { + return array('phpbb/googleanalytics'); + } + + /** + * Test Google Analytics ACP page and save settings + * + * @access public + */ + public function test_set_acp_settings() + { + $this->login(); + $this->admin_login(); + + // Add language files + $this->add_lang('acp/board'); + $this->add_lang_ext('phpbb/googleanalytics', 'googleanalytics_acp'); + + // Load ACP board settings page + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); + + // Test that GA settings field is found in the correct position (after OVERRIDE_STYLE) + $nodes = $crawler->filter('#acp_board > fieldset > dl > dt > label')->extract(array('_text')); + foreach ($nodes as $config_name) + { + if (strpos($config_name, $this->lang('OVERRIDE_STYLE')) !== 0) + { + continue; + } + + $this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', current($nodes)); + } + + // Set GA form values + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $values['config[googleanalytics_id]'] = $this->sample_ga_code; + $form->setValues($values); + + // Submit form and test success + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + } + + /** + * Test Google Analytics code appears as expected + * + * @access public + */ + public function test_google_analytics_code() + { + $crawler = self::request('GET', 'index.php'); + $this->assertContains($this->sample_ga_code, $crawler->filter('head > script')->text()); + } +} From e5c44fa7329a91f17185d60277b277b7c31c3ad4 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 3 Aug 2014 10:44:58 -0500 Subject: [PATCH 2/3] More clearly test next array value --- tests/functional/google_analytics_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/google_analytics_test.php b/tests/functional/google_analytics_test.php index 3acfa94..02d2845 100644 --- a/tests/functional/google_analytics_test.php +++ b/tests/functional/google_analytics_test.php @@ -47,14 +47,14 @@ public function test_set_acp_settings() // Test that GA settings field is found in the correct position (after OVERRIDE_STYLE) $nodes = $crawler->filter('#acp_board > fieldset > dl > dt > label')->extract(array('_text')); - foreach ($nodes as $config_name) + foreach ($nodes as $key => $config_name) { if (strpos($config_name, $this->lang('OVERRIDE_STYLE')) !== 0) { continue; } - $this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', current($nodes)); + $this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', $nodes[$key + 1]); } // Set GA form values From 3cbbae34878352b848f29e583306f9b7a47c657f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 3 Aug 2014 23:41:12 -0500 Subject: [PATCH 3/3] Extra assertion in case not found where expected --- tests/functional/google_analytics_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/functional/google_analytics_test.php b/tests/functional/google_analytics_test.php index 02d2845..0a09b42 100644 --- a/tests/functional/google_analytics_test.php +++ b/tests/functional/google_analytics_test.php @@ -42,6 +42,8 @@ public function test_set_acp_settings() $this->add_lang('acp/board'); $this->add_lang_ext('phpbb/googleanalytics', 'googleanalytics_acp'); + $found = false; + // Load ACP board settings page $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid); @@ -54,9 +56,17 @@ public function test_set_acp_settings() continue; } + $found = true; + $this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', $nodes[$key + 1]); } + // If GA settings not found where expected, test if they exist on page at all + if (!$found) + { + $this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', $crawler->text()); + } + // Set GA form values $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $values = $form->getValues();