Skip to content

Commit

Permalink
Merge pull request #978 from pedroresende/EZP-23288b
Browse files Browse the repository at this point in the history
New test for EZP-23288: Allow to set modifier of Content Versions & ContentType
  • Loading branch information
andrerom committed Oct 24, 2014
2 parents 04f637d + 8fd7782 commit 69bbdb7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Repository/Tests/BaseContentServiceTest.php
Expand Up @@ -184,6 +184,52 @@ protected function createUpdatedDraftVersion2()
return $draftVersion2;
}

/**
* Creates an updated content draft named <b>$draftVersion2</b> from
* a currently published content object with a user different from the
* creator.
*
* @return array \eZ\Publish\API\Repository\Values\Content\Content, id
*/
protected function createUpdatedDraftVersion2_NotAdmin()
{
$repository = $this->getRepository();

$contentService = $repository->getContentService();
$userService = $repository->getUserService();
$mainLanguageCode = 'eng-US';

// Create a new user that belongs to the Administrator users group
$newUserCreateStruct = $userService->newUserCreateStruct( 'admin2', 'admin2@ez.no', "admin2", $mainLanguageCode );
$newUserCreateStruct->setField( 'first_name', 'Admin2', $mainLanguageCode );
$newUserCreateStruct->setField( 'last_name', 'Admin2', $mainLanguageCode );

// Load the Admin Group
$userAdminGroup = $userService->loadUserGroup( '12' );

$userAdmin2 = $userService->createUser( $newUserCreateStruct, array ( $userAdminGroup ) );

/* BEGIN: Inline */
$draftVersion2 = $this->createContentDraftVersion2();

// Create an update struct and modify some fields
$contentUpdate = $contentService->newContentUpdateStruct();
$contentUpdate->initialLanguageCode = $mainLanguageCode;

$contentUpdate->creatorId = $this->generateId( 'user', $userAdmin2->id );
$contentUpdate->setField( 'name', 'An awesome forum²' );
$contentUpdate->setField( 'name', 'An awesome forum²³', 'eng-GB' );

// Update the content draft
$draftVersion2 = $contentService->updateContent(
$draftVersion2->getVersionInfo(),
$contentUpdate
);
/* END: Inline */

return array( $draftVersion2, $userAdmin2->id );
}

/**
* Creates an updated content object named <b>$contentVersion2</b> from
* a currently published content object.
Expand Down
30 changes: 30 additions & 0 deletions Repository/Tests/ContentServiceTest.php
Expand Up @@ -1306,6 +1306,36 @@ public function testUpdateContent()
return $draftVersion2;
}

/**
* Test for the updateContent_WithDifferentUser() method.
*
* @return \eZ\Publish\API\Repository\Values\Content\Content
* @see \eZ\Publish\API\Repository\ContentService::updateContent()
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
* @group user
* @group field-type
*/
public function testUpdateContent_WithDifferentUser()
{
/* BEGIN: Use Case */
$arrayWithDraftVersion2 = $this->createUpdatedDraftVersion2_NotAdmin();
/* END: Use Case */

$this->assertInstanceOf(
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
$arrayWithDraftVersion2[0]
);

$this->assertEquals(
$this->generateId( 'user', $arrayWithDraftVersion2[1] ),
$arrayWithDraftVersion2[0]->versionInfo->creatorId,
"creatorId is not properly set on new Version"
);

return $arrayWithDraftVersion2[0];
}

/**
* Test for the updateContent() method.
*
Expand Down

0 comments on commit 69bbdb7

Please sign in to comment.