Code Duplication    Length = 25-28 lines in 3 locations

eZ/Publish/API/Repository/Tests/UserServiceTest.php 3 locations

@@ 697-721 (lines=25) @@
694
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
695
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
696
     */
697
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
698
    {
699
        $repository = $this->getRepository();
700
        $userService = $repository->getUserService();
701
702
        /* BEGIN: Use Case */
703
        $userGroup = $this->createUserGroupVersion1();
704
705
        // Load the content service
706
        $contentService = $repository->getContentService();
707
708
        // Create a content update struct and update the group name
709
        $contentUpdate = $contentService->newContentUpdateStruct();
710
        // An object of stdClass is not accepted as a value by the field "name"
711
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
712
713
        // Create a group update struct and set content update struct
714
        $groupUpdate = $userService->newUserGroupUpdateStruct();
715
        $groupUpdate->contentUpdateStruct = $contentUpdate;
716
717
        // This call will fail with an InvalidArgumentException, because the
718
        // field "name" does not accept the given value
719
        $userService->updateUserGroup($userGroup, $groupUpdate);
720
        /* END: Use Case */
721
    }
722
723
    /**
724
     * Test for the newUserCreateStruct() method.
@@ 1689-1716 (lines=28) @@
1686
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1687
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1688
     */
1689
    public function testUpdateUserWhenMissingField()
1690
    {
1691
        $repository = $this->getRepository();
1692
1693
        $userService = $repository->getUserService();
1694
1695
        /* BEGIN: Use Case */
1696
        $user = $this->createUserVersion1();
1697
1698
        // Get the ContentService implementation
1699
        $contentService = $repository->getContentService();
1700
1701
        // Create a content update struct and change the remote id.
1702
        $contentUpdate = $contentService->newContentUpdateStruct();
1703
        $contentUpdate->setField('first_name', null, 'eng-US');
1704
1705
        // Create a new update struct instance
1706
        $userUpdate = $userService->newUserUpdateStruct();
1707
1708
        // Set the content update struct.
1709
        $userUpdate->contentUpdateStruct = $contentUpdate;
1710
1711
        // This call will fail with a "ContentFieldValidationException" because the
1712
        // mandatory field "first_name" is set to an empty value.
1713
        $userService->updateUser($user, $userUpdate);
1714
1715
        /* END: Use Case */
1716
    }
1717
1718
    /**
1719
     * Test for the updateUser() method.
@@ 1725-1752 (lines=28) @@
1722
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1723
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1724
     */
1725
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1726
    {
1727
        $repository = $this->getRepository();
1728
1729
        $userService = $repository->getUserService();
1730
1731
        /* BEGIN: Use Case */
1732
        $user = $this->createUserVersion1();
1733
1734
        // Get the ContentService implementation
1735
        $contentService = $repository->getContentService();
1736
1737
        $contentUpdate = $contentService->newContentUpdateStruct();
1738
        // An object of stdClass is not valid for the field first_name
1739
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1740
1741
        // Create a new update struct instance
1742
        $userUpdate = $userService->newUserUpdateStruct();
1743
1744
        // Set the content update struct.
1745
        $userUpdate->contentUpdateStruct = $contentUpdate;
1746
1747
        // This call will fail with a "InvalidArgumentException" because the
1748
        // the field "first_name" does not accept the given value.
1749
        $userService->updateUser($user, $userUpdate);
1750
1751
        /* END: Use Case */
1752
    }
1753
1754
    /**
1755
     * Test for the loadUserGroupsOfUser() method.