Skip to content

Commit 4632999

Browse files
committed
Merge branch 'brendo-master'
Validation of return and cancel urls from @brendo, with unit tests. Closes #70
2 parents 4a9ebab + 5a76b1c commit 4632999

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/PayPal/Api/RedirectUrls.php

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class RedirectUrls extends PPModel
2323
*/
2424
public function setReturnUrl($return_url)
2525
{
26+
if(filter_var($return_url, FILTER_VALIDATE_URL) === false)
27+
{
28+
throw new \InvalidArgumentException("Return URL is not a fully qualified URL");
29+
}
30+
2631
$this->return_url = $return_url;
2732

2833
return $this;
@@ -79,6 +84,10 @@ public function getReturn_url()
7984
*/
8085
public function setCancelUrl($cancel_url)
8186
{
87+
if(filter_var($cancel_url, FILTER_VALIDATE_URL) === false)
88+
{
89+
throw new \InvalidArgumentException("Cancel URL is not a fully qualified URL");
90+
}
8291
$this->cancel_url = $cancel_url;
8392

8493
return $this;
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
namespace PayPal\Test\Api;
3+
4+
use PayPal\Api\RedirectUrls;
5+
6+
class RedirectUrlsTest extends \PHPUnit_Framework_TestCase {
7+
8+
public function validRedirectUrlsProvider() {
9+
return array(
10+
array('https://devtools-paypal.com/guide/pay_paypal/php?success=true', 'https://devtools-paypal.com/guide/pay_paypal/php?cancel=true')
11+
);
12+
}
13+
14+
public function invalidRedirectUrlsProvider() {
15+
return array(
16+
array('devtools-paypal.com/guide/pay_paypal/php?success=true', 'devtools-paypal.com/guide/pay_paypal/php?cancel=true')
17+
);
18+
}
19+
20+
/**
21+
* @dataProvider validRedirectUrlsProvider
22+
*/
23+
public function testValidRedirectUrls($return_url, $cancel_url) {
24+
$redirectUrls = new RedirectUrls();
25+
$redirectUrls->setReturn_url($return_url);
26+
$redirectUrls->setCancel_url($cancel_url);
27+
28+
$this->assertEquals($return_url, $redirectUrls->getReturnUrl());
29+
$this->assertEquals($cancel_url, $redirectUrls->getCancelUrl());
30+
}
31+
32+
/**
33+
* @dataProvider invalidRedirectUrlsProvider
34+
*/
35+
public function testInvalidRedirectUrls($return_url, $cancel_url) {
36+
$redirectUrls = new RedirectUrls();
37+
$this->setExpectedException('\InvalidArgumentException');
38+
$redirectUrls->setReturnUrl($return_url);
39+
$redirectUrls->setCancelUrl($cancel_url);
40+
}
41+
42+
}

0 commit comments

Comments
 (0)