コード例 #1
0
ファイル: PageTest.php プロジェクト: Doability/magento2dev
 public function testBeforeSave()
 {
     $this->pageMock->expects($this->any())->method('getData')->willReturnMap([['identifier', null, 'test'], ['custom_theme_from', null, null], ['custom_theme_to', null, '10/02/2016']]);
     $this->dateTimeMock->expects($this->once())->method('formatDate')->with('10/02/2016')->willReturn('10 Feb 2016');
     $this->pageMock->expects($this->any())->method('setData')->withConsecutive(['custom_theme_from', null], ['custom_theme_to', '10 Feb 2016']);
     $this->model->beforeSave($this->pageMock);
 }
コード例 #2
0
 public function testExecute()
 {
     $entityId = 1;
     $linkId = 2;
     $oldStore = 1;
     $newStore = 2;
     $linkField = 'link_id';
     $adapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMockForAbstractClass();
     $whereForDelete = [$linkField . ' = ?' => $linkId, 'store_id IN (?)' => [$oldStore]];
     $adapter->expects($this->once())->method('delete')->with('cms_page_store', $whereForDelete)->willReturnSelf();
     $whereForInsert = [$linkField => $linkId, 'store_id' => $newStore];
     $adapter->expects($this->once())->method('insertMultiple')->with('cms_page_store', [$whereForInsert])->willReturnSelf();
     $entityMetadata = $this->getMockBuilder('Magento\\Framework\\Model\\Entity\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadata->expects($this->once())->method('getEntityConnection')->willReturn($adapter);
     $entityMetadata->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $this->metadataPool->expects($this->once())->method('getMetadata')->with('Magento\\Cms\\Model\\Page')->willReturn($entityMetadata);
     $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$oldStore]);
     $this->resourcePage->expects($this->once())->method('getTable')->with('cms_page_store')->willReturn('cms_page_store');
     $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->setMethods(['getStores', 'getStoreId', 'getId', 'getData'])->getMock();
     $page->expects($this->once())->method('getStores')->willReturn(null);
     $page->expects($this->once())->method('getStoreId')->willReturn($newStore);
     $page->expects($this->once())->method('getId')->willReturn($entityId);
     $page->expects($this->exactly(2))->method('getData')->with($linkField)->willReturn($linkId);
     $result = $this->model->execute('Magento\\Cms\\Model\\Page', $page);
     $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result);
 }
コード例 #3
0
ファイル: SaveHandler.php プロジェクト: rafaelstz/magento2
 /**
  * @param string $entityType
  * @param object $entity
  * @param array $arguments
  * @return object
  * @throws \Exception
  */
 public function execute($entityType, $entity, $arguments = [])
 {
     $entityMetadata = $this->metadataPool->getMetadata($entityType);
     $linkField = $entityMetadata->getLinkField();
     $connection = $entityMetadata->getEntityConnection();
     $oldStores = $this->resourcePage->lookupStoreIds((int) $entity->getId());
     $newStores = (array) $entity->getStores();
     if (empty($newStores)) {
         $newStores = (array) $entity->getStoreId();
     }
     $table = $this->resourcePage->getTable('cms_page_store');
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = [$linkField . ' = ?' => (int) $entity->getData($linkField), 'store_id IN (?)' => $delete];
         $connection->delete($table, $where);
     }
     $insert = array_diff($newStores, $oldStores);
     if ($insert) {
         $data = [];
         foreach ($insert as $storeId) {
             $data[] = [$linkField => (int) $entity->getData($linkField), 'store_id' => (int) $storeId];
         }
         $connection->insertMultiple($table, $data);
     }
     return $entity;
 }
コード例 #4
0
ファイル: ReadHandler.php プロジェクト: koliaGI/magento2
 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     if ($entity->getId()) {
         $stores = $this->resourcePage->lookupStoreIds((int) $entity->getId());
         $entity->setData('store_id', $stores);
     }
     return $entity;
 }
コード例 #5
0
ファイル: PageTest.php プロジェクト: whoople/magento2-testing
 /**
  * @covers \Magento\Cms\Model\Page::checkIdentifier
  */
 public function testCheckIdentifier()
 {
     $identifier = 1;
     $storeId = 2;
     $fetchOneResult = 'some result';
     $this->resourcePageMock->expects($this->atLeastOnce())->method('checkIdentifier')->with($identifier, $storeId)->willReturn($fetchOneResult);
     $this->assertInternalType('string', $this->thisMock->checkIdentifier($identifier, $storeId));
 }
