| @@ 15-68 (lines=54) @@ | ||
| 12 | /** |
|
| 13 | * Basic tests to get_url method. |
|
| 14 | */ |
|
| 15 | public function test_get_url() { |
|
| 16 | ||
| 17 | $url = Redirect::get_url( 'simple' ); |
|
| 18 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
|
| 19 | ||
| 20 | // Test invalid parameter. |
|
| 21 | $url = Redirect::get_url( 'simple', array( 'invalid' => 'value' ) ); |
|
| 22 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
|
| 23 | ||
| 24 | // Test path. |
|
| 25 | $url = Redirect::get_url( 'simple', array( 'path' => 'value' ) ); |
|
| 26 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=value', $url ); |
|
| 27 | ||
| 28 | // Test path special chars. |
|
| 29 | $url = Redirect::get_url( 'simple', array( 'path' => 'weird value!' ) ); |
|
| 30 | $v = rawurlencode( 'weird value!' ); |
|
| 31 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=' . $v, $url ); |
|
| 32 | ||
| 33 | // Test query. |
|
| 34 | $url = Redirect::get_url( 'simple', array( 'query' => 'value' ) ); |
|
| 35 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=value', $url ); |
|
| 36 | ||
| 37 | // Test query special chars. |
|
| 38 | $url = Redirect::get_url( 'simple', array( 'query' => 'key=value&key2=value2' ) ); |
|
| 39 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 40 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=' . $v, $url ); |
|
| 41 | ||
| 42 | // Test anchor. |
|
| 43 | $url = Redirect::get_url( 'simple', array( 'anchor' => 'value' ) ); |
|
| 44 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=value', $url ); |
|
| 45 | ||
| 46 | // Test anchor special chars. |
|
| 47 | $url = Redirect::get_url( 'simple', array( 'anchor' => 'key=value&key2=value2' ) ); |
|
| 48 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 49 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=' . $v, $url ); |
|
| 50 | ||
| 51 | // Test informing URL. |
|
| 52 | $url = Redirect::get_url( 'https://wordpress.com/support' ); |
|
| 53 | $v = rawurlencode( 'https://wordpress.com/support' ); |
|
| 54 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v . '&site=example.org', $url ); |
|
| 55 | ||
| 56 | // Test URL and query. |
|
| 57 | $url = Redirect::get_url( 'https://wordpress.com/support', array( 'query' => 'key=value&key2=value2' ) ); |
|
| 58 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 59 | $v_url = rawurlencode( 'https://wordpress.com/support' ); |
|
| 60 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
|
| 61 | ||
| 62 | // Test URL and query, discarding info from url. |
|
| 63 | $url = Redirect::get_url( 'https://wordpress.com/support?this=that#super', array( 'query' => 'key=value&key2=value2' ) ); |
|
| 64 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 65 | $v_url = rawurlencode( 'https://wordpress.com/support' ); |
|
| 66 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
|
| 67 | ||
| 68 | } |
|
| 69 | ||
| 70 | } |
|
| 71 | ||
| @@ 15-68 (lines=54) @@ | ||
| 12 | /** |
|
| 13 | * Basic tests to get_url method. |
|
| 14 | */ |
|
| 15 | public function test_get_url() { |
|
| 16 | ||
| 17 | $url = Soft_Wp::get_url( 'simple' ); |
|
| 18 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
|
| 19 | ||
| 20 | // Test invalid parameter. |
|
| 21 | $url = Soft_Wp::get_url( 'simple', array( 'invalid' => 'value' ) ); |
|
| 22 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org', $url ); |
|
| 23 | ||
| 24 | // Test path. |
|
| 25 | $url = Soft_Wp::get_url( 'simple', array( 'path' => 'value' ) ); |
|
| 26 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=value', $url ); |
|
| 27 | ||
| 28 | // Test path special chars. |
|
| 29 | $url = Soft_Wp::get_url( 'simple', array( 'path' => 'weird value!' ) ); |
|
| 30 | $v = rawurlencode( 'weird value!' ); |
|
| 31 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&path=' . $v, $url ); |
|
| 32 | ||
| 33 | // Test query. |
|
| 34 | $url = Soft_Wp::get_url( 'simple', array( 'query' => 'value' ) ); |
|
| 35 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=value', $url ); |
|
| 36 | ||
| 37 | // Test query special chars. |
|
| 38 | $url = Soft_Wp::get_url( 'simple', array( 'query' => 'key=value&key2=value2' ) ); |
|
| 39 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 40 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&query=' . $v, $url ); |
|
| 41 | ||
| 42 | // Test anchor. |
|
| 43 | $url = Soft_Wp::get_url( 'simple', array( 'anchor' => 'value' ) ); |
|
| 44 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=value', $url ); |
|
| 45 | ||
| 46 | // Test anchor special chars. |
|
| 47 | $url = Soft_Wp::get_url( 'simple', array( 'anchor' => 'key=value&key2=value2' ) ); |
|
| 48 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 49 | $this->assertEquals( 'https://jetpack.com/redirect?source=simple&site=example.org&anchor=' . $v, $url ); |
|
| 50 | ||
| 51 | // Test informing URL. |
|
| 52 | $url = Soft_Wp::get_url( 'https://wordpress.com/support' ); |
|
| 53 | $v = rawurlencode( 'https://wordpress.com/support' ); |
|
| 54 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v . '&site=example.org', $url ); |
|
| 55 | ||
| 56 | // Test URL and query. |
|
| 57 | $url = Soft_Wp::get_url( 'https://wordpress.com/support', array( 'query' => 'key=value&key2=value2' ) ); |
|
| 58 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 59 | $v_url = rawurlencode( 'https://wordpress.com/support' ); |
|
| 60 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
|
| 61 | ||
| 62 | // Test URL and query, discarding info from url. |
|
| 63 | $url = Soft_Wp::get_url( 'https://wordpress.com/support?this=that#super', array( 'query' => 'key=value&key2=value2' ) ); |
|
| 64 | $v = rawurlencode( 'key=value&key2=value2' ); |
|
| 65 | $v_url = rawurlencode( 'https://wordpress.com/support' ); |
|
| 66 | $this->assertEquals( 'https://jetpack.com/redirect?url=' . $v_url . '&site=example.org&query=' . $v, $url ); |
|
| 67 | ||
| 68 | } |
|
| 69 | ||
| 70 | public function test_options() { |
|
| 71 | Soft_Wp::store( 'testing', 123 ); |
|