2018-12-21 14:51:58 +00:00
|
|
|
<?php
|
2019-02-16 17:51:24 +00:00
|
|
|
|
2019-01-08 15:14:42 +00:00
|
|
|
namespace ActivityPub\Test\Utils;
|
2018-12-21 14:51:58 +00:00
|
|
|
|
2019-02-07 03:48:00 +00:00
|
|
|
use ActivityPub\Test\TestConfig\APTestCase;
|
2019-02-16 17:51:24 +00:00
|
|
|
use ActivityPub\Utils\Util;
|
2018-12-21 14:51:58 +00:00
|
|
|
|
2019-02-07 03:48:00 +00:00
|
|
|
class UtilTest extends APTestCase
|
2018-12-21 14:51:58 +00:00
|
|
|
{
|
|
|
|
public function testItFindsAssocArray()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo' => 'bar' );
|
|
|
|
$isAssoc = Util::isAssoc( $arr );
|
|
|
|
$this->assertTrue( $isAssoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItReturnsFalseForNonAssoc()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo', 'bar' );
|
|
|
|
$isAssoc = Util::isAssoc( $arr );
|
|
|
|
$this->assertFalse( $isAssoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItHandlesMixedArray()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo' => 'bar', 'baz' );
|
|
|
|
$isAssoc = Util::isAssoc( $arr );
|
|
|
|
$this->assertTrue( $isAssoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItChecksEmptyArrayIsAssoc()
|
|
|
|
{
|
|
|
|
$arr = array();
|
|
|
|
$isAssoc = Util::isAssoc( $arr );
|
|
|
|
$this->assertFalse( $isAssoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testArrayKeysExist()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo' => 'bar', 'baz' => 'qux' );
|
|
|
|
$keys = array( 'foo', 'baz' );
|
|
|
|
$keysExist = Util::arrayKeysExist( $arr, $keys );
|
|
|
|
$this->assertTrue( $keysExist );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItChecksForAllKeys()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo' => 'bar' );
|
|
|
|
$keys = array( 'foo', 'baz' );
|
|
|
|
$keysExist = Util::arrayKeysExist( $arr, $keys );
|
|
|
|
$this->assertFalse( $keysExist );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItAllowsExtraKeys()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo' => 'bar', 'baz' => 'qux' );
|
|
|
|
$keys = array( 'foo' );
|
|
|
|
$keysExist = Util::arrayKeysExist( $arr, $keys );
|
|
|
|
$this->assertTrue( $keysExist );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItHandlesEmptyArray()
|
|
|
|
{
|
|
|
|
$arr = array();
|
|
|
|
$keys = array( 'foo' );
|
|
|
|
$keysExist = Util::arrayKeysExist( $arr, $keys );
|
|
|
|
$this->assertFalse( $keysExist );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItHandlesEmptyKeys()
|
|
|
|
{
|
|
|
|
$arr = array( 'foo' => 'bar', 'baz' => 'qux' );
|
|
|
|
$keys = array();
|
|
|
|
$keysExist = Util::arrayKeysExist( $arr, $keys );
|
|
|
|
$this->assertTrue( $keysExist );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItHandlesBothEmpty()
|
|
|
|
{
|
|
|
|
$arr = array();
|
|
|
|
$keys = array();
|
|
|
|
$keysExist = Util::arrayKeysExist( $arr, $keys );
|
|
|
|
$this->assertTrue( $keysExist );
|
|
|
|
}
|
|
|
|
}
|
2019-02-07 03:48:00 +00:00
|
|
|
|