fuck tests

This commit is contained in:
flash 2018-09-16 21:16:17 +02:00
parent b4a4c75904
commit a3fb32f65a
6 changed files with 0 additions and 356 deletions

View file

@ -1,16 +0,0 @@
cache:
directories:
- vendor
language: php
php:
- 7.2
matrix:
fast_finish: true
before_install:
- composer install
script: ./vendor/bin/phpunit

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="misuzu.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Misuzu Tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -1,108 +0,0 @@
<?php
namespace MisuzuTests;
use PHPUnit\Framework\TestCase;
use InvalidArgumentException;
class ColourTest extends TestCase
{
public const RED_HEX6 = 67;
public const GREEN_HEX6 = 45;
public const BLUE_HEX6 = 23;
public const STR_HEX6 = '#432d17';
public const RAW_HEX6 = 4402455;
public const RED_HEX3 = 51;
public const GREEN_HEX3 = 136;
public const BLUE_HEX3 = 221;
public const SSTR_HEX3 = '#38d';
public const STR_HEX3 = '#3388dd';
public const RAW_HEX3 = 3377373;
public function testNone()
{
$colour = colour_none();
$this->assertTrue(colour_get_inherit($colour));
$this->assertEquals($colour, 0x40000000);
$this->assertEquals(colour_get_red($colour), 0);
$this->assertEquals(colour_get_green($colour), 0);
$this->assertEquals(colour_get_blue($colour), 0);
$this->assertEquals(colour_get_hex($colour), '#000000');
$this->assertEquals(colour_get_css($colour), 'inherit');
}
public function testNull()
{
$colour = colour_create();
$this->assertFalse(colour_get_inherit($colour));
$this->assertEquals($colour, 0);
$this->assertEquals(colour_get_red($colour), 0);
$this->assertEquals(colour_get_green($colour), 0);
$this->assertEquals(colour_get_blue($colour), 0);
$this->assertEquals(colour_get_hex($colour), '#000000');
$this->assertEquals(colour_get_css($colour), '#000000');
}
public function testFromRaw()
{
$colour = static::RAW_HEX6;
$this->assertFalse(colour_get_inherit($colour));
$this->assertEquals($colour, static::RAW_HEX6);
$this->assertEquals(colour_get_red($colour), static::RED_HEX6);
$this->assertEquals(colour_get_green($colour), static::GREEN_HEX6);
$this->assertEquals(colour_get_blue($colour), static::BLUE_HEX6);
$this->assertEquals(colour_get_hex($colour), static::STR_HEX6);
$this->assertEquals(colour_get_css($colour), static::STR_HEX6);
}
public function testFromRGB()
{
$colour = colour_create();
colour_from_rgb($colour, static::RED_HEX6, static::GREEN_HEX6, static::BLUE_HEX6);
$this->assertFalse(colour_get_inherit($colour));
$this->assertEquals($colour, static::RAW_HEX6);
$this->assertEquals(colour_get_red($colour), static::RED_HEX6);
$this->assertEquals(colour_get_green($colour), static::GREEN_HEX6);
$this->assertEquals(colour_get_blue($colour), static::BLUE_HEX6);
$this->assertEquals(colour_get_hex($colour), static::STR_HEX6);
$this->assertEquals(colour_get_css($colour), static::STR_HEX6);
}
public function testFromHex()
{
$colour = colour_create();
colour_from_hex($colour, static::STR_HEX6);
$this->assertFalse(colour_get_inherit($colour));
$this->assertEquals($colour, static::RAW_HEX6);
$this->assertEquals(colour_get_red($colour), static::RED_HEX6);
$this->assertEquals(colour_get_green($colour), static::GREEN_HEX6);
$this->assertEquals(colour_get_blue($colour), static::BLUE_HEX6);
$this->assertEquals(colour_get_hex($colour), static::STR_HEX6);
$this->assertEquals(colour_get_css($colour), static::STR_HEX6);
}
public function testFromHex3()
{
$colour = colour_create();
colour_from_hex($colour, static::SSTR_HEX3);
$this->assertFalse(colour_get_inherit($colour));
$this->assertEquals($colour, static::RAW_HEX3);
$this->assertEquals(colour_get_red($colour), static::RED_HEX3);
$this->assertEquals(colour_get_green($colour), static::GREEN_HEX3);
$this->assertEquals(colour_get_blue($colour), static::BLUE_HEX3);
$this->assertEquals(colour_get_hex($colour), static::STR_HEX3);
$this->assertEquals(colour_get_css($colour), static::STR_HEX3);
}
public function testHexException()
{
$colour = colour_create();
$this->assertFalse(colour_from_hex($colour, 'invalid hex code'));
}
}

View file

