コード例 #1
0
ファイル: PreviewTest.php プロジェクト: kriswillis/sulu
 public function testRealScenario()
 {
     $data = $this->prepareData();
     // start preview from FORM
     $content = $this->preview->start(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $this->assertEquals('Test1', $content->getPropertyValue('title'));
     $this->assertEquals('Lorem Ipsum dolorem apsum', $content->getPropertyValue('article'));
     // render PREVIEW
     $response = $this->preview->render(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $expected = $this->render('Test1', 'Lorem Ipsum dolorem apsum', [['title' => 'Block-Title-1', 'article' => ['Block-Article-1-1', 'Block-Article-1-2']], ['title' => 'Block-Title-2', 'article' => ['Block-Article-2-1', 'Block-Article-2-2']]]);
     $this->assertEquals($expected, $response);
     // change a property in FORM
     $content = $this->preview->updateProperty(1, $data[0]->getUuid(), 'sulu_io', 'en', 'title', 'New Title');
     $this->assertEquals('New Title', $content->getPropertyValue('title'));
     $this->assertEquals('Lorem Ipsum dolorem apsum', $content->getPropertyValue('article'));
     $content = $this->preview->updateProperty(1, $data[0]->getUuid(), 'sulu_io', 'en', 'article', 'asdf');
     $this->assertEquals('New Title', $content->getPropertyValue('title'));
     $this->assertEquals('asdf', $content->getPropertyValue('article'));
     // update PREVIEW
     $changes = $this->preview->getChanges(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $this->assertEquals(2, sizeof($changes));
     $this->assertEquals(['New Title', 'PREF: New Title'], $changes['title']);
     $this->assertEquals(['asdf'], $changes['article']);
     // update PREVIEW
     $changes = $this->preview->getChanges(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $this->assertEquals(0, sizeof($changes));
     // rerender PREVIEW
     $response = $this->preview->render(1, $data[0]->getUuid(), 'sulu_io', 'en');
     $expected = $this->render('New Title', 'asdf', [['title' => 'Block-Title-1', 'article' => ['Block-Article-1-1', 'Block-Article-1-2']], ['title' => 'Block-Title-2', 'article' => ['Block-Article-2-1', 'Block-Article-2-2']]]);
     $this->assertEquals($expected, $response);
 }
コード例 #2
0
 /**
  * Updates properties of current session content.
  *
  * @param ConnectionInterface   $from
  * @param MessageHandlerContext $context
  * @param array                 $msg
  *
  * @return array
  *
  * @throws PreviewNotStartedException
  * @throws MissingParameterException
  */
 private function update(ConnectionInterface $from, MessageHandlerContext $context, $msg)
 {
     // check context parameters
     if (!$context->has('content') && !$context->has('locale') && !$context->has('webspaceKey') && !$context->has('user')) {
         throw new PreviewNotStartedException();
     }
     // get user id
     $user = $context->get('user');
     // get session vars
     $contentUuid = $context->get('content');
     $locale = $context->get('locale');
     $webspaceKey = $context->get('webspaceKey');
     // init msg vars
     if (!array_key_exists('data', $msg) && is_array($msg['data'])) {
         throw new MissingParameterException('data');
     }
     $changes = $msg['data'];
     $this->requestAnalyzer->setWebspaceKey($webspaceKey);
     $this->requestAnalyzer->setLocalizationCode($locale);
     foreach ($changes as $property => $data) {
         // update property
         $this->preview->updateProperty($user, $contentUuid, $webspaceKey, $locale, $property, $data);
     }
     return ['command' => 'update', 'content' => $contentUuid, 'data' => $this->preview->getChanges($user, $contentUuid, $webspaceKey, $locale)];
 }
コード例 #3
0
 /**
  * Connection lost.
  *
  * @param ConnectionInterface $conn
  * @param MessageHandlerContext $context
  */
 public function onClose(ConnectionInterface $conn, MessageHandlerContext $context)
 {
     // get session vars
     $user = $context->get('user');
     $locale = $context->get('locale');
     $contentUuid = $context->get('content');
     $webspaceKey = $context->get('webspaceKey');
     $this->preview->stop($user, $contentUuid, $webspaceKey, $locale);
 }