public function testSaveRecords() { $cmdl = $this->connection->getCMDLForContentType('example01'); $contentTypeDefinition = Parser::parseCMDLString($cmdl); $contentTypeDefinition->setName('example01'); $this->connection->selectContentType('example01'); for ($i = 1; $i <= 5; $i++) { $record = new Record($contentTypeDefinition, 'New Record ' . $i); $record->setProperty('article', 'Test ' . $i); $id = $this->connection->saveRecord($record); $this->assertEquals($i, $id); } }
public function testNumericalLists() { /* @var ContentTypeDefinition */ $contentTypeDefinition = Parser::parseCMDLString('@custom type (a,b,c) (a,b,b)'); $this->assertCount(1, $contentTypeDefinition->getCustomAnnotations()); $customAnnotations = $contentTypeDefinition->getCustomAnnotations(); /** @var CustomAnnotation $customAnnotation */ $customAnnotation = $customAnnotations[0]; $this->assertCount(3, $customAnnotation->getList(1)); $this->assertCount(2, $customAnnotation->getList(2)); $this->assertFalse($customAnnotation->hasList(3)); $this->assertCount(3, $customAnnotation->getNumericalList(1)); $this->assertCount(3, $customAnnotation->getNumericalList(2)); $this->assertFalse($customAnnotation->hasNumericalList(3)); }
public function saveConfigTypeCMDL($repositoryName, $configTypeName, $cmdl, $locale = null, $createRepository = true) { if ($configTypeName != Util::generateValidIdentifier($configTypeName) || $repositoryName != Util::generateValidIdentifier($repositoryName)) { throw new RepositoryException('Invalid repository and/or config type name(s).'); } try { $configTypeDefinition = Parser::parseCMDLString($cmdl); $configTypeDefinition->setName($configTypeName); } catch (CMDLParserException $e) { throw new RepositoryException('Could not parse definition for config type ' . $configTypeName); } if ($this->hasRepository($repositoryName) || $createRepository == true) { $filename = $this->getCMDLDirectory(); if (file_exists($filename)) { $filename .= '/' . $repositoryName; if (!file_exists($filename)) { mkdir($filename); } $filename .= '/config'; if (!file_exists($filename)) { mkdir($filename); } $filename .= '/' . $configTypeName . '.cmdl'; if (@file_put_contents($filename, $cmdl)) { $this->app['db']->refreshConfigTypesTableStructure($repositoryName, $configTypeDefinition); $this->configTypeDefinitions = array(); return true; } } } return false; }
public function testTimeShiftableAnnotation() { /* @var ContentTypeDefinition */ $contentTypeDefinition = Parser::parseCMDLString(''); $this->assertFalse($contentTypeDefinition->isTimeShiftAble()); /* @var ContentTypeDefinition */ $contentTypeDefinition = Parser::parseCMDLString('@time-shiftable '); $this->assertTrue($contentTypeDefinition->isTimeShiftAble()); }
public function createRecordFromCMDL($cmdl, $properties = [], $viewName = "default", $workspace = "default", $language = "default") { $contentTypeDefinition = Parser::parseCMDLString($cmdl); /** @var Record $record */ $record = new Record($contentTypeDefinition, '', $viewName, $workspace, $language); $revision = isset($jsonRecord['revision']) ? $jsonRecord['revision'] : 0; $record->setRevision($revision); if ($this->getOption('validateProperties') == true) { foreach ($properties as $property => $value) { $record->setProperty($property, $value); } } else { $record->setProperties($properties); } return $record; }
public function testWorkspacesAndLanguagesRestrictions() { /* @var ContentTypeDefinition */ $contentTypeDefinition = Parser::parseCMDLString(' a @insert a (1:i1) (default) () +++i1+++ b '); $this->assertContains('a', $contentTypeDefinition->getProperties()); $this->assertContains('b', $contentTypeDefinition->getProperties()); /* @var ViewDefinition */ $viewDefinition = $contentTypeDefinition->getViewDefinition('default'); $formelements = $viewDefinition->getFormElementDefinitions(); /** @var InsertFormElementDefinition $insertFormElement */ $insertFormElement = $formelements[1]; $this->assertContains('default', $insertFormElement->getWorkspaces()); $this->assertTrue($insertFormElement->hasWorkspacesRestriction()); $this->assertFalse($insertFormElement->hasLanguagesRestriction()); /* @var ContentTypeDefinition */ $contentTypeDefinition = Parser::parseCMDLString(' a @insert i1 (default) () +++i1+++ b '); $this->assertContains('a', $contentTypeDefinition->getProperties()); $this->assertContains('b', $contentTypeDefinition->getProperties()); /** @var InsertFormElementDefinition $insertFormElement */ $insertFormElement = $formelements[1]; $this->assertContains('default', $insertFormElement->getWorkspaces()); $this->assertTrue($insertFormElement->hasWorkspacesRestriction()); $this->assertFalse($insertFormElement->hasLanguagesRestriction()); }
public static function postEditConfigType(Application $app, Request $request, $configTypeAccessHash) { /** @var Repository $repository */ $repository = $app['repos']->getRepositoryByConfigTypeAccessHash($configTypeAccessHash); $response = array(); $response['success'] = false; if ($repository) { $cmdl = $request->get('cmdl'); try { /** @var ConfigTypeDefinition $contentTypeDefinition */ $configTypeDefinition = Parser::parseCMDLString($cmdl, null, null, 'config'); } catch (\Exception $e) { $response['message'] = $e->getMessage(); } try { /** @var ConfigTypeDefinition $contentTypeDefinition */ $configTypeDefinition = $repository->getConfigTypeDefinition(); $connection = $repository->getWriteConnection(); if ($connection->saveConfigTypeCMDL($configTypeDefinition->getName(), $cmdl)) { $response['success'] = true; $app['menus']->clearCache(); } } catch (\Exception $e) { } } return new JsonResponse($response); }
public function saveConfigTypeCMDL($repositoryName, $configTypeName, $cmdl, $locale = null, $createRepository = true) { if ($configTypeName != Util::generateValidIdentifier($configTypeName) || $repositoryName != Util::generateValidIdentifier($repositoryName)) { throw new RepositoryException('Invalid repository and/or config type name(s).'); } try { $configTypeDefinition = Parser::parseCMDLString($cmdl); $configTypeDefinition->setName($configTypeName); } catch (ParserException $e) { throw new RepositoryException('Could not parse definition for config type ' . $configTypeName); } if ($this->hasRepository($repositoryName) || $createRepository == true) { /** @var PDO $db */ $dbh = $this->app['db']->getConnection(); try { $timestamp = $this->app['repos']->getTimeshiftTimestamp(); $sql = 'INSERT INTO _cmdl_ (repository,data_type,name,cmdl,lastchange_timestamp) VALUES (? ,"config", ? , ? , ?) ON DUPLICATE KEY UPDATE cmdl = ?, lastchange_timestamp = ?'; $params = array(); $params[] = $repositoryName; $params[] = $configTypeName; $params[] = $cmdl; $params[] = $timestamp; $params[] = $cmdl; $params[] = $timestamp; $stmt = $dbh->prepare($sql); $stmt->execute($params); $this->app['db']->refreshConfigTypesTableStructure($repositoryName, $configTypeDefinition); $this->configTypeDefinitions = array(); return true; } catch (\PDOException $e) { } } return false; }
public function testPrintFormElementDefinition() { /* @var ContentTypeDefinition */ $contentTypeDefinition = Parser::parseCMDLString('> Hello world!'); /* @var ViewDefinition */ $viewDefinition = $contentTypeDefinition->getViewDefinition('default'); $formElements = $viewDefinition->getFormElementDefinitions(); $formElementDefinition = $formElements[0]; $this->assertInstanceOf('CMDL\\FormElementDefinitions\\PrintFormElementDefinition', $formElementDefinition); $this->assertEquals('Hello world!', $formElementDefinition->getDisplay()); }