From 8e55eafd89c4818b3058d5c8df6dbead2c41a1fb Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 2 Aug 2016 10:29:25 +0200 Subject: [PATCH] fixing "risky" unit tests --- tst/jsonApi.php | 10 ++++++++++ tst/privatebin.php | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tst/jsonApi.php b/tst/jsonApi.php index 69ec82e6..d45f1db5 100644 --- a/tst/jsonApi.php +++ b/tst/jsonApi.php @@ -44,6 +44,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertStringEndsWith('?' . $response['id'], $response['url'], 'returned URL points to new paste'); @@ -78,6 +79,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertEquals(helper::getPasteId(), $response['id'], 'outputted paste ID matches input'); @@ -111,6 +113,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted'); @@ -135,6 +138,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted'); @@ -153,6 +157,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs success status'); $this->assertEquals(helper::getPasteId(), $response['id'], 'outputs data correctly'); @@ -179,6 +184,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertEquals(str_replace( '?jsonld=', '/?jsonld=', @@ -198,6 +204,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertEquals(str_replace( '?jsonld=', '/?jsonld=', @@ -217,6 +224,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertEquals(str_replace( '?jsonld=', '/?jsonld=', @@ -236,6 +244,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertEquals(str_replace( '?jsonld=', '/?jsonld=', @@ -255,6 +264,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertEquals('{}', $content, 'does not output nasty data'); } diff --git a/tst/privatebin.php b/tst/privatebin.php index 78774f46..852ccc4c 100644 --- a/tst/privatebin.php +++ b/tst/privatebin.php @@ -35,6 +35,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertContains( 'PrivateBin', $content, @@ -61,6 +62,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertContains( 'PrivateBin', $content, @@ -83,6 +85,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertContains( 'PrivateBin', $content, @@ -105,6 +108,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#', $content, @@ -166,6 +170,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -195,6 +200,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -224,6 +230,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -247,6 +254,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -276,6 +284,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -301,6 +310,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -333,6 +343,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -364,6 +375,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -393,6 +405,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -416,6 +429,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -440,6 +454,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -478,6 +493,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -500,6 +516,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -523,6 +540,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); @@ -555,6 +573,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after posting data'); @@ -580,6 +599,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), $response['id']), 'paste exists after posting data'); @@ -605,6 +625,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data'); @@ -631,6 +652,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data'); @@ -655,6 +677,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data'); @@ -682,6 +705,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs error status'); $this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data'); @@ -698,6 +722,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertContains( '#', $content, @@ -734,6 +760,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, @@ -753,6 +780,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, @@ -772,6 +800,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); unset($burnPaste['meta']['salt']); $this->assertContains( '#', $content, @@ -927,6 +962,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, @@ -946,6 +982,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#]*id="errormessage"[^>]*>.*Wrong deletion token[^<]*#', $content, @@ -970,6 +1007,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted'); @@ -990,6 +1028,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $response = json_decode($content, true); $this->assertEquals(1, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste successfully deleted'); @@ -1010,6 +1049,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, @@ -1033,6 +1073,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase ob_start(); new privatebin; $content = ob_get_contents(); + ob_end_clean(); $this->assertRegExp( '#]*id="status"[^>]*>.*Paste was properly deleted[^<]*#s', $content,