Code Duplication    Length = 25-28 lines in 3 locations

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

@@ 684-708 (lines=25) @@
681
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
682
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
683
     */
684
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
685
    {
686
        $repository = $this->getRepository();
687
        $userService = $repository->getUserService();
688
689
        /* BEGIN: Use Case */
690
        $userGroup = $this->createUserGroupVersion1();
691
692
        // Load the content service
693
        $contentService = $repository->getContentService();
694
695
        // Create a content update struct and update the group name
696
        $contentUpdate = $contentService->newContentUpdateStruct();
697
        // An object of stdClass is not accepted as a value by the field "name"
698
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
699
700
        // Create a group update struct and set content update struct
701
        $groupUpdate = $userService->newUserGroupUpdateStruct();
702
        $groupUpdate->contentUpdateStruct = $contentUpdate;
703
704
        // This call will fail with an InvalidArgumentException, because the
705
        // field "name" does not accept the given value
706
        $userService->updateUserGroup($userGroup, $groupUpdate);
707
        /* END: Use Case */
708
    }
709
710
    /**
711
     * Test for the newUserCreateStruct() method.
@@ 1548-1575 (lines=28) @@
1545
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1546
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1547
     */
1548
    public function testUpdateUserWhenMissingField()
1549
    {
1550
        $repository = $this->getRepository();
1551
1552
        $userService = $repository->getUserService();
1553
1554
        /* BEGIN: Use Case */
1555
        $user = $this->createUserVersion1();
1556
1557
        // Get the ContentService implementation
1558
        $contentService = $repository->getContentService();
1559
1560
        // Create a content update struct and change the remote id.
1561
        $contentUpdate = $contentService->newContentUpdateStruct();
1562
        $contentUpdate->setField('first_name', null, 'eng-US');
1563
1564
        // Create a new update struct instance
1565
        $userUpdate = $userService->newUserUpdateStruct();
1566
1567
        // Set the content update struct.
1568
        $userUpdate->contentUpdateStruct = $contentUpdate;
1569
1570
        // This call will fail with a "ContentFieldValidationException" because the
1571
        // mandatory field "first_name" is set to an empty value.
1572
        $userService->updateUser($user, $userUpdate);
1573
1574
        /* END: Use Case */
1575
    }
1576
1577
    /**
1578
     * Test for the updateUser() method.
@@ 1584-1611 (lines=28) @@
1581
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1582
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1583
     */
1584
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1585
    {
1586
        $repository = $this->getRepository();
1587
1588
        $userService = $repository->getUserService();
1589
1590
        /* BEGIN: Use Case */
1591
        $user = $this->createUserVersion1();
1592
1593
        // Get the ContentService implementation
1594
        $contentService = $repository->getContentService();
1595
1596
        $contentUpdate = $contentService->newContentUpdateStruct();
1597
        // An object of stdClass is not valid for the field first_name
1598
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1599
1600
        // Create a new update struct instance
1601
        $userUpdate = $userService->newUserUpdateStruct();
1602
1603
        // Set the content update struct.
1604
        $userUpdate->contentUpdateStruct = $contentUpdate;
1605
1606
        // This call will fail with a "InvalidArgumentException" because the
1607
        // the field "first_name" does not accept the given value.
1608
        $userService->updateUser($user, $userUpdate);
1609
1610
        /* END: Use Case */
1611
    }
1612
1613
    /**
1614
     * Test for the loadUserGroupsOfUser() method.