Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Oct 31, 2024
1 parent c2bf163 commit a1d2aad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
36 changes: 36 additions & 0 deletions tests/src/Kernel/EventSubscriber/GoogleAnalyticsSubscriberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Drupal\Tests\stanford_profile_helper\Kernel\EventSubscriber;

use Drupal\google_analytics\Constants\GoogleAnalyticsEvents;
use Drupal\google_analytics\Event\GoogleAnalyticsConfigEvent;
use Drupal\google_analytics\GaAccount;
use Drupal\google_analytics\GaJavascriptObject;
use Drupal\Tests\stanford_profile_helper\Kernel\SuProfileHelperKernelTestBase;

/**
* Test the event subscriber.
*
* @coversDefaultClass \Drupal\stanford_profile_helper\EventSubscriber\GoogleAnalyticsSubscriber
*/
class GoogleAnalyticsSubscriberTest extends SuProfileHelperKernelTestBase {

public function testConfigChanges() {
$config = $this->container->get('config.factory')
->getEditable('google_analytics.settings');
$config->set('account', '');
$config->save();

$account = new GaAccount('');
$javascript = new GaJavascriptObject('');
$ga_config = new GoogleAnalyticsConfigEvent($javascript, $account);
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($ga_config, GoogleAnalyticsEvents::ADD_CONFIG);

$config = $ga_config->getConfig();
$this->assertNotEmpty($config['cookie_domain']);
$this->assertEquals('su', $config['cookie_prefix']);
$this->assertEquals(15552000, $config['cookie_expires']);
}

}
13 changes: 0 additions & 13 deletions tests/src/Kernel/EventSubscriber/test.html

This file was deleted.

1 change: 1 addition & 0 deletions tests/src/Kernel/SuProfileHelperKernelTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class SuProfileHelperKernelTestBase extends KernelTestBase {
'file',
'next',
'menu_link',
'google_analytics',
];

/**
Expand Down

0 comments on commit a1d2aad

Please sign in to comment.