Skip to content

Commit

Permalink
Merge pull request #104 from newfold-labs/fix-queue
Browse files Browse the repository at this point in the history
Add `page_view` to disabled events
  • Loading branch information
BrianHenryIE authored Oct 18, 2024
2 parents e5c949a + d1f82fc commit 961fe52
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion includes/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function add_minutely_schedule( $schedules ) {
public function shutdown(): void {

// Due to a bug sending too many events, we are temporarily disabling these.
$disabled_events = array( 'pageview', 'wp_mail', 'plugin_updated' );
$disabled_events = array( 'pageview', 'page_view', 'wp_mail', 'plugin_updated' );
foreach ( $this->queue as $index => $event ) {
if ( in_array( $event->key, $disabled_events, true ) ) {
unset( $this->queue[ $index ] );
Expand Down
38 changes: 37 additions & 1 deletion tests/wpunit/includes/EventManagerWPUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
* @coversDefaultClass \NewfoldLabs\WP\Module\Data\EventManager
*/
class EventManagerWPUnitTest extends \lucatume\WPBrowser\TestCase\WPTestCase {

protected function tearDown(): void {
parent::tearDown();
\Mockery::close();
}

/**
* 2.6.0 was released with a bug where an empty array was passed to the Queue to be saved, causing a fatal error.
*
Expand All @@ -33,7 +39,7 @@ public function test_empty_response_from_hiive(): void {
$sut->push( $event );

$hiive_connection = Mockery::mock( HiiveConnection::class );
$hiive_connection->expects('notify' )
$hiive_connection->expects( 'notify' )
->once()
->andReturn(
array(
Expand All @@ -46,4 +52,34 @@ public function test_empty_response_from_hiive(): void {

$sut->shutdown();
}

public static function does_not_send_certain_events_dataprovider(): array {
return array(
array( 'pageview' ),
array( 'page_view' ),
array( 'wp_mail' ),
array( 'plugin_updated' ),
);
}

/**
* @dataProvider does_not_send_certain_events_dataprovider
*/
public function test_does_not_send_certain_events( string $event_name ): void {
$sut = new EventManager();

$event = Mockery::mock( Event::class );
$event->category = 'admin';
$event->key = $event_name;
$event->data = array();

$sut->push( $event );

$hiive_connection = Mockery::mock( HiiveConnection::class );
$hiive_connection->shouldReceive( 'notify' )->never();

$sut->add_subscriber( $hiive_connection );

$sut->shutdown();
}
}

0 comments on commit 961fe52

Please sign in to comment.