-
Notifications
You must be signed in to change notification settings - Fork 22
Add functional test #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]); | ||
| } | ||
|
|
||
| // 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()); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).