Skip to content
This repository has been archived by the owner on Sep 22, 2019. It is now read-only.

Commit

Permalink
Add lots of misc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ozh committed Jun 21, 2017
1 parent c04ad1c commit 2fdf014
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/db/misc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* Utilities
*
* @group db
*/

class Misc_DB_Tests extends PHPUnit_Framework_TestCase {

public function test_get_num_queries() {
$num = yourls_get_num_queries();
$this->assertInternalType("int", $num);
}

}
1 change: 0 additions & 1 deletion tests/geoip.php → tests/geoip/geoip.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* YOURLS Unit Tests for the Geolocation API
*
* @group geoip
* @since 0.1
*/

class GeoIP_Tests extends PHPUnit_Framework_TestCase {
Expand Down
94 changes: 94 additions & 0 deletions tests/http/headers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* HTTP redirects and headers
*
* @group http
*/
class HTTP_Headers_Tests extends PHPUnit_Framework_TestCase {

public function todo_some_day_test_redirect() {
// PHP headers are a bitch to test. TODO some day.
}

/**
* Test that we have some javascript redirection output
*/
public function test_javascript_redirect() {
$regexp = '!<script type="text/javascript">\s*window.location="http://somewhere";!m';

$this->expectOutputRegex($regexp);
yourls_redirect_javascript('http://somewhere');
}

public function status_codes() {
return array(
array(100, 'Continue'),
array(101, 'Switching Protocols'),
array(102, 'Processing'),

array(200, 'OK'),
array(201, 'Created'),
array(202, 'Accepted'),
array(203, 'Non-Authoritative Information'),
array(204, 'No Content'),
array(205, 'Reset Content'),
array(206, 'Partial Content'),
array(207, 'Multi-Status'),
array(226, 'IM Used'),

array(300, 'Multiple Choices'),
array(301, 'Moved Permanently'),
array(302, 'Found'),
array(303, 'See Other'),
array(304, 'Not Modified'),
array(305, 'Use Proxy'),
array(306, 'Reserved'),
array(307, 'Temporary Redirect'),

array(400, 'Bad Request'),
array(401, 'Unauthorized'),
array(402, 'Payment Required'),
array(403, 'Forbidden'),
array(404, 'Not Found'),
array(405, 'Method Not Allowed'),
array(406, 'Not Acceptable'),
array(407, 'Proxy Authentication Required'),
array(408, 'Request Timeout'),
array(409, 'Conflict'),
array(410, 'Gone'),
array(411, 'Length Required'),
array(412, 'Precondition Failed'),
array(413, 'Request Entity Too Large'),
array(414, 'Request-URI Too Long'),
array(415, 'Unsupported Media Type'),
array(416, 'Requested Range Not Satisfiable'),
array(417, 'Expectation Failed'),
array(422, 'Unprocessable Entity'),
array(423, 'Locked'),
array(424, 'Failed Dependency'),
array(426, 'Upgrade Required'),

array(500, 'Internal Server Error'),
array(501, 'Not Implemented'),
array(502, 'Bad Gateway'),
array(503, 'Service Unavailable'),
array(504, 'Gateway Timeout'),
array(505, 'HTTP Version Not Supported'),
array(506, 'Variant Also Negotiates'),
array(507, 'Insufficient Storage'),
array(510, 'Not Extended'),
);
}

/**
* @dataProvider status_codes
*/
public function test_get_HTTP_status($code, $status) {
$this->assertSame(yourls_get_HTTP_status($code), $status);
}

public function test_get_HTTP_status_invalid() {
$this->assertSame(yourls_get_HTTP_status(1337), '');
}
}
24 changes: 24 additions & 0 deletions tests/http/misc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Utilities
*
* @group http
*/

class Misc_HTTP_Tests extends PHPUnit_Framework_TestCase {

public function test_get_user_agent() {
$this->assertInternalType("string", yourls_get_user_agent());
}

public function test_get_user_agent_empty() {
$copy = yourls_get_user_agent();
unset($_SERVER['HTTP_USER_AGENT']);

$this->assertSame("-", yourls_get_user_agent());

$_SERVER['HTTP_USER_AGENT'] = $copy;
}

}
15 changes: 15 additions & 0 deletions tests/stats/misc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Stats functions
*
* @group stats
*/

class Misc_Stats_Tests extends PHPUnit_Framework_TestCase {

public function test_do_log_redirect() {
$this->assertInternalType("bool", yourls_do_log_redirect());
}

}
37 changes: 37 additions & 0 deletions tests/utilities/next_decimal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Utilities
*
* @group utils
*/

class NextDecimal_Tests extends PHPUnit_Framework_TestCase {

public function test_get_next_decimal() {
$id = yourls_get_next_decimal();
$this->assertInternalType("int", $id);

return $id;
}

/**
* @depends test_get_next_decimal
*/
public function test_update_next_decimal($id) {
// with no arg
$update = yourls_update_next_decimal();
$this->assertTrue($update);
$next = yourls_get_next_decimal();
$this->assertSame($next, $id + 1);

// with arg
$rand = mt_rand(150,200);
$update = yourls_update_next_decimal($rand);
$this->assertTrue($update);
$next = yourls_get_next_decimal();
$this->assertSame($next, $rand);

}

}

0 comments on commit 2fdf014

Please sign in to comment.