Code Duplication    Length = 25-28 lines in 3 locations

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

@@ 686-710 (lines=25) @@
683
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
684
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup
685
     */
686
    public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
687
    {
688
        $repository = $this->getRepository();
689
        $userService = $repository->getUserService();
690
691
        /* BEGIN: Use Case */
692
        $userGroup = $this->createUserGroupVersion1();
693
694
        // Load the content service
695
        $contentService = $repository->getContentService();
696
697
        // Create a content update struct and update the group name
698
        $contentUpdate = $contentService->newContentUpdateStruct();
699
        // An object of stdClass is not accepted as a value by the field "name"
700
        $contentUpdate->setField('name', new \stdClass(), 'eng-US');
701
702
        // Create a group update struct and set content update struct
703
        $groupUpdate = $userService->newUserGroupUpdateStruct();
704
        $groupUpdate->contentUpdateStruct = $contentUpdate;
705
706
        // This call will fail with an InvalidArgumentException, because the
707
        // field "name" does not accept the given value
708
        $userService->updateUserGroup($userGroup, $groupUpdate);
709
        /* END: Use Case */
710
    }
711
712
    /**
713
     * Test for the newUserCreateStruct() method.
@@ 1514-1541 (lines=28) @@
1511
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException
1512
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1513
     */
1514
    public function testUpdateUserThrowsContentValidationException()
1515
    {
1516
        $repository = $this->getRepository();
1517
1518
        $userService = $repository->getUserService();
1519
1520
        /* BEGIN: Use Case */
1521
        $user = $this->createUserVersion1();
1522
1523
        // Get the ContentService implementation
1524
        $contentService = $repository->getContentService();
1525
1526
        // Create a content update struct and change the remote id.
1527
        $contentUpdate = $contentService->newContentUpdateStruct();
1528
        $contentUpdate->setField('first_name', null, 'eng-US');
1529
1530
        // Create a new update struct instance
1531
        $userUpdate = $userService->newUserUpdateStruct();
1532
1533
        // Set the content update struct.
1534
        $userUpdate->contentUpdateStruct = $contentUpdate;
1535
1536
        // This call will fail with a "ContentValidationException" because the
1537
        // mandatory field "first_name" is set to an empty value.
1538
        $userService->updateUser($user, $userUpdate);
1539
1540
        /* END: Use Case */
1541
    }
1542
1543
    /**
1544
     * Test for the updateUser() method.
@@ 1550-1577 (lines=28) @@
1547
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1548
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
1549
     */
1550
    public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1551
    {
1552
        $repository = $this->getRepository();
1553
1554
        $userService = $repository->getUserService();
1555
1556
        /* BEGIN: Use Case */
1557
        $user = $this->createUserVersion1();
1558
1559
        // Get the ContentService implementation
1560
        $contentService = $repository->getContentService();
1561
1562
        $contentUpdate = $contentService->newContentUpdateStruct();
1563
        // An object of stdClass is not valid for the field first_name
1564
        $contentUpdate->setField('first_name', new \stdClass(), 'eng-US');
1565
1566
        // Create a new update struct instance
1567
        $userUpdate = $userService->newUserUpdateStruct();
1568
1569
        // Set the content update struct.
1570
        $userUpdate->contentUpdateStruct = $contentUpdate;
1571
1572
        // This call will fail with a "InvalidArgumentException" because the
1573
        // the field "first_name" does not accept the given value.
1574
        $userService->updateUser($user, $userUpdate);
1575
1576
        /* END: Use Case */
1577
    }
1578
1579
    /**
1580
     * Test for the loadUserGroupsOfUser() method.