Пример #1
0
 public function testRemoveByUrl()
 {
     $this->post->expects($this->exactly(2))->method('checkUrlKey')->willReturn(self::POST_ID);
     $this->post->expects($this->exactly(2))->method('load')->with(self::POST_ID)->willReturn($this->post);
     $this->post->expects($this->once())->method('getId')->willReturn(self::POST_ID);
     $this->postFactory->expects($this->exactly(2))->method('create')->willReturn($this->post);
     $this->post->expects($this->once())->method('getUrlKey')->willReturn(self::URL);
     $actual = $this->postRegistry->retrieveByUrl(self::URL);
     $this->assertSame($this->post, $actual);
     $this->postRegistry->removeByUrl(self::URL);
     $actual = $this->postRegistry->retrieveByUrl(self::URL);
     $this->assertSame($this->post, $actual);
 }
Пример #2
0
 public function save(PostInterface $post)
 {
     $this->validate($post);
     $postData = $post->getData();
     $postModel = $this->_postFactory->create();
     $postModel->load($post->getId());
     $postModel->setData($postData);
     $postModel->save();
     $this->_postRegistry->push($postModel);
     $savedPost = $this->getByUrl($post->getUrlKey());
     $this->_eventManager->dispatch('post_save_after_data_object', ['post_data_object' => $savedPost, 'orig_post_data_object' => $post]);
     return $savedPost;
 }