Вход Регистрация
Файл: gapps/vendor/swiftmailer/swiftmailer/tests/unit/Swift/CharacterStream/ArrayCharacterStreamTest.php
Строк: 385
<?php

class Swift_CharacterStream_ArrayCharacterStreamTest extends SwiftMailerTestCase
{
    public function 
testValidatorAlgorithmOnImportString()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importString(pack('C*',
            
0xD00x94,
            
0xD00xB6,
            
0xD00xBE,
            
0xD10x8D,
            
0xD00xBB,
            
0xD00xB0
            
)
        );
    }

    public function 
testCharactersWrittenUseValidator()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$stream->write(pack('C*',
            
0xD00xBB,
            
0xD10x8E,
            
0xD00xB1,
            
0xD10x8B,
            
0xD10x85
            
)
        );
    }

    public function 
testReadCharactersAreInTact()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
//String
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
//Stream
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$stream->write(pack('C*',
            
0xD00xBB,
            
0xD10x8E,
            
0xD00xB1,
            
0xD10x8B,
            
0xD10x85
            
)
        );

        
$this->assertIdenticalBinary(pack('C*'0xD00x94), $stream->read(1));
        
$this->assertIdenticalBinary(
            
pack('C*'0xD00xB60xD00xBE), $stream->read(2)
            );
        
$this->assertIdenticalBinary(pack('C*'0xD00xBB), $stream->read(1));
        
$this->assertIdenticalBinary(
            
pack('C*'0xD10x8E0xD00xB10xD10x8B), $stream->read(3)
            );
        
$this->assertIdenticalBinary(pack('C*'0xD10x85), $stream->read(1));

        
$this->assertFalse($stream->read(1));
    }

    public function 
testCharactersCanBeReadAsByteArrays()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
//String
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
//Stream
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD1), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$stream->write(pack('C*',
            
0xD00xBB,
            
0xD10x8E,
            
0xD00xB1,
            
0xD10x8B,
            
0xD10x85
            
)
        );

        
$this->assertEquals(array(0xD00x94), $stream->readBytes(1));
        
$this->assertEquals(array(0xD00xB60xD00xBE), $stream->readBytes(2));
        
$this->assertEquals(array(0xD00xBB), $stream->readBytes(1));
        
$this->assertEquals(
            array(
0xD10x8E0xD00xB10xD10x8B), $stream->readBytes(3)
            );
        
$this->assertEquals(array(0xD10x85), $stream->readBytes(1));

        
$this->assertFalse($stream->readBytes(1));
    }

    public function 
testRequestingLargeCharCountPastEndOfStream()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$this->assertIdenticalBinary(pack('C*'0xD00x940xD00xB60xD00xBE),
            
$stream->read(100)
            );

        
$this->assertFalse($stream->read(1));
    }

    public function 
testRequestingByteArrayCountPastEndOfStream()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$this->assertEquals(array(0xD00x940xD00xB60xD00xBE),
            
$stream->readBytes(100)
            );

        
$this->assertFalse($stream->readBytes(1));
    }

    public function 
testPointerOffsetCanBeSet()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$this->assertIdenticalBinary(pack('C*'0xD00x94), $stream->read(1));

        
$stream->setPointer(0);

        
$this->assertIdenticalBinary(pack('C*'0xD00x94), $stream->read(1));

        
$stream->setPointer(2);

        
$this->assertIdenticalBinary(pack('C*'0xD00xBE), $stream->read(1));
    }

    public function 
testContentsCanBeFlushed()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importString(pack('C*'0xD00x940xD00xB60xD00xBE));

        
$stream->flushContents();

        
$this->assertFalse($stream->read(1));
    }

    public function 
testByteStreamCanBeImportingUsesValidator()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);
        
$os $this->_getByteStream();

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$os->shouldReceive('setReadPointer')
           ->
between(01)
           ->
with(0);
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xD0));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0x94));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xD0));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xB6));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xD0));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xBE));
        
$os->shouldReceive('read')
           ->
zeroOrMoreTimes()
           ->
andReturn(false);

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importByteStream($os);
    }

    public function 
testImportingStreamProducesCorrectCharArray()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);
        
$os $this->_getByteStream();

        
$stream = new Swift_CharacterStream_ArrayCharacterStream($factory'utf-8');

        
$os->shouldReceive('setReadPointer')
           ->
between(01)
           ->
with(0);
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xD0));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0x94));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xD0));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xB6));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xD0));
        
$os->shouldReceive('read')->once()->andReturn(pack('C*'0xBE));
        
$os->shouldReceive('read')
           ->
zeroOrMoreTimes()
           ->
andReturn(false);

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD0), 1)->andReturn(1);

        
$stream->importByteStream($os);

        
$this->assertIdenticalBinary(pack('C*'0xD00x94), $stream->read(1));
        
$this->assertIdenticalBinary(pack('C*'0xD00xB6), $stream->read(1));
        
$this->assertIdenticalBinary(pack('C*'0xD00xBE), $stream->read(1));

        
$this->assertFalse($stream->read(1));
    }

    public function 
testAlgorithmWithFixedWidthCharsets()
    {
        
$reader $this->_getReader();
        
$factory $this->_getFactory($reader);

        
$reader->shouldReceive('getInitialByteSize')
               ->
zeroOrMoreTimes()
               ->
andReturn(2);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD10x8D), 2);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD00xBB), 2);
        
$reader->shouldReceive('validateByteSequence')->once()->with(array(0xD00xB0), 2);

        
$stream = new Swift_CharacterStream_ArrayCharacterStream(
            
$factory'utf-8'
        
);
        
$stream->importString(pack('C*'0xD10x8D0xD00xBB0xD00xB0));

        
$this->assertIdenticalBinary(pack('C*'0xD10x8D), $stream->read(1));
        
$this->assertIdenticalBinary(pack('C*'0xD00xBB), $stream->read(1));
        
$this->assertIdenticalBinary(pack('C*'0xD00xB0), $stream->read(1));

        
$this->assertFalse($stream->read(1));
    }

    private function 
_getReader()
    {
        return 
$this->getMockery('Swift_CharacterReader');
    }

    private function 
_getFactory($reader)
    {
        
$factory $this->getMockery('Swift_CharacterReaderFactory');
        
$factory->shouldReceive('getReaderFor')
                ->
zeroOrMoreTimes()
                ->
with('utf-8')
                ->
andReturn($reader);

        return 
$factory;
    }

    private function 
_getByteStream()
    {
        return 
$this->getMockery('Swift_OutputByteStream');
    }
}
Онлайн: 0
Реклама