public function testPublishNewRoleDraft()
{
$this->loggerMock->expects($this->once())->method('logCall');
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler');
$this->persistenceHandlerMock->expects($this->once())->method('userHandler')->willReturn($innerHandlerMock);
$roleDraftId = 33;
$originalRoleId = -1;
$innerHandlerMock->expects($this->at(0))->method('loadRole')->with($roleDraftId, Role::STATUS_DRAFT)->willReturn(new Role(['originalId' => $originalRoleId]));
$innerHandlerMock->expects($this->at(1))->method('publishRoleDraft')->with($roleDraftId);
$innerHandlerMock->expects($this->at(2))->method('loadRole')->with($originalRoleId, Role::STATUS_DEFINED)->willThrowException(new NotFoundException('foo', 'bar'));
$innerHandlerMock->expects($this->at(3))->method('loadRole')->with($roleDraftId, Role::STATUS_DEFINED)->willReturn(new Role(['id' => $roleDraftId]));
$this->cacheMock->expects($this->once())->method('clear')->with('user', 'role', 'assignments')->will($this->returnValue(true));
$cacheItemMock = $this->getMock('Stash\\Interfaces\\ItemInterface');
$this->cacheMock->expects($this->once())->method('getItem')->with('user', 'role', $roleDraftId)->will($this->returnValue($cacheItemMock));
$cacheItemMock->expects($this->once())->method('set')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Role'))->will($this->returnValue($cacheItemMock));
$cacheItemMock->expects($this->once())->method('save')->with();
$handler = $this->persistenceCacheHandler->userHandler();
$handler->publishRoleDraft($roleDraftId);
}