/** * Test for modify(). */ public function testModify() { $modifier = new ContentModifier(); /** @var Content $content */ $content = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Content'); $content->setId('testId')->setActive(true)->setPosition(4)->setContent('testContent')->setTitle('testTitle')->setFolder('testFolder')->setLoadId('testSlug')->setSnippet(false)->setType(5)->setFolder('testFolder'); /** @var Seo|\PHPUnit_Framework_MockObject_MockObject $seo */ $seo = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Seo'); $seo->setSeoUrl('test'); /** @var SeoFinder|\PHPUnit_Framework_MockObject_MockObject $seoFinder */ $seoFinder = $this->getMockBuilder('ONGR\\OXIDConnectorBundle\\Service\\SeoFinder')->disableOriginalConstructor()->getMock(); $seoFinder->expects($this->once())->method('getEntitySeo')->willReturn(new \ArrayIterator([$seo])); $modifier->setSeoFinderService($seoFinder); $expectedDocument = new ContentDocument(); $expectedDocument->setId('testId'); $expectedDocument->setActive(true); $expectedDocument->setPosition(4); $expectedDocument->setContent('testContent'); $expectedDocument->setTitle('testTitle'); $expectedDocument->setFolder('testFolder'); $expectedDocument->setSlug('testSlug'); $expectedDocument->setSnippet(false); $expectedDocument->setType(5); $expectedDocument->setFolder('testFolder'); $url = new UrlNested(); $url->setUrl('test'); $expectedDocument->setUrls(new \ArrayIterator([$url])); $expectedDocument->setExpiredUrls([]); $document = new ContentDocument(); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); $modifier->modify(new ImportItem($content, $document), $event); $this->assertEquals($expectedDocument, $document); }
/** * Test for modify(). */ public function testModify() { $modifier = new ContentModifier(); /** @var Content $content */ $content = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Content'); $content->setId('testId')->setActive(true)->setPosition(4)->setContent('testContent')->setTitle('testTitle')->setFolder('testFolder')->setLoadId('testSlug')->setSnippet(false)->setType(5)->setFolder('testFolder'); $expectedDocument = new ContentDocument(); $expectedDocument->setId('testId'); $expectedDocument->setActive(true); $expectedDocument->setPosition(4); $expectedDocument->setContent('testContent'); $expectedDocument->setTitle('testTitle'); $expectedDocument->setFolder('testFolder'); $expectedDocument->setSlug('testSlug'); $expectedDocument->setSnippet(false); $expectedDocument->setType(5); $expectedDocument->setFolder('testFolder'); $expectedDocument->setUrls(new \ArrayIterator()); $expectedDocument->setExpiredUrls([]); $document = new ContentDocument(); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); $modifier->modify(new ImportItem($content, $document), $event); $this->assertEquals($expectedDocument, $document); }
/** * Transforms Content entity into ES document. * * @param Content $content * @param ContentDocument $document */ public function transformContentToDocument(Content $content, ContentDocument $document) { $document->setId($content->getId()); $document->setTitle($content->getTitle()); $document->setContent($content->getContent()); $document->setFolder($content->getFolder()); $document->setSlug($content->getLoadId()); $document->setSnippet($content->isSnippet()); $document->setType($content->getType()); $document->setActive($content->isActive()); $document->setPosition($content->getPosition()); $this->extractUrls($content, $document); }
/** * Test modification. */ public function testModify() { $expectedContent1 = new ContentDocument(); $expectedContent1->setId('8709e45f31a86909e9f999222e80b1d0'); $expectedContent1->setContent('CONTENT ONE'); $expectedContent1->setTitle('TITLE OF CONTENT ONE'); $expectedContent1->setFolder('CMSFOLDER_STANDARD'); $expectedContent1->setSlug('oxstdfooter'); $expectedContent1->setSnippet(true); $expectedContent1->setType(2); $expectedContent1->setActive(false); $expectedContent1->setPosition('position1'); $url = new UrlNested(); $url->setUrl('Test/Content/1'); $expectedContent1->setUrls(new \ArrayIterator([$url])); $expectedContent1->setExpiredUrls([]); $expectedContent2 = new ContentDocument(); $expectedContent2->setId('ad542e49bff479009.64538090'); $expectedContent2->setContent('<div>Content two</div>'); $expectedContent2->setTitle('Title of content two'); $expectedContent2->setFolder('CMSFOLDER_EMAILS'); $expectedContent2->setSlug('oxadminorderemail'); $expectedContent2->setSnippet(false); $expectedContent2->setType(1); $expectedContent2->setActive(true); $expectedContent2->setPosition('position2'); $url = new UrlNested(); $url->setUrl('Test/Content/2'); $expectedContent2->setUrls(new \ArrayIterator([$url])); $expectedContent2->setExpiredUrls([]); $expectedEntities = [$expectedContent1, $expectedContent2]; $contentItems = $this->getTestElements(['8709e45f31a86909e9f999222e80b1d0', 'ad542e49bff479009.64538090'], 'ONGROXIDConnectorBundleTest:Content'); $this->assertCount(2, $contentItems); $seoFinder = new SeoFinder(); $seoFinder->setEntityManager($this->getEntityManager()); $seoFinder->setShopId(0); $seoFinder->setRepository('ONGROXIDConnectorBundleTest:Seo'); $modifier = new ContentModifier(); $modifier->setSeoFinderService($seoFinder); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); foreach ($expectedEntities as $key => $expectedContent) { $actualContent = new ContentDocument(); $modifier->modify(new ImportItem($contentItems[$key], $actualContent), $event); $this->assertEquals($expectedContent, $actualContent); } }