Skip to content

Commit 5e3f98a

Browse files
committed
Merge pull request #19 from VSEphpbb/testing
Add functional test
2 parents de6a709 + 3cbbae3 commit 5e3f98a

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
$found = false;
46+
47+
// Load ACP board settings page
48+
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=settings&sid=' . $this->sid);
49+
50+
// Test that GA settings field is found in the correct position (after OVERRIDE_STYLE)
51+
$nodes = $crawler->filter('#acp_board > fieldset > dl > dt > label')->extract(array('_text'));
52+
foreach ($nodes as $key => $config_name)
53+
{
54+
if (strpos($config_name, $this->lang('OVERRIDE_STYLE')) !== 0)
55+
{
56+
continue;
57+
}
58+
59+
$found = true;
60+
61+
$this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', $nodes[$key + 1]);
62+
}
63+
64+
// If GA settings not found where expected, test if they exist on page at all
65+
if (!$found)
66+
{
67+
$this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', $crawler->text());
68+
}
69+
70+
// Set GA form values
71+
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
72+
$values = $form->getValues();
73+
$values['config[googleanalytics_id]'] = $this->sample_ga_code;
74+
$form->setValues($values);
75+
76+
// Submit form and test success
77+
$crawler = self::submit($form);
78+
$this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
79+
}
80+
81+
/**
82+
* Test Google Analytics code appears as expected
83+
*
84+
* @access public
85+
*/
86+
public function test_google_analytics_code()
87+
{
88+
$crawler = self::request('GET', 'index.php');
89+
$this->assertContains($this->sample_ga_code, $crawler->filter('head > script')->text());
90+
}
91+
}

0 commit comments

Comments
 (0)