Skip to content
Snippets Groups Projects
Commit f0a75dbc authored by Demian Katz's avatar Demian Katz
Browse files

Improved test coverage.

parent 572a89be
No related merge requests found
...@@ -46,9 +46,7 @@ class GoogleAnalyticsTest extends \VuFindTest\Unit\ViewHelperTestCase ...@@ -46,9 +46,7 @@ class GoogleAnalyticsTest extends \VuFindTest\Unit\ViewHelperTestCase
*/ */
public function testOldSetup() public function testOldSetup()
{ {
$helper = new GoogleAnalytics('myfakekey', false); $output = $this->renderGA('myfakekey', false);
$helper->setView($this->getPhpRenderer());
$output = $helper()->__toString();
$this->assertTrue(false !== strstr($output, 'ga.js')); $this->assertTrue(false !== strstr($output, 'ga.js'));
$this->assertFalse(strstr($output, 'analytics.js')); $this->assertFalse(strstr($output, 'analytics.js'));
$this->assertTrue(false !== strstr($output, 'myfakekey')); $this->assertTrue(false !== strstr($output, 'myfakekey'));
...@@ -61,11 +59,34 @@ class GoogleAnalyticsTest extends \VuFindTest\Unit\ViewHelperTestCase ...@@ -61,11 +59,34 @@ class GoogleAnalyticsTest extends \VuFindTest\Unit\ViewHelperTestCase
*/ */
public function testNewSetup() public function testNewSetup()
{ {
$helper = new GoogleAnalytics('myfakekey', true); $output = $this->renderGA('myfakekey', true);
$helper->setView($this->getPhpRenderer());
$output = $helper()->__toString();
$this->assertTrue(false !== strstr($output, 'analytics.js')); $this->assertTrue(false !== strstr($output, 'analytics.js'));
$this->assertFalse(strstr($output, 'ga.js')); $this->assertFalse(strstr($output, 'ga.js'));
$this->assertTrue(false !== strstr($output, 'myfakekey')); $this->assertTrue(false !== strstr($output, 'myfakekey'));
} }
/**
* Test the helper (disabled mode)
*
* @return void
*/
public function testDisabled()
{
$this->assertEquals('', $this->renderGA(false));
}
/**
* Render the GA code
*
* @param string $key GA key (false for disabled)
* @param bool $uni Universal mode?
*
* @return string
*/
protected function renderGA($key, $uni = false)
{
$helper = new GoogleAnalytics($key, $uni);
$helper->setView($this->getPhpRenderer());
return (string)$helper();
}
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment