| @@ 54-70 (lines=17) @@ | ||
| 51 | * |
|
| 52 | * @covers Automattic\Jetpack\Abtest::get_variation |
|
| 53 | */ |
|
| 54 | public function test_when_test_inactive_or_does_not_exist() { |
|
| 55 | $this->abtest->expects( $this->once() ) |
|
| 56 | ->method( 'request_variation' ) |
|
| 57 | ->willReturn( |
|
| 58 | array( |
|
| 59 | 'body' => json_encode( // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
| 60 | array( |
|
| 61 | 'code' => 'incorrect_test_name', |
|
| 62 | 'message' => 'This A/B test does not exist or is currently inactive.', |
|
| 63 | ) |
|
| 64 | ), |
|
| 65 | ) |
|
| 66 | ); |
|
| 67 | ||
| 68 | $result = $this->abtest->get_variation( 'example_test' ); |
|
| 69 | $this->assertNull( $result ); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * Tests an error or malformed response. |
|
| @@ 77-88 (lines=12) @@ | ||
| 74 | * |
|
| 75 | * @covers Automattic\Jetpack\Abtest::get_variation |
|
| 76 | */ |
|
| 77 | public function test_when_error_or_malformed_response() { |
|
| 78 | $this->abtest->expects( $this->once() ) |
|
| 79 | ->method( 'request_variation' ) |
|
| 80 | ->willReturn( |
|
| 81 | array( |
|
| 82 | 'status' => 500, |
|
| 83 | ) |
|
| 84 | ); |
|
| 85 | ||
| 86 | $result = $this->abtest->get_variation( 'some_test' ); |
|
| 87 | $this->assertNull( $result ); |
|
| 88 | } |
|
| 89 | ||
| 90 | /** |
|
| 91 | * Tests when the response is in an unexpected format. |
|
| @@ 95-110 (lines=16) @@ | ||
| 92 | * |
|
| 93 | * @covers Automattic\Jetpack\Abtest::get_variation |
|
| 94 | */ |
|
| 95 | public function test_when_response_in_unexpected_format() { |
|
| 96 | $this->abtest->expects( $this->once() ) |
|
| 97 | ->method( 'request_variation' ) |
|
| 98 | ->willReturn( |
|
| 99 | array( |
|
| 100 | 'body' => json_encode( // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
| 101 | array( |
|
| 102 | 'foo' => 'bar', |
|
| 103 | ) |
|
| 104 | ), |
|
| 105 | ) |
|
| 106 | ); |
|
| 107 | ||
| 108 | $result = $this->abtest->get_variation( 'some_test' ); |
|
| 109 | $this->assertNull( $result ); |
|
| 110 | } |
|
| 111 | ||
| 112 | /** |
|
| 113 | * Test with an active test. |
|