fromIdentifier() public static method

Initiliaze from identifier
public static fromIdentifier ( string $identifier ) : Model
$identifier string Identifier
return Model
Example #1
0
 public function testImportScript()
 {
     $this->assertFalse($this->object->import('<xml></xml>'));
     $this->assertFalse($this->object->import(''));
     $this->assertFalse($this->object->import('<a></b>'));
     $this->createUser();
     $this->createContent();
     $data = $this->object->export($this->what);
     $this->removeContent();
     $this->assertTrue($this->object->import($data));
     $view = ViewModel::fromIdentifier('ViewContentIdentifier');
     $layout = LayoutModel::fromIdentifier('LayoutContentIdentifier');
     $script = ScriptModel::fromIdentifier('ScriptContentIdentifier');
     $this->assertInstanceOf('Gc\\View\\Model', $view);
     $this->assertInstanceOf('Gc\\Layout\\Model', $layout);
     $this->assertInstanceOf('Gc\\Script\\Model', $script);
     //Test datatype
     $datatype = new DatatypeModel();
     $datatype = $datatype->fromArray($datatype->fetchRow($datatype->select(array('name' => 'DatatypeTest'))));
     $this->assertInstanceOf('Gc\\Datatype\\Model', $datatype);
     //Test document type
     $documentType = new DocumentTypeModel();
     $documentType = $documentType->fromArray($documentType->fetchRow($documentType->select(array('name' => 'DocumentType'))));
     $this->assertInstanceOf('Gc\\DocumentType\\Model', $documentType);
     $this->assertCount(1, $documentType->getDependencies());
     $this->assertCount(1, $documentType->getAvailableViews()->getViews());
     $tabs = $documentType->getTabs();
     $this->assertCount(1, $tabs);
     $properties = $tabs[0]->getProperties();
     $this->assertCount(1, $properties);
     //Test document
     $document = DocumentModel::fromUrlKey('');
     $this->assertInstanceOf('Gc\\Document\\Model', $document);
     $property = $document->getProperty('azd');
     $this->assertInstanceof('Gc\\Property\\Model', $property);
     $this->assertEquals('string', $property->getValue());
     $document->delete();
     //Delete data
     $properties[0]->delete();
     $tabs[0]->delete();
     $datatype->delete();
     $view->delete();
     $script->delete();
     $layout->delete();
     $documentType->delete();
     $this->removeUser();
 }
Example #2
0
 /**
  * Upload a file to the server
  *
  * @return \Zend\Http\Response
  */
 public function uploadAction()
 {
     $layoutId = $this->getRouteMatch()->getParam('id', null);
     if (!empty($layoutId)) {
         $layout = Layout\Model::fromId($layoutId);
         if (empty($layout) or empty($_FILES['upload']['tmp_name']) or $_FILES['upload']['error'] != UPLOAD_ERR_OK) {
             $this->flashMessenger()->addErrorMessage('Can not upload layout');
             return $this->redirect()->toRoute('development/layout/edit', array('id' => $layoutId));
         }
         $layout->setContent(file_get_contents($_FILES['upload']['tmp_name']));
         $layout->save();
         $this->flashMessenger()->addSuccessMessage('Layout updated');
         return $this->redirect()->toRoute('development/layout/edit', array('id' => $layoutId));
     }
     if (empty($_FILES['upload'])) {
         $this->flashMessenger()->addErrorMessage('Can not upload layouts');
         return $this->redirect()->toRoute('development/layout');
     }
     foreach ($_FILES['upload']['name'] as $idx => $name) {
         if ($_FILES['upload']['error'][$idx] != UPLOAD_ERR_OK) {
             continue;
         }
         $identifier = preg_replace('~\\.phtml$~', '', $name);
         $layout = Layout\Model::fromIdentifier($identifier);
         if (empty($layout)) {
             continue;
         }
         $layout->setContent(file_get_contents($_FILES['upload']['tmp_name'][$idx]));
         $layout->save();
     }
     $this->flashMessenger()->addSuccessMessage('Layouts updated');
     return $this->redirect()->toRoute('development/layout');
 }
Example #3
0
 /**
  * Test
  *
  * @return void
  */
 public function testEditActionWithPostData()
 {
     $layoutModel = LayoutModel::fromArray(array('name' => 'LayoutName', 'identifier' => 'LayoutIdentifier'));
     $layoutModel->save();
     $this->dispatch('/admin/development/layout/edit/' . $layoutModel->getId(), 'POST', array('name' => 'LayoutName', 'identifier' => 'Identifier', 'delayoution' => 'Delayoution'));
     $this->assertResponseStatusCode(302);
     $this->assertModuleName('GcDevelopment');
     $this->assertControllerName('LayoutController');
     $this->assertControllerClass('LayoutController');
     $this->assertMatchedRouteName('development/layout/edit');
     LayoutModel::fromIdentifier('Identifier')->delete();
 }
Example #4
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeIdentifier()
 {
     $model = $this->object->fromIdentifier('fake-identifier');
     $this->assertFalse($model);
 }