Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitcbr committed May 21, 2024
1 parent ddb24cb commit 9a32a61
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions tests/phpunit/tests/test-instrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ function () {
public function testUpdateCurrentVersion()
{
$this->expectNotToPerformAssertions();

add_option('rzp_woocommerce_current_version', get_plugin_data(__FILE__)['Version']);

$_POST['woocommerce_razorpay_key_id'] = 'key_id';
$_POST['woocommerce_razorpay_key_secret'] = 'key_secret';
$_POST['woocommerce_razorpay_enabled'] = 'yes';
Expand Down Expand Up @@ -248,15 +248,15 @@ public function testInstrumentationDataLakeEmptyProperties()
$this->assertSame('error', $response['status']);
$this->assertSame('properties given as input is not valid', $response['message']);
}

public function testGetDefaultPropertiesWithTimeStamp()
{
$response = $this->instrumentationMock->getDefaultProperties();

$this->assertSame('WordPress', $response['platform']);
$this->assertNotNull($response['platform_version']);
$this->assertNotNull($response['woocommerce_version']);
$this->assertSame('Razorpay for WooCommerce', $response['plugin_name']);
$this->assertSame('1 Razorpay: Signup for FREE PG', $response['plugin_name']);
$this->assertNotNull($response['plugin_version']);
$this->assertNotNull($response['unique_id']);
$this->assertNotNull($response['event_timestamp']);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/test-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public function testMetadata()
{
$pluginData = get_plugin_data(PLUGIN_DIR . '/woo-razorpay.php');

$this->assertSame('Razorpay for WooCommerce', $pluginData['Name']);
$this->assertSame('1 Razorpay: Signup for FREE PG', $pluginData['Name']);

$version = $pluginData['Version'];
$v = explode(".", $version);
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/tests/test-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testReceiptPage()
$this->assertStringContainsString('<button id="btn-razorpay">Pay Now</button>', $result);
$this->assertStringContainsString('<button id="btn-razorpay-cancel" onclick="document.razorpayform.submit()">Cancel</button>', $result);
}

public function testCreateRazorpayOrderId()
{
$order = wc_create_order();
Expand All @@ -133,7 +133,7 @@ public function testCreateRazorpayOrderId()
});
$this->instance->shouldReceive('autoEnableWebhook');

$response = $this->instance->createOrGetRazorpayOrderId($orderId);
$response = $this->instance->createOrGetRazorpayOrderId($order, $orderId);
$this->assertStringContainsString('razorpay_test_id', $response);
}

Expand All @@ -148,10 +148,10 @@ public function testCreateRazorpayOrderIdwitwebhooktime()
$this->instance->shouldReceive('autoEnableWebhook');

add_option('webhook_enable_flag', 2400);
$response = $this->instance->createOrGetRazorpayOrderId($orderId);
$response = $this->instance->createOrGetRazorpayOrderId($order, $orderId);
$this->assertStringContainsString('razorpay_test_id', $response );
}

public function testGetRazorpayOrderId()
{
$order = wc_create_order();
Expand All @@ -164,7 +164,7 @@ public function testGetRazorpayOrderId()
});
$this->instance->shouldReceive('autoEnableWebhook');

$response = $this->instance->createOrGetRazorpayOrderId($orderId);
$response = $this->instance->createOrGetRazorpayOrderId($order, $orderId);
$this->assertStringContainsString('razorpay_test_id', $response);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ function () {
$this->assertStringContainsString("<input type='hidden' name='_[integration_type]' value='plugin'>", $response);
$this->assertStringContainsString("</form>", $response);
}

public function testGetShippingZone()
{
$response = $this->instance->getShippingZone(0);
Expand Down
32 changes: 16 additions & 16 deletions tests/phpunit/tests/test-order-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Test_OrderMethods extends WP_UnitTestCase
{
private $instance;
private $rzpPaymentObj;

public function setup(): void
{
parent::setup();
Expand All @@ -29,11 +29,11 @@ public function setup(): void

$_POST = array();
}

public function testGetRazorpayPaymentParams()
{
{
global $woocommerce;

$order = wc_create_order();

$wcOrderId = $order->get_id();
Expand All @@ -47,11 +47,11 @@ function () {

$razorpayOrderId = $this->instance->shouldReceive('createOrGetRazorpayOrderId')->with($wcOrderId)->andReturn('order_test');

$this->assertEquals(['order_id' => 'order_test'], $this->instance->getRazorpayPaymentParams($wcOrderId));
$this->assertEquals(['order_id' => 'order_test'], $this->instance->getRazorpayPaymentParams($order, $wcOrderId));

//After the webhook flag is set

$this->assertEquals(['order_id' => 'order_test'], $this->instance->getRazorpayPaymentParams($wcOrderId));
$this->assertEquals(['order_id' => 'order_test'], $this->instance->getRazorpayPaymentParams($order, $wcOrderId));


}
Expand All @@ -71,16 +71,16 @@ function () {

$message = 'RAZORPAY ERROR: Razorpay API could not be reached';

try
try
{
$this->instance->getRazorpayPaymentParams($wcOrderId);
$this->instance->getRazorpayPaymentParams($order, $wcOrderId);

$this->fail("Expected Exception has not been raised.");
}
catch (Exception $ex)
catch (Exception $ex)
{
$this->assertEquals($message, $ex->getMessage());
}
}
}

public function testGetCustomOrderCreationMessage()
Expand All @@ -103,11 +103,11 @@ public function testGetDefaultCustomOrderCreationMessage()
$order = wc_create_order();

$defaultmessage = 'Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be processing your order soon.';

$this->instance->shouldReceive('getSetting')->with('order_success_message');

$response = $this->instance->getCustomOrdercreationMessage("", $order);

$this->assertSame($defaultmessage, $response);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public function testGetDefaultCheckoutArguments()
'email' => $order->get_billing_email(),
'contact' => $order->get_billing_phone(),
);

$this->instance->shouldReceive('getOrderSessionKey')->with($orderId)->andReturn($sessionKey);

$response = $this->instance->getDefaultCheckoutArguments($order);
Expand All @@ -167,7 +167,7 @@ public function testGetDefaultCheckoutArguments()

$this->assertSame($args, $response['prefill']);
}

public function testUpdateOrder()
{
global $woocommerce;
Expand Down Expand Up @@ -345,7 +345,7 @@ public function testCheckRazorpayResponse()
$wpdb->insert($wpdb->posts, array('post_status' => 'Pending', 'post_type' => 'shop_order', 'ID' => 22));

$this->instance->shouldReceive('verifySignature');

$this->instance->shouldReceive('redirectUser');

$this->instance->shouldReceive('updateOrder');
Expand Down

0 comments on commit 9a32a61

Please sign in to comment.