Skip to content

Instantly share code, notes, and snippets.

@bdunogier
Created October 8, 2011 11:01
Show Gist options
  • Save bdunogier/1272146 to your computer and use it in GitHub Desktop.
Save bdunogier/1272146 to your computer and use it in GitHub Desktop.
A PHPUnit test
<?php
/**
* Tests processing of URL items found in the XML
*/
public function testProcessRelatedContent()
{
$idArray = array( 1, 2, 3 );
$version = $this->getMock( 'ezp\\Content\\Version' );
$version->id = 1;
$version->contentId = 1;
$repository = $this->getMockBuilder( '\\ezp\\Base\\Repository' )
->disableOriginalConstructor()
->getMock();
$repositoryHandler = $this->getMock( 'ezp\\Persistence\\Repository\\Handler' );
$fieldTypeService = $this->getMockBuilder( 'ezp\\Content\\FieldType\\Service' )
->setConstructorArgs( array( $repository, $repositoryHandler ) )
->getMock();
$fieldTypeService
->expects( $this->exactly( 6 ) )
->method( 'addRelation' )
->with(
$this->logicalOr( $this->equalTo( Relation::ATTRIBUTE ), $this->equalTo( Relation::LINK ) ),
$version->contentId,
$version->id,
$this->logicalOr( $this->equalTo( 1 ), $this->equalTo( 2 ), $this->equalTo( 3 ) ),
$this->isNull()
);
$repository
->expects( $this->once() )
->method( 'getInternalFieldTypeService' )
->will( $this->returnValue( $fieldTypeService ) );
$inputParser = $this->getInputParserMock();
// Parser::process => DOMDocument
$inputParser
->expects( $this->once() )
->method( 'process' )
->will( $this->returnValue( $this->getMock( '\\DOMDocument' ) ) );
// Parser::getRelatedContentIdArray() => array
$inputParser
->expects( $this->once() )
->method( 'getRelatedContentIdArray' )
->will( $this->returnValue( $idArray ) );
// Parser::getLinkedContentIdArray() => array
$inputParser
->expects( $this->once() )
->method( 'getLinkedContentIdArray' )
->will( $this->returnValue( $idArray ) );
$handler = new InputHandler( $inputParser );
self::assertTrue( $handler->process( '', $repository, $version ) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment