Skip to content

Commit

Permalink
Fix updated formidable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolap994 committed Dec 9, 2024
1 parent 707e001 commit 5f4cd52
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions __tests__/integration/FacebookWordpressFormidableFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,36 @@
final class FacebookWordpressFormidableFormTest
extends FacebookWordpressTestBase {

public function testInjectPixelCode() {
public function testInjectLeadEventWithoutInternalUser() {
self::mockIsInternalUser(false);
self::mockFacebookWordpressOptions();

\WP_Mock::expectActionAdded(
'frm_after_create_entry',
array(
'FacebookPixelPlugin\\Integration\\FacebookWordpressFormidableForm',
'trackServerEvent'
),
20,
2);

FacebookWordpressFormidableForm::injectPixelCode();
}
\WP_Mock::userFunction(
'sanitize_text_field',
array(
'args' => array( \Mockery::any() ),
'return' => function ( $input ) {
return $input;
},
)
);

public function testInjectLeadEventWithoutInternalUser() {
self::mockIsInternalUser(false);
self::mockFacebookWordpressOptions();
$event = ServerEventFactory::new_event('Lead');

\WP_Mock::userFunction(
'wp_json_encode',
array(
'args' => array(
\Mockery::type( 'array' ),
\Mockery::type( 'int' ),
),
'return' => function ( $data, $options ) {
return json_encode( $data );
},
)
);

$event = ServerEventFactory::newEvent('Lead');
FacebookServerSideEvent::getInstance()->track($event);
FacebookServerSideEvent::get_instance()->track($event);

FacebookWordpressFormidableForm::injectLeadEvent();

Expand All @@ -73,6 +81,16 @@ public function testTrackEventWithoutInternalUser() {
self::mockIsInternalUser(false);
self::mockFacebookWordpressOptions();

\WP_Mock::userFunction(
'sanitize_text_field',
array(
'args' => array( \Mockery::any() ),
'return' => function ( $input ) {
return $input;
},
)
);

$mock_entry_id = 1;
$mock_form_id = 1;

Expand All @@ -92,7 +110,7 @@ public function testTrackEventWithoutInternalUser() {
$mock_entry_id, $mock_form_id);

$tracked_events =
FacebookServerSideEvent::getInstance()->getTrackedEvents();
FacebookServerSideEvent::get_instance()->get_tracked_events();

$this->assertCount(1, $tracked_events);

Expand Down Expand Up @@ -144,7 +162,7 @@ private static function setupErrorForm($entry_id) {

$mock_utils = \Mockery::mock(
'alias:FacebookPixelPlugin\Integration\IntegrationUtils');
$mock_utils->shouldReceive('getFormidableFormsEntryValues')->with($entry_id)->andReturn($entry_values);
$mock_utils->shouldReceive('get_formidable_forms_entry_values')->with($entry_id)->andReturn($entry_values);
}

private static function setupMockFormidableForm($entry_id) {
Expand Down Expand Up @@ -184,6 +202,6 @@ private static function setupMockFormidableForm($entry_id) {

$mock_utils = \Mockery::mock(
'alias:FacebookPixelPlugin\Integration\IntegrationUtils');
$mock_utils->shouldReceive('getFormidableFormsEntryValues')->with($entry_id)->andReturn($entry_values);
$mock_utils->shouldReceive('get_formidable_forms_entry_values')->with($entry_id)->andReturn($entry_values);
}
}

0 comments on commit 5f4cd52

Please sign in to comment.