@ -1,170 +0,0 @@
<?php
namespace MisuzuTests;
use PHPUnit\Framework\TestCase;
use Misuzu\Net\IPAddress;
use Misuzu\Net\IPAddressRange;
class IPAddressTest extends TestCase
{
public function testVersion()
{
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromString('127.0.0.1'));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromRaw(hex2bin('7f000001')));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromString('104.27.135.189'));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromRaw(hex2bin('681b87bd')));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromString('104.27.154.200'));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromRaw(hex2bin('681b9ac8')));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromString('104.28.9.4'));
$this->assertEquals(IPAddress::V4, IPAddress::detectVersionFromRaw(hex2bin('681c0904')));
$this->assertEquals(IPAddress::V6, IPAddress::detectVersionFromString('::1'));
$this->assertEquals(
IPAddress::V6,
IPAddress::detectVersionFromRaw(hex2bin('00000000000000000000000000000001'))
);
$this->assertEquals(IPAddress::V6, IPAddress::detectVersionFromString('2400:cb00:2048:1:0:0:681b:9ac8'));
$this->assertEquals(
IPAddress::V6,
IPAddress::detectVersionFromRaw(hex2bin('2400cb002048000100000000681b9ac8'))
);
$this->assertEquals(IPAddress::V6, IPAddress::detectVersionFromString('2400:cb00:2048:1:0:0:681c:804'));
$this->assertEquals(
IPAddress::V6,
IPAddress::detectVersionFromRaw(hex2bin('2400cb002048000100000000681c0804'))
);
$this->assertEquals(IPAddress::V6, IPAddress::detectVersionFromString('2400:cb00:2048:1:0:0:681b:86bd'));
$this->assertEquals(
IPAddress::V6,
IPAddress::detectVersionFromRaw(hex2bin('2400cb002048000100000000681b86bd'))
);
$this->assertEquals(IPAddress::V6, IPAddress::detectVersionFromString('2400:cb00:2048:1:0:0:681f:5e2a'));
$this->assertEquals(
IPAddress::V6,
IPAddress::detectVersionFromRaw(hex2bin('2400cb002048000100000000681f5e2a'))
);
$this->assertEquals(IPAddress::UNKNOWN_VERSION, IPAddress::detectVersionFromString('not an ip address'));
$this->assertEquals(IPAddress::UNKNOWN_VERSION, IPAddress::detectVersionFromString('256.256.256.256'));
$this->assertEquals(IPAddress::UNKNOWN_VERSION, IPAddress::detectVersionFromRaw('invalid'));
}
public function testString()
{
$this->assertEquals(hex2bin('7f000001'), IPAddress::fromString('127.0.0.1')->getRaw());
$this->assertEquals(hex2bin('681b87bd'), IPAddress::fromString('104.27.135.189')->getRaw());
$this->assertEquals(hex2bin('681b9ac8'), IPAddress::fromString('104.27.154.200')->getRaw());
$this->assertEquals(hex2bin('681c0904'), IPAddress::fromString('104.28.9.4')->getRaw());
$this->assertEquals(
hex2bin('00000000000000000000000000000001'),
IPAddress::fromString('::1')->getRaw()
);
$this->assertEquals(
hex2bin('2400cb002048000100000000681b9ac8'),
IPAddress::fromString('2400:cb00:2048:1:0:0:681b:9ac8')->getRaw()
);
$this->assertEquals(
hex2bin('2400cb002048000100000000681c0804'),
IPAddress::fromString('2400:cb00:2048:1:0:0:681c:804')->getRaw()
);
$this->assertEquals(
hex2bin('2400cb002048000100000000681b86bd'),
IPAddress::fromString('2400:cb00:2048:1:0:0:681b:86bd')->getRaw()
);
$this->assertEquals(
hex2bin('2400cb002048000100000000681f5e2a'),
IPAddress::fromString('2400:cb00:2048:1:0:0:681f:5e2a')->getRaw()
);
}
public function testRaw()
{
$this->assertEquals('127.0.0.1', IPAddress::fromRaw(hex2bin('7f000001'))->getString());
$this->assertEquals('104.27.135.189', IPAddress::fromRaw(hex2bin('681b87bd'))->getString());
$this->assertEquals('104.27.154.200', IPAddress::fromRaw(hex2bin('681b9ac8'))->getString());
$this->assertEquals('104.28.9.4', IPAddress::fromRaw(hex2bin('681c0904'))->getString());
$this->assertEquals(
'::1',
IPAddress::fromRaw(hex2bin('00000000000000000000000000000001'))->getString()
);
$this->assertEquals(
IPAddress::fromRaw(hex2bin('2400cb002048000100000000681b9ac8'))->getString(),
'2400:cb00:2048:1::681b:9ac8'
);
$this->assertEquals(
'2400:cb00:2048:1::681c:804',
IPAddress::fromRaw(hex2bin('2400cb002048000100000000681c0804'))->getString()
);
$this->assertEquals(
'2400:cb00:2048:1::681b:86bd',
IPAddress::fromRaw(hex2bin('2400cb002048000100000000681b86bd'))->getString()
);
$this->assertEquals(
'2400:cb00:2048:1::681f:5e2a',
IPAddress::fromRaw(hex2bin('2400cb002048000100000000681f5e2a'))->getString()
);
}
public function testCompare()
{
$v4_start = IPAddress::fromString('117.0.0.255');
$v4_end = IPAddress::fromString('127.0.0.255');
$v6_start = IPAddress::fromString('::1');
$v6_end = IPAddress::fromString('::FFFF');
$this->assertEquals(1, $v4_start->compareTo($v4_end));
$this->assertEquals(-1, $v4_end->compareTo($v4_start));
$this->assertEquals(0, $v4_start->compareTo($v4_start));
$this->assertEquals(0, $v4_end->compareTo($v4_end));
$this->assertEquals(1, $v6_start->compareTo($v6_end));
$this->assertEquals(-1, $v6_end->compareTo($v6_start));
$this->assertEquals(0, $v6_start->compareTo($v6_start));
$this->assertEquals(0, $v6_end->compareTo($v6_end));
}
public function testMaskedRange()
{
$range_v4 = IPAddressRange::fromMaskedString('127.0.0.1/8');
$this->assertEquals('127.0.0.1', $range_v4->getMaskAddress()->getString());
$this->assertEquals(8, $range_v4->getCidrLength());
$this->assertEquals('127.0.0.1/8', $range_v4->getMaskedString());
$range_v6 = IPAddressRange::fromMaskedString('::1/16');
$this->assertEquals('::1', $range_v6->getMaskAddress()->getString());
$this->assertEquals(16, $range_v6->getCidrLength());
$this->assertEquals('::1/16', $range_v6->getMaskedString());
}
// excellent naming
public function testRangedRange()
{
$range_v4 = IPAddressRange::fromRangeString('255.255.255.248-255.255.255.255');
$this->assertEquals('255.255.255.248', $range_v4->getMaskAddress()->getString());
$this->assertEquals(29, $range_v4->getCidrLength());
$range_v6 = IPAddressRange::fromRangeString('2400:cb00:2048:1::681b:86bd-2400:cb00:2048:1::681f:5e2a');
$this->assertEquals('2400:cb00:2048:1::6818:0', $range_v6->getMaskAddress()->getString());
$this->assertEquals(109, $range_v6->getCidrLength());
}
public function testMatchRange()
{
$range_v4 = new IPAddressRange(IPAddress::fromString('108.162.192.0'), 18);
$this->assertTrue($range_v4->match(IPAddress::fromString('108.162.255.255')));
$this->assertFalse($range_v4->match(IPAddress::fromString('127.0.0.1')));
$range_v6 = new IPAddressRange(IPAddress::fromString('2a06:98c0::'), 29);
$this->assertTrue($range_v6->match(IPAddress::fromString('2a06:98c7:7f:43:645:ab:cd:2525')));
$this->assertFalse($range_v6->match(IPAddress::fromString('::1')));
}
}

