Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/functional/google_analytics_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
*
* Google Analytics extension for the phpBB Forum Software package.
*
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
* @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');

$found = false;

// 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 $key => $config_name)
{
if (strpos($config_name, $this->lang('OVERRIDE_STYLE')) !== 0)
{
continue;
}

$found = true;

$this->assertContainsLang('ACP_GOOGLEANALYTICS_ID', $nodes[$key + 1]);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks that it exists in the expected place, but not necessarily that it exists at all (if OVERRIDE_STYLE isn't found, this test will never execute).


// 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();
$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());
}
}