File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ class RedirectUrls extends PPModel
23
23
*/
24
24
public function setReturnUrl ($ return_url )
25
25
{
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
+
26
31
$ this ->return_url = $ return_url ;
27
32
28
33
return $ this ;
@@ -79,6 +84,10 @@ public function getReturn_url()
79
84
*/
80
85
public function setCancelUrl ($ cancel_url )
81
86
{
87
+ if (filter_var ($ cancel_url , FILTER_VALIDATE_URL ) === false )
88
+ {
89
+ throw new \InvalidArgumentException ("Cancel URL is not a fully qualified URL " );
90
+ }
82
91
$ this ->cancel_url = $ cancel_url ;
83
92
84
93
return $ this ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments