eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testCreateContentWithLocations PHP Метод

testCreateContentWithLocations() публичный Метод

Test for the createContent() method.
    public function testCreateContentWithLocations()
    {
        $spiFields = array(new SPIField(array('fieldDefinitionId' => 'fieldDefinitionId', 'type' => 'fieldTypeIdentifier', 'value' => 'defaultValue', 'languageCode' => 'eng-US')));
        $fieldDefinitions = array(new FieldDefinition(array('id' => 'fieldDefinitionId', 'fieldTypeIdentifier' => 'fieldTypeIdentifier', 'isTranslatable' => false, 'identifier' => 'identifier', 'isRequired' => false, 'defaultValue' => 'defaultValue')));
        // Set up a simple case that will pass
        $locationCreateStruct1 = new LocationCreateStruct(array('parentLocationId' => 321));
        $locationCreateStruct2 = new LocationCreateStruct(array('parentLocationId' => 654));
        $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2);
        $contentCreateStruct = $this->assertForTestCreateContentNonRedundantFieldSet('eng-US', array(), $spiFields, $fieldDefinitions, $locationCreateStructs, false, false);
        $repositoryMock = $this->getRepositoryMock();
        $mockedService = $this->getPartlyMockedContentService();
        $locationServiceMock = $this->getLocationServiceMock();
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
        $handlerMock = $this->getPersistenceMock()->contentHandler();
        $domainMapperMock = $this->getDomainMapperMock();
        $spiLocationCreateStruct = new SPILocation\CreateStruct();
        $parentLocation = new Location(array('contentInfo' => new ContentInfo(array('sectionId' => 1))));
        $locationServiceMock->expects($this->at(0))->method('loadLocation')->with($this->equalTo(321))->will($this->returnValue($parentLocation));
        $locationServiceMock->expects($this->at(1))->method('loadLocation')->with($this->equalTo(654))->will($this->returnValue($parentLocation));
        $repositoryMock->expects($this->atLeastOnce())->method('getLocationService')->will($this->returnValue($locationServiceMock));
        $domainMapperMock->expects($this->at(1))->method('buildSPILocationCreateStruct')->with($this->equalTo($locationCreateStruct1), $this->equalTo($parentLocation), $this->equalTo(true), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($spiLocationCreateStruct));
        $domainMapperMock->expects($this->at(2))->method('buildSPILocationCreateStruct')->with($this->equalTo($locationCreateStruct2), $this->equalTo($parentLocation), $this->equalTo(false), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($spiLocationCreateStruct));
        $spiContentCreateStruct = new SPIContentCreateStruct(array('name' => array(), 'typeId' => 123, 'sectionId' => 1, 'ownerId' => 169, 'remoteId' => 'hash', 'fields' => $spiFields, 'modified' => time(), 'initialLanguageId' => 4242, 'locations' => array($spiLocationCreateStruct, $spiLocationCreateStruct)));
        $spiContentCreateStruct2 = clone $spiContentCreateStruct;
        ++$spiContentCreateStruct2->modified;
        $spiContent = new SPIContent(array('versionInfo' => new SPIContent\VersionInfo(array('contentInfo' => new SPIContent\ContentInfo(array('id' => 42)), 'versionNo' => 7))));
        $handlerMock->expects($this->once())->method('create')->with($this->logicalOr($spiContentCreateStruct, $spiContentCreateStruct2))->will($this->returnValue($spiContent));
        $domainMapperMock->expects($this->once())->method('buildContentDomainObject')->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'), $this->equalTo(null));
        $repositoryMock->expects($this->once())->method('commit');
        // Execute
        $mockedService->createContent($contentCreateStruct, $locationCreateStructs);
    }
ContentTest