Skip to content

Commit

Permalink
EZP-29593: Fixed time-related test (ezsystems#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikadamczyk authored and alongosz committed Oct 3, 2018
1 parent 8ad7aae commit cdc02d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
10 changes: 9 additions & 1 deletion eZ/Publish/Core/Repository/ContentService.php
Expand Up @@ -1513,7 +1513,7 @@ protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicat
throw new BadStateException('$versionInfo', 'Only versions in draft status can be published.');
}

$currentTime = time();
$currentTime = $this->getUnixTimestamp();
if ($publicationDate === null && $versionInfo->versionNo === 1) {
$publicationDate = $currentTime;
}
Expand Down Expand Up @@ -1553,6 +1553,14 @@ protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicat
return $content;
}

/**
* @return int
*/
protected function getUnixTimestamp()
{
return time();
}

/**
* Removes the given version.
*
Expand Down
34 changes: 24 additions & 10 deletions eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php
Expand Up @@ -5406,7 +5406,11 @@ public function testCopyContentThrowsUnauthorizedException()
public function testCopyContent()
{
$repositoryMock = $this->getRepositoryMock();
$contentService = $this->getPartlyMockedContentService(array('internalLoadContentInfo', 'internalLoadContent'));
$contentService = $this->getPartlyMockedContentService(array(
'internalLoadContentInfo',
'internalLoadContent',
'getUnixTimestamp',
));
$locationServiceMock = $this->getLocationServiceMock();
$contentInfoMock = $this->createMock(APIContentInfo::class);
$locationCreateStruct = new LocationCreateStruct();
Expand Down Expand Up @@ -5484,7 +5488,7 @@ public function testCopyContent()
->will($this->returnValue($versionInfoMock));

/* @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfoMock */
$content = $this->mockPublishVersion(123456);
$content = $this->mockPublishVersion(123456, 126666);
$locationServiceMock->expects($this->once())
->method('createLocation')
->with(
Expand All @@ -5499,6 +5503,10 @@ public function testCopyContent()
)
->will($this->returnValue($content));

$contentService->expects($this->once())
->method('getUnixTimestamp')
->will($this->returnValue(126666));

/* @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfoMock */
$contentService->copyContent($contentInfoMock, $locationCreateStruct, null);
}
Expand All @@ -5513,7 +5521,11 @@ public function testCopyContent()
public function testCopyContentWithVersionInfo()
{
$repositoryMock = $this->getRepositoryMock();
$contentService = $this->getPartlyMockedContentService(array('internalLoadContentInfo', 'internalLoadContent'));
$contentService = $this->getPartlyMockedContentService(array(
'internalLoadContentInfo',
'internalLoadContent',
'getUnixTimestamp',
));
$locationServiceMock = $this->getLocationServiceMock();
$contentInfoMock = $this->createMock(APIContentInfo::class);
$locationCreateStruct = new LocationCreateStruct();
Expand Down Expand Up @@ -5589,7 +5601,7 @@ public function testCopyContentWithVersionInfo()
->will($this->returnValue($versionInfoMock));

/* @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfoMock */
$content = $this->mockPublishVersion(123456);
$content = $this->mockPublishVersion(123456, 126666);
$locationServiceMock->expects($this->once())
->method('createLocation')
->with(
Expand All @@ -5604,6 +5616,10 @@ public function testCopyContentWithVersionInfo()
)
->will($this->returnValue($content));

$contentService->expects($this->once())
->method('getUnixTimestamp')
->will($this->returnValue(126666));

/* @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfoMock */
$contentService->copyContent($contentInfoMock, $locationCreateStruct, $versionInfoMock);
}
Expand Down Expand Up @@ -5729,10 +5745,11 @@ protected function mockSetDefaultObjectStates()

/**
* @param int|null $publicationDate
* @param int|null $modificationDate
*
* @return \eZ\Publish\API\Repository\Values\Content\Content
*/
protected function mockPublishVersion($publicationDate = null)
protected function mockPublishVersion($publicationDate = null, $modificationDate = null)
{
$domainMapperMock = $this->getDomainMapperMock();
$contentMock = $this->createMock(APIContent::class);
Expand Down Expand Up @@ -5786,18 +5803,15 @@ protected function mockPublishVersion($publicationDate = null)

// Account for 1 second of test execution time
$metadataUpdateStruct->publicationDate = $publicationDate;
$metadataUpdateStruct->modificationDate = $currentTime;
$metadataUpdateStruct2 = clone $metadataUpdateStruct;
++$metadataUpdateStruct2->publicationDate;
++$metadataUpdateStruct2->modificationDate;
$metadataUpdateStruct->modificationDate = $modificationDate ?? $currentTime;

$spiContent = new SPIContent();
$contentHandlerMock->expects($this->once())
->method('publish')
->with(
42,
123,
$this->logicalOr($metadataUpdateStruct, $metadataUpdateStruct2)
$metadataUpdateStruct
)
->will($this->returnValue($spiContent));

Expand Down

0 comments on commit cdc02d1

Please sign in to comment.