コード例 #6
0
 public function testExecute()
 {
     $entityId = 1;
     $storeId = 1;
     $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$storeId]);
     $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->getMock();
     $page->expects($this->exactly(2))->method('getId')->willReturn($entityId);
     $page->expects($this->once())->method('setData')->with('store_id', [$storeId])->willReturnSelf();
     $result = $this->model->execute('', $page);
     $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result);
 }
コード例 #7
0
ファイル: PageTest.php プロジェクト: Doability/magento2dev
 protected function setUp()
 {
     $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock();
     $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
     $this->resourcePageMock = $this->getMockBuilder(PageResource::class)->disableOriginalConstructor()->setMethods(['getIdFieldName', 'checkIdentifier'])->getMock();
     $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->disableOriginalConstructor()->getMock();
     $this->resourcesMock = $this->getMockBuilder(AbstractResource::class)->setMethods(['getIdFieldName', 'load', 'checkIdentifier'])->getMockForAbstractClass();
     $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMockForAbstractClass();
     $this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManagerMock);
     $this->resourcePageMock->expects($this->any())->method('getResources')->willReturn($this->resourcesMock);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->model = $objectManager->getObject(Page::class, ['context' => $this->contextMock, 'resource' => $this->resourcesMock]);
     $objectManager->setBackwardCompatibleProperty($this->model, 'scopeConfig', $this->scopeConfigMock);
 }
コード例 #8
0
ファイル: LinkTest.php プロジェクト: pradeep-wagento/magento2
 public function testGetLabelByPageId()
 {
     $pageId = 1;
     $label = 'Label by page id';
     $this->mockResourcePage->expects($this->once())->method('getCmsPageTitleById')->with($pageId)->willReturn($label);
     $this->linkElement->setData('page_id', $pageId);
     $this->assertEquals($label, $this->linkElement->getLabel());
 }
コード例 #9
0
 /**
  * Delete Page
  *
  * @param \Magento\Cms\Api\Data\PageInterface $page
  * @return bool
  * @throws CouldNotDeleteException
  */
 public function delete(\Magento\Cms\Api\Data\PageInterface $page)
 {
     try {
         $this->resource->delete($page);
     } catch (\Exception $exception) {
         throw new CouldNotDeleteException(__('Could not delete the page: %1', $exception->getMessage()));
     }
     return true;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function delete(\Magento\Framework\Model\AbstractModel $object)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'delete');
     if (!$pluginInfo) {
         return parent::delete($object);
     } else {
         return $this->___callPlugins('delete', func_get_args(), $pluginInfo);
     }
 }
コード例 #11
0
ファイル: Link.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Prepare label using passed text as parameter.
  * If anchor text was not specified use title instead and
  * if title will be blank string, page identifier will be used.
  *
  * @return string
  */
 public function getLabel()
 {
     if ($this->getData('anchor_text')) {
         $this->_anchorText = $this->getData('anchor_text');
     } elseif ($this->getTitle()) {
         $this->_anchorText = $this->getTitle();
     } elseif ($this->getData('href')) {
         $this->_anchorText = $this->_resourcePage->setStore($this->_storeManager->getStore())->getCmsPageTitleByIdentifier($this->getData('href'));
     } elseif ($this->getData('page_id')) {
         $this->_anchorText = $this->_resourcePage->getCmsPageTitleById($this->getData('page_id'));
     } else {
         $this->_anchorText = $this->getData('href');
     }
     return $this->_anchorText;
 }
コード例 #12
0
 /**
  * @test
  *
  * @expectedException \Magento\Framework\Exception\CouldNotDeleteException
  */
 public function testDeleteException()
 {
     $this->pageResource->expects($this->once())->method('delete')->with($this->page)->willThrowException(new \Exception());
     $this->repository->delete($this->page);
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function getValidationRulesBeforeSave()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getValidationRulesBeforeSave');
     if (!$pluginInfo) {
         return parent::getValidationRulesBeforeSave();
     } else {
         return $this->___callPlugins('getValidationRulesBeforeSave', func_get_args(), $pluginInfo);
     }
 }