Source of file AnalyticFunctionalTests.php
Size: 1,745 Bytes - Last Modified: 2021-12-23T10:20:11+00:00
/var/www/docs.ssmods.com/process/src/tests/AnalyticFunctionalTests.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?php namespace Symbiote\Multisites\GoogleAnalytics\Tests; use SilverStripe\Core\Config\Config; use SilverStripe\Control\Director; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Kernel; use Symbiote\Multisites\Model\Site; use Symbiote\Multisites\Multisites; class AnalyticFunctionalTests extends FunctionalTest { protected $usesDatabase = true; public function testAnalyticSnippets() { $_SERVER['HTTP_HOST'] = 'www.site.com'; $this->logInWithPermission(); // Create a site and home page. $site = Site::create( array( 'Title' => 'Site', 'Host' => 'www.site.com', 'GoogleAnalyticsID' => 'UA-TESTING' ) ); $site->writeToStage('Stage'); $site->publishRecursive(); $home = \Page::create( array( 'Title' => 'Home', 'ParentID' => $site->ID ) ); $home->writeToStage('Stage'); $home->publishRecursive(); // The environment needs to be live for the snippets to appear. $kernel = Injector::inst()->get(Kernel::class); $kernel->setEnvironment('live'); // Determine whether the correct snippet was included in the source. $response = $this->get($home->Link()); $this->assertContains("_gaq.push(['_setAccount', 'UA-TESTING']);", $response->getBody()); // Update the site to use universal analytics. $site->GoogleAnalyticsUseUniversalAnalytics = 1; $site->write(); $site->publishRecursive(); // The site object is currently cached, so we need to retrieve it again. Multisites::inst()->resetCurrentSite(); // Determine whether the correct snippet was included in the source. $response = $this->get($site->Link()); $this->assertContains("ga('create', 'UA-TESTING', 'auto');", $response->getBody()); } } |