View file

@ -1,18 +0,0 @@
<?php
namespace MisuzuTests;
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
public function testUsernameValidation()
{
$this->assertEquals(user_validate_username('flashwave'), '');
$this->assertEquals(user_validate_username(' flash '), 'trim');
$this->assertEquals(user_validate_username('f'), 'short');
$this->assertEquals(user_validate_username('flaaaaaaaaaaaaaaaash'), 'long');
$this->assertEquals(user_validate_username('F|@$h'), 'invalid');
$this->assertEquals(user_validate_username('fl ash_wave'), 'spacing');
$this->assertEquals(user_validate_username('fl ash'), 'double-spaces');
}
}

View file

@ -1,27 +0,0 @@
<?php
namespace MisuzuTests;
use PHPUnit\Framework\TestCase;
class ZalgoTest extends TestCase
{
public const TEST_STRING = 'This string will be put through the Zalgo function, and back to a regular string.';
public function testStrip()
{
$this->assertEquals(
static::TEST_STRING,
zalgo_strip(zalgo_run(static::TEST_STRING, MSZ_ZALGO_MODE_MINI))
);
$this->assertEquals(
static::TEST_STRING,
zalgo_strip(zalgo_run(static::TEST_STRING, MSZ_ZALGO_MODE_NORMAL))
);
$this->assertEquals(
static::TEST_STRING,
zalgo_strip(zalgo_run(static::TEST_STRING, MSZ_ZALGO_MODE_MAX))
);
}
}