Exemplo n.º 1
0
 /**
  * @test
  * @group small
  * @group dev
  * @group library
  */
 public function test_getById_returnsMergedFormValues()
 {
     // ARRANGE
     $websiteId = 'WEBSITE-ID';
     $websiteSettingsId = 'rz_shop';
     $baseDirectory = $this->getBaseDirectory();
     $source = $this->getWebsiteSettingsSource($websiteId, array(array($baseDirectory, $websiteSettingsId)));
     $expectedFormValues = (object) array('filesystem' => array('foo', 'bar'), 'doctrine' => array('bar', 'foo'), 'both_object' => (object) array('dao' => 'doctrine'), 'both_array' => array('dao' => 'doctrine'), 'both_string' => 'doctrine');
     $filesystemData = new WebsiteSettingsData();
     $filesystemData->setWebsiteId($websiteId);
     $filesystemData->setId($websiteSettingsId);
     $filesystemData->setFormValues((object) array('filesystem' => array('foo', 'bar'), 'both_object' => (object) array('dao' => 'filesystem'), 'both_array' => array('dao' => 'filesystem'), 'both_string' => 'filesystem'));
     $filesystemDaoMock = $this->getFilesystemDaoMock();
     $filesystemDaoMock->expects($this->once())->method('getById')->with($this->equalTo($source), $this->equalTo($websiteSettingsId))->will($this->returnValue($filesystemData));
     $doctrineData = new WebsiteSettingsData();
     $doctrineData->setWebsiteId($websiteId);
     $doctrineData->setId($websiteSettingsId);
     $doctrineData->setFormValues((object) array('doctrine' => array('bar', 'foo'), 'both_object' => (object) array('dao' => 'doctrine'), 'both_array' => array('dao' => 'doctrine'), 'both_string' => 'doctrine'));
     $doctrineDaoMock = $this->getDoctrineDaoMock();
     $doctrineDaoMock->expects($this->once())->method('exists')->with($this->equalTo($source), $this->equalTo($websiteSettingsId))->will($this->returnValue(true));
     $doctrineDaoMock->expects($this->once())->method('getById')->with($this->equalTo($source), $this->equalTo($websiteSettingsId))->will($this->returnValue($doctrineData));
     $dao = $this->getAllDao($filesystemDaoMock, $doctrineDaoMock);
     // ACT
     $actualWebsiteSettings = $dao->getById($source, $websiteSettingsId);
     // ASSERT
     $this->assertInstanceOf('\\Cms\\Data\\WebsiteSettings', $actualWebsiteSettings);
     $this->assertEquals($expectedFormValues, $actualWebsiteSettings->getFormValues());
 }
 /**
  * @param string $websiteId
  * @param array  $websiteSettings
  *
  * @return ServiceBasedWebsiteInfoStorage
  */
 protected function getServiceBasedWebsiteInfoStorage($websiteId, array $websiteSettings)
 {
     // Create website service  mock
     $websiteServiceStub = $this->getMockBuilder('\\Cms\\Service\\Website')->disableOriginalConstructor()->getMock();
     // Create website settings service mock
     $websiteSettingsServiceStub = $this->getMockBuilder('\\Cms\\Service\\WebsiteSettings')->disableOriginalConstructor()->getMock();
     $websiteSettingsServiceStub->expects($this->any())->method('getById')->will($this->returnCallback(function ($wId, $sId) use($websiteId, $websiteSettings) {
         if ($wId != $websiteId || !is_string($sId) || !array_key_exists($sId, $websiteSettings)) {
             throw new \Exception();
         }
         $data = new WebsiteSettingsData();
         $data->setWebsiteId($wId);
         $data->setId($sId);
         $data->setFormValues($websiteSettings[$sId]);
         return $data;
     }));
     return new ServiceBasedWebsiteInfoStorage($websiteId, $websiteServiceStub, $websiteSettingsServiceStub);
 }
Exemplo n.º 3
0
 /**
  * @param DataWebsiteSettings $websiteSettings
  *
  * @return array
  */
 protected function getFormValuesAsArray(DataWebsiteSettings $websiteSettings)
 {
     $formValues = $websiteSettings->getFormValues();
     if (is_object($formValues)) {
         $formValuesAsArray = get_object_vars($formValues);
     } elseif (!is_array($formValues)) {
         $formValuesAsArray = array();
     }
     return $formValuesAsArray;
 }
Exemplo n.º 4
0
 /**
  * set the WebsiteSettings attributes to orm
  *
  * @param \Orm\Entity\WebsiteSettings $orm
  * @param \Cms\Data\WebsiteSettings   $websiteSettings
  */
 protected function setAttributesToOrm(OrmWebsiteSettings $orm, DataWebsiteSettings $websiteSettings)
 {
     $orm->setFormValues(json_encode($websiteSettings->getFormValues()));
 }
Exemplo n.º 5
0
 protected function setValuesFromData(WebsiteSettingsData $data)
 {
     $this->setId($data->getId());
     $this->setWebsiteId($data->getWebsiteId());
     $this->setName($data->getName());
     $this->setDescription($data->getDescription());
     $this->setVersion($data->getVersion());
     $this->setFrom($data->getForm());
     $this->setFromData($data->getFormValues());
 }
Exemplo n.º 6
0
 /**
  * @param DataWebsiteSettings $websiteSettings
  * @param array               $attributes
  */
 protected function setAttributesToDataWebsiteSettings(DataWebsiteSettings $websiteSettings, array $attributes)
 {
     if (array_key_exists('formValues', $attributes)) {
         $websiteSettings->setFormValues($attributes['formValues']);
     }
 }
Exemplo n.º 7
0
 /**
  * @param string     $websiteId
  * @param string     $id
  * @param SourceItem $sourceItem
  * @param \stdClass  $manifest
  *
  * @return DataWebsiteSettings
  */
 protected function loadDataObject($websiteId, $id, SourceItem $sourceItem, \stdClass $manifest)
 {
     $websiteSettings = new DataWebsiteSettings();
     $websiteSettings->setWebsiteid($websiteId);
     $websiteSettings->setId($id);
     $websiteSettings->setReadonly($sourceItem->isReadonly());
     $websiteSettings->setSource($sourceItem);
     $websiteSettings->setSourceType($sourceItem->getType());
     if (property_exists($manifest, 'name') && is_object($manifest->name)) {
         $websiteSettings->setName($manifest->name);
     }
     if (property_exists($manifest, 'description') && is_object($manifest->description)) {
         $websiteSettings->setDescription($manifest->description);
     }
     if (property_exists($manifest, 'version')) {
         $websiteSettings->setVersion($manifest->version);
     }
     if (property_exists($manifest, 'form')) {
         $websiteSettings->setForm($manifest->form);
     }
     if (property_exists($manifest, 'formValues')) {
         $websiteSettings->setFormValues($manifest->formValues);
     }
     return $websiteSettings;
 }