Skip to content

Commit ff4b78d

Browse files
committed
Add functional test
1 parent de6a709 commit ff4b78d

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
*
4+
* Google Analytics extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\googleanalytics\tests\functional;
12+
13+
/**
14+
* @group functional
15+
*/
16+
class google_analytics_test extends \phpbb_functional_test_case
17+
{
18+
protected $sample_ga_code = 'UA-000000-00';
19+
20+
/**
21+
* Define the extensions to be tested
22+
*
23+
* @return array vendor/name of extension(s) to test
24+
* @access static
25+
*/
26+
static protected function setup_extensions()
27+
{
28+
return array('phpbb/googleanalytics');
29+
}
30+
31+
/**
32+
* Test Google Analytics ACP page and save settings
33+
*
34+
* @access public
35+
*/
36+
public function test_set_acp_settings()
37+
{
38+
$this->login();
39+
$this->admin_login();
40+
41+
// Add language files
42+
$this->add_lang('acp/board');
43+
$this->add_lang_ext('phpbb/googleanalytics', 'googleanalytics_acp');
44+
45+
// Load ACP board settings page
46+
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid);
47+
48+
// Test that GA settings field is found in the correct position (after OVERRIDE_STYLE)
49+
$nodes = $crawler->filter('#acp_board > fieldset > dl > dt > label')->extract(array('_text'));
50+
foreach ($nodes as $config_name)
51+
{
52+
if (strpos($config_name, $this->lang('OVERRIDE_STYLE')) !== 0)
53+
{
54+
continue;
55+
}
56+
57+
$this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', current($nodes));
58+
}
59+
60+
// Set GA form values
61+
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
62+
$values = $form->getValues();
63+
$values['config[googleanalytics_id]'] = $this->sample_ga_code;
64+
$form->setValues($values);
65+
66+
// Submit form and test success
67+
$crawler = self::submit($form);
68+
$this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
69+
}
70+
71+
/**
72+
* Test Google Analytics code appears as expected
73+
*
74+
* @access public
75+
*/
76+
public function test_google_analytics_code()
77+
{
78+
$crawler = self::request('GET', 'index.php');
79+
$this->assertContains($this->sample_ga_code, $crawler->filter('head > script')->text());
80+
}
81+
}

0 commit comments

Comments
 (0)