Initial commit
This commit is contained in:
31
tests/AuthPlainTest.php
Normal file
31
tests/AuthPlainTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Pdahal\Xmpp\AuthTypes\Plain;
|
||||
use Pdahal\Xmpp\Options;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class AuthPlainTest extends TestCase
|
||||
{
|
||||
public Plain $plainAuth;
|
||||
|
||||
public Options $optionsStub;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->optionsStub = $this->createMock(Options::class);
|
||||
$this->optionsStub->method('getUsername')->willReturn('Foo');
|
||||
$this->optionsStub->method('getPassword')->willReturn('Bar');
|
||||
|
||||
$this->plainAuth = new Plain($this->optionsStub);
|
||||
}
|
||||
|
||||
public function testIfCredentialsAreEncodedRight(): void
|
||||
{
|
||||
$this->assertEquals('AEZvbwBCYXI=', $this->plainAuth->encodedCredentials());
|
||||
}
|
||||
}
|
26
tests/DigestMD5Test.php
Normal file
26
tests/DigestMD5Test.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Pdahal\Xmpp\AuthTypes\DigestMD5;
|
||||
use Pdahal\Xmpp\Options;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DigestMD5Test extends TestCase
|
||||
{
|
||||
public DigestMD5 $digestAuth;
|
||||
|
||||
public Options $optionsStub;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->optionsStub = $this->createMock(Options::class);
|
||||
$this->optionsStub->method('getUsername')->willReturn('Foo');
|
||||
$this->optionsStub->method('getPassword')->willReturn('Bar');
|
||||
|
||||
$this->digestAuth = new DigestMD5($this->optionsStub);
|
||||
}
|
||||
|
||||
public function testIfCredentialsAreEncodedRight(): void
|
||||
{
|
||||
$this->assertEquals("80e25ae4140c338afbe621c1b3d7a9ec9480f731", $this->digestAuth->encodedCredentials());
|
||||
}
|
||||
}
|
124
tests/OptionsTest.php
Normal file
124
tests/OptionsTest.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
use Pdahal\Xmpp\Options;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class OptionsTest extends TestCase
|
||||
{
|
||||
protected $host;
|
||||
protected $port;
|
||||
protected $username;
|
||||
protected $password;
|
||||
|
||||
public Options $options;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->host = 'www.host.com';
|
||||
$this->username = 'foo';
|
||||
$this->password = 'bar';
|
||||
$this->port = 5222;
|
||||
$this->options = new Options();
|
||||
|
||||
$this->options
|
||||
->setHost($this->host)
|
||||
->setPort($this->port)
|
||||
->setUsername($this->username)
|
||||
->setPassword($this->password)
|
||||
;
|
||||
}
|
||||
|
||||
public function testIfNoHostThrowsError(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->options->setHost('');
|
||||
$this->options->getHost();
|
||||
}
|
||||
|
||||
public function testIfNoUsernameThrowsError(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->options->setUsername('');
|
||||
$this->options->getUsername();
|
||||
}
|
||||
|
||||
public function testIfNoPasswordThrowsError(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->options->setPassword('');
|
||||
$this->options->getPassword();
|
||||
}
|
||||
|
||||
public function testIfHostGetsTrimmed(): void
|
||||
{
|
||||
$this->options->setHost(' host');
|
||||
$this->assertEquals('host', $this->options->getHost());
|
||||
|
||||
$this->options->setHost('host ');
|
||||
$this->assertEquals('host', $this->options->getHost());
|
||||
|
||||
$this->options->setHost(' host ');
|
||||
$this->assertEquals('host', $this->options->getHost());
|
||||
}
|
||||
|
||||
public function testIfUsernameSplitResource(): void
|
||||
{
|
||||
$this->options->setUsername('user/resource');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
|
||||
$this->options->setUsername('user');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
|
||||
$this->options->setUsername('user/resource/resource2/resource3');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
}
|
||||
|
||||
public function testResourcePrecedence(): void
|
||||
{
|
||||
$this->options->setUsername('user/resource');
|
||||
$this->options->setResource('resource2');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource2', $this->options->getResource());
|
||||
|
||||
$this->options->setResource('resource2');
|
||||
$this->options->setUsername('user/resource');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
}
|
||||
|
||||
public function testIfResourceGetsTrimmed(): void
|
||||
{
|
||||
$this->options->setResource(' resource');
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
|
||||
$this->options->setResource('resource ');
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
|
||||
$this->options->setResource(' resource ');
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
}
|
||||
|
||||
public function testFullSocketAddress(): void
|
||||
{
|
||||
$this->assertEquals('tcp://www.host.com:5222', $this->options->fullSocketAddress());
|
||||
}
|
||||
|
||||
public function testFullJid(): void
|
||||
{
|
||||
$this->options->setResource('resource');
|
||||
$this->assertEquals('foo@www.host.com/resource', $this->options->fullJid());
|
||||
}
|
||||
|
||||
public function testBareJid(): void
|
||||
{
|
||||
$this->assertEquals('foo@www.host.com', $this->options->bareJid());
|
||||
}
|
||||
}
|
70
tests/ResponseBufferTest.php
Normal file
70
tests/ResponseBufferTest.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use Pdahal\Xmpp\Buffers\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class ResponseBufferTest extends TestCase
|
||||
{
|
||||
public Response $buffer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->buffer = new Response();
|
||||
}
|
||||
|
||||
public function testWriteString(): void
|
||||
{
|
||||
$this->buffer->write('test');
|
||||
$this->assertEquals(['test'], $this->buffer->getCurrentBufferData());
|
||||
}
|
||||
|
||||
public function testWriteNumber(): void
|
||||
{
|
||||
$this->buffer->write(123);
|
||||
$this->assertEquals(['123'], $this->buffer->getCurrentBufferData());
|
||||
}
|
||||
|
||||
public function testWriteEmpty(): void
|
||||
{
|
||||
$this->buffer->write('');
|
||||
$this->assertEquals([], $this->buffer->getCurrentBufferData());
|
||||
}
|
||||
|
||||
public function testWriteNull(): void
|
||||
{
|
||||
$this->buffer->write(null);
|
||||
$this->assertEquals([], $this->buffer->getCurrentBufferData());
|
||||
}
|
||||
|
||||
public function testRead(): void
|
||||
{
|
||||
$this->buffer->write('test');
|
||||
$response = $this->buffer->read();
|
||||
$this->assertEquals('test', $response);
|
||||
}
|
||||
|
||||
public function testReadNullInput(): void
|
||||
{
|
||||
$this->buffer->write(null);
|
||||
$response = $this->buffer->read();
|
||||
$this->assertEquals('', $response);
|
||||
}
|
||||
|
||||
public function testFlushWithInput(): void
|
||||
{
|
||||
$this->buffer->write('test');
|
||||
$this->buffer->read();
|
||||
$this->assertEquals([], $this->buffer->getCurrentBufferData());
|
||||
}
|
||||
|
||||
public function testFlushWithoutInput(): void
|
||||
{
|
||||
$this->buffer->read();
|
||||
$this->assertEquals([], $this->buffer->getCurrentBufferData());
|
||||
}
|
||||
}
|
16
tests/XmlTest.php
Normal file
16
tests/XmlTest.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Pdahal\Xmpp\Xml\Xml;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class XmlTest extends TestCase
|
||||
{
|
||||
use Xml;
|
||||
public $host = 'www.test.com';
|
||||
|
||||
public function testOpeningStream(): void
|
||||
{
|
||||
$expected = "<?xml version='1.0' encoding='UTF-8'?><stream:stream to='www.test.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' version='1.0'>";
|
||||
$this->assertEquals($expected, $this->openXmlStream($this->host));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user