diff --git a/includes/EventManager.php b/includes/EventManager.php index 9daf245..594e7a4 100644 --- a/includes/EventManager.php +++ b/includes/EventManager.php @@ -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 ] ); diff --git a/tests/wpunit/includes/EventManagerWPUnitTest.php b/tests/wpunit/includes/EventManagerWPUnitTest.php index f69b615..99d6403 100644 --- a/tests/wpunit/includes/EventManagerWPUnitTest.php +++ b/tests/wpunit/includes/EventManagerWPUnitTest.php @@ -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. * @@ -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( @@ -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(); + } }