eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testCreateContentWithLocationsDuplicateUnderParent PHP Method

testCreateContentWithLocationsDuplicateUnderParent() public method

Test for the createContent() method.
    public function testCreateContentWithLocationsDuplicateUnderParent()
    {
        $fieldDefinitions = array(new FieldDefinition(array('id' => 'fieldDefinitionId', 'fieldTypeIdentifier' => 'fieldTypeIdentifier', 'isTranslatable' => false, 'identifier' => 'identifier', 'isRequired' => false, 'defaultValue' => 'defaultValue')));
        $repositoryMock = $this->getRepositoryMock();
        $mockedService = $this->getPartlyMockedContentService();
        $locationServiceMock = $this->getLocationServiceMock();
        $contentTypeServiceMock = $this->getContentTypeServiceMock();
        $domainMapperMock = $this->getDomainMapperMock();
        /** @var \PHPUnit_Framework_MockObject_MockObject $languageHandlerMock */
        $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();
        $spiLocationCreateStruct = new SPILocation\CreateStruct();
        $parentLocation = new Location(array('id' => 321));
        $locationCreateStruct = new LocationCreateStruct(array('parentLocationId' => 321));
        $locationCreateStructs = array($locationCreateStruct, clone $locationCreateStruct);
        $contentType = new ContentType(array('id' => 123, 'fieldDefinitions' => $fieldDefinitions, 'nameSchema' => '<nameSchema>'));
        $contentCreateStruct = new ContentCreateStruct(array('fields' => array(), 'mainLanguageCode' => 'eng-US', 'contentType' => $contentType, 'alwaysAvailable' => false, 'ownerId' => 169, 'sectionId' => 1));
        $languageHandlerMock->expects($this->any())->method('loadByLanguageCode')->with($this->isType('string'))->will($this->returnCallback(function () {
            return new Language(array('id' => 4242));
        }));
        $contentTypeServiceMock->expects($this->once())->method('loadContentType')->with($this->equalTo($contentType->id))->will($this->returnValue($contentType));
        $repositoryMock->expects($this->once())->method('getContentTypeService')->will($this->returnValue($contentTypeServiceMock));
        $that = $this;
        $repositoryMock->expects($this->once())->method('canUser')->with($this->equalTo('content'), $this->equalTo('create'), $this->isInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct'), $this->equalTo($locationCreateStructs))->will($this->returnCallback(function () use($that, $contentCreateStruct) {
            $that->assertEquals($contentCreateStruct, func_get_arg(2));
            return true;
        }));
        $domainMapperMock->expects($this->once())->method('getUniqueHash')->with($this->isInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct'))->will($this->returnCallback(function ($object) use($that, $contentCreateStruct) {
            $that->assertEquals($contentCreateStruct, $object);
            return 'hash';
        }));
        $locationServiceMock->expects($this->once())->method('loadLocation')->with($this->equalTo(321))->will($this->returnValue($parentLocation));
        $repositoryMock->expects($this->any())->method('getLocationService')->will($this->returnValue($locationServiceMock));
        $domainMapperMock->expects($this->any())->method('buildSPILocationCreateStruct')->with($this->equalTo($locationCreateStruct), $this->equalTo($parentLocation), $this->equalTo(true), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($spiLocationCreateStruct));
        $mockedService->createContent($contentCreateStruct, $locationCreateStructs);
    }
ContentTest