Skip to content

Commit

Permalink
Add test coverage for get_gtag_src.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfmohit committed Mar 26, 2024
1 parent 70341cc commit 1ee2a8a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/phpunit/integration/Core/Tags/GTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,21 @@ public function test_gtag_with_tag_config() {
$this->assertEquals( 'gtag("config", "' . static::TEST_TAG_ID_2 . '", ' . json_encode( self::TEST_TAG_ID_2_CONFIG ) . ');', $script->extra['after'][6] );
}

public function test_get_gtag_src() {
$this->assertEquals( 'https://www.googletagmanager.com/gtag/js?id=' . static::TEST_TAG_ID_1, $this->gtag->get_gtag_src() );

// Reset the GTag instance.
$this->gtag = new GTag();
$this->gtag->register();

// Verify that this returns `false` when no tags are added.
$this->assertFalse( $this->gtag->get_gtag_src() );

// Add a different tag ID.
$this->gtag->add_tag( static::TEST_TAG_ID_2 );

// Verify that this returns the correct URL for the different tag ID.
$this->assertEquals( 'https://www.googletagmanager.com/gtag/js?id=' . static::TEST_TAG_ID_2, $this->gtag->get_gtag_src() );
}

}

0 comments on commit 1ee2a8a

Please sign in to comment.