public function testSaveRecords() { $this->repository->selectContentType('example01'); $record = $this->repository->createRecord('New Record'); $record->setProperty('source', 'a'); $id = $this->repository->saveRecord($record); $this->assertEquals(1, $id); $record = $this->repository->createRecord('New Record'); $record->setProperty('source', 'b'); $id = $this->repository->saveRecord($record); $this->assertEquals(2, $id); $record = $this->repository->createRecord('Differing Name'); $record->setProperty('source', 'c'); $id = $this->repository->saveRecord($record); $this->assertEquals(3, $id); $records = $this->repository->getRecords('name = New Record'); $this->assertCount(2, $records); $filter1 = new PropertyFilter('name = New Record'); $filter2 = new PropertyFilter('name = Differing Name'); $orFilter = new ORFilter([$filter1, $filter2]); $records = $this->repository->getRecords($orFilter); $this->assertCount(3, $records); $records = $this->repository->getRecords('source > b'); $this->assertCount(1, $records); $filter1 = new PropertyFilter('source > a'); $filter2 = new PropertyFilter('name = Differing Name'); $andFilter = new ANDFilter([$filter1, $filter2]); $records = $this->repository->getRecords($andFilter); $this->assertCount(1, $records); }
public function testSliceFilteredRecords() { $this->repository->selectContentType('example01'); $records = $this->repository->getRecords('source > 3', 'source', 1, 5); $this->assertCount(5, $records); $this->assertEquals([4, 5, 6, 7, 8], array_keys($records)); $records = $this->repository->getRecords('source > 3', 'source', 2, 5); $this->assertCount(2, $records); $this->assertEquals([9, 10], array_keys($records)); }
public function testNewConnection() { $this->repository->selectContentType('example01'); $record = $this->repository->getRecord(1); $this->assertEquals(5, $record->getRevision()); $this->assertEquals('example01', $record->getContentTypeName()); $this->assertEquals(1, $record->getID()); $this->assertEquals('New Record 1 - Revision 5', $record->getName()); $this->assertEquals('Test 1', $record->getProperty('article')); $records = $this->repository->getRecords(); $this->assertCount(5, $records); $this->assertEquals(5, $this->repository->countRecords()); }
public function testGetRecords() { $repository = new Repository('phpunit', $this->connection); $repository->selectContentType('temp'); $records = $repository->getRecords(); $this->assertCount(608, $records); }
public static function setUpBeforeClass() { if (defined('PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_HOST')) { $configuration = new MySQLSchemalessConfiguration(); $configuration->initDatabase(PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_HOST, PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_DBNAME, PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_USERNAME, PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_PASSWORD); $configuration->setCMDLFolder(__DIR__ . '/../../resources/ContentArchiveExample1/cmdl'); $configuration->setRepositoryName('phpunit'); $configuration->addContentTypes(); $database = $configuration->getDatabase(); $database->execute('DROP TABLE IF EXISTS _cmdl_'); $database->execute('DROP TABLE IF EXISTS _counter_'); $database->execute('DROP TABLE IF EXISTS phpunit$profiles'); $connection = $configuration->createReadWriteConnection(); $repository = new Repository('phpunit', $connection); $repository->selectContentType('profiles'); $record = $repository->createRecord('dmc digital media center', 5); $repository->saveRecord($record); $record = $repository->createRecord('Agency 16', 16); $repository->saveRecord($record); $repository->selectWorkspace('live'); $record = $repository->createRecord('dmc digital media center', 5); $repository->saveRecord($record); $repository->selectLanguage('de'); $record = $repository->createRecord('dmc digital media center', 5); $repository->saveRecord($record); KVMLoggerFactory::createWithKLogger(__DIR__ . '/../../../tmp'); } }
public function testSortByUserInfo() { $this->repository->selectContentType('example01'); $userInfo1 = new UserInfo('a', 'a', 'a', 1); $userInfo2 = new UserInfo('b', 'b', 'b', 2); $record1 = $this->repository->createRecord('New Record')->setId(1); $record2 = $this->repository->createRecord('New Record')->setId(2); $records = [1 => $record1, 2 => $record2]; $record1->setCreationUserInfo($userInfo1); $record2->setCreationUserInfo($userInfo2); $records = RecordsSorter::orderRecords($records, ['.info.creation.username']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.firstname']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.lastname']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.timestamp']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.username-']); $this->assertEquals([2, 1], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.firstname-']); $this->assertEquals([2, 1], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.lastname-']); $this->assertEquals([2, 1], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.creation.timestamp-']); $this->assertEquals([2, 1], array_keys($records)); $record1->setLastChangeUserInfo($userInfo1); $record2->setLastChangeUserInfo($userInfo2); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.username']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.firstname']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.lastname']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.timestamp']); $this->assertEquals([1, 2], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.username-']); $this->assertEquals([2, 1], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.firstname-']); $this->assertEquals([2, 1], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.lastname-']); $this->assertEquals([2, 1], array_keys($records)); $records = RecordsSorter::orderRecords($records, ['.info.lastchange.timestamp-']); $this->assertEquals([2, 1], array_keys($records)); }
public function exportXLSX(Repository $repository, $contentTypeName, $workspace = 'default', $language = 'default', $viewName = 'exchange') { $repository->selectContentType($contentTypeName); // Select view and fallback if necessary $contentTypeDefinition = $repository->getContentTypeDefinition(); $viewDefinition = $contentTypeDefinition->getExchangeViewDefinition($viewName); $viewName = $viewDefinition->getName(); $this->writeln('Connecting repository'); $this->writeln(''); $repository->selectWorkspace($workspace); $repository->selectLanguage($language); $repository->selectView($viewName); /** @var Record[] $records */ $records = $repository->getRecords('', '.id', 1); if ($records !== false) { // Create new PHPExcel object $objPHPExcel = new \PHPExcel(); // use temp folder for processing of large files $cacheMethod = \PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $cacheSettings = array('memoryCacheSize' => '12MB'); \PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); // Set document properties $objPHPExcel->getProperties()->setCreator("AnyContent CMCK")->setLastModifiedBy("AnyContent CMCK")->setTitle("Full Export from content type " . $contentTypeDefinition->getTitle())->setSubject("AnyContent Export")->setDescription(""); $worksheet = $objPHPExcel->setActiveSheetIndex(0); $worksheet->setTitle('Export'); $worksheet->setCellValueByColumnAndRow(0, 1, '.id'); $worksheet->getStyleByColumnAndRow(0, 1)->getFont()->setBold(false)->setItalic(true); $worksheet->setCellValueByColumnAndRow(1, 1, '.revision'); $worksheet->getStyleByColumnAndRow(1, 1)->getFont()->setBold(false)->setItalic(true); $row = 1; $column = 2; foreach ($contentTypeDefinition->getProperties($viewName) as $property) { $worksheet->setCellValueByColumnAndRow($column, $row, $property); $worksheet->getStyleByColumnAndRow($column, $row)->getFont()->setBold(true); $worksheet->getColumnDimensionByColumn($column)->setWidth(20); $column++; } $row++; foreach ($records as $record) { $this->writeln('Processing record ' . $record->getID() . ' - ' . $record->getName()); $worksheet->setCellValueByColumnAndRow(0, $row, $record->getID()); $worksheet->setCellValueByColumnAndRow(1, $row, $record->getRevision()); $column = 2; foreach ($contentTypeDefinition->getProperties($viewName) as $property) { $worksheet->setCellValueByColumnAndRow($column, $row, $record->getProperty($property)); $column++; } $row++; } $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); ob_start(); $objWriter->save('php://output'); $excelOutput = ob_get_clean(); return $excelOutput; } return false; }
public function testSortRecords() { $this->repository->selectContentType('example01'); $this->repository->sortRecords([10 => 0, 9 => 10, 8 => 10]); $records = $this->repository->getRecords(); $this->assertEquals(10, $records[9]->getParent()); $this->assertEquals(10, $records[8]->getParent()); $this->assertEquals(0, $records[10]->getParent()); $this->assertNull($records[1]->getParent()); $this->assertNotNull($records[10]->getParent()); $this->assertEquals(1, $records[9]->getPosition()); $this->assertEquals(2, $records[8]->getPosition()); $records = $this->repository->getSortedRecords(0); $this->assertEquals([10, 9, 8], array_keys($records)); $this->assertEquals(2, $records[9]->getLevel()); $this->assertEquals(2, $records[8]->getLevel()); $this->assertEquals(1, $records[10]->getLevel()); $records = $this->repository->getSortedRecords(10); $this->assertEquals([9, 8], array_keys($records)); }
public function testSaveRecords() { $this->repository->selectContentType('example01'); for ($i = 1; $i <= 5; $i++) { $record = $this->repository->createRecord('New Record ' . $i); $this->assertEquals('DEFAULT', $record->getProperty('article', 'DEFAULT')); $record->setProperty('article', ''); $id = $this->repository->saveRecord($record); $this->assertEquals($i, $id); } $record = $this->repository->getRecord(1); $this->assertEquals('DEFAULT', $record->getProperty('article', 'DEFAULT')); $record->setProperty('article', 0); $id = $this->repository->saveRecord($record); $record = $this->repository->getRecord(1); $this->assertEquals('0', $record->getProperty('article', 'DEFAULT')); $record->setProperty('article', null); $id = $this->repository->saveRecord($record); $record = $this->repository->getRecord(1); $this->assertEquals('DEFAULT', $record->getProperty('article', 'DEFAULT')); }
public function testReverseSortRecords() { $this->repository->selectContentType('example01'); // 1 // 2 // -- 4 // -- 8 // -- 5 // -- 6 // 3 // -- 9 // 7 $this->repository->sortRecords([1 => 0, 2 => 0, 4 => 2, 8 => 4, 5 => 4, 6 => 2, 3 => 0, 9 => 3, 7 => 0]); $records = $this->repository->getRecords(); $this->assertEquals(2, $records[6]->getParent()); $records = $this->repository->getSortedRecords(4); $this->assertEquals([8, 5], array_keys($records)); $records = $this->repository->getSortedRecords(4, true); $this->assertEquals([4, 8, 5], array_keys($records)); $records = $this->repository->getSortedRecords(4, true, 0, 1); $this->assertEquals([2, 4], array_keys($records)); $records = $this->repository->getSortedRecords(4, false, 0, 1); $this->assertEquals([2], array_keys($records)); $records = $this->repository->getSortedRecords(5, true, 0, 1); $this->assertEquals([2, 4, 5], array_keys($records)); $records = $this->repository->getSortedRecords(9, true, 0, 1); $this->assertEquals([3, 9], array_keys($records)); $records = $this->repository->getSortedRecords(4, true, 1, 1); $this->assertEquals([2, 4, 8, 5], array_keys($records)); $records = $this->repository->getSortedRecords(2, false, 1); $this->assertEquals([4, 6], array_keys($records)); $records = MenuBuilder::getBreadcrumb($this->repository, 'example01', 8); $this->assertEquals([2, 4, 8], array_keys($records)); $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 8); $this->assertEquals([1, 2, 4, 8, 5, 6, 3, 7], array_keys($records)); $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 6); $this->assertEquals([1, 2, 4, 6, 3, 7], array_keys($records)); $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 4); $this->assertEquals([1, 2, 4, 8, 5, 6, 3, 7], array_keys($records)); }
public function testNumericalComparison() { $this->repository->selectContentType('example01'); $record1 = $this->repository->createRecord('New Record'); $record1->setProperty('source', '110'); $record2 = $this->repository->createRecord('Another Record'); $record2->setProperty('source', '10'); $record3 = $this->repository->createRecord('Another Record'); $record3->setProperty('source', '12'); $filter = new PropertyFilter('source < 111'); $this->assertTrue($filter->match($record1)); $this->assertTrue($filter->match($record2)); $this->assertTrue($filter->match($record3)); }
public function testSaveRecords() { $this->repository->selectContentType('example01'); for ($i = 1; $i <= 5; $i++) { $record = $this->repository->createRecord('New Record ' . $i); $record->setProperty('article', 'Test ' . $i); $id = $this->repository->saveRecord($record); $this->assertEquals($i, $id); } $this->repository->selectLanguage('es'); for ($i = 1; $i <= 5; $i++) { $record = $this->repository->createRecord('New Record ' . (5 + $i)); $record->setProperty('article', 'Test ' . (5 + $i)); $id = $this->repository->saveRecord($record); $this->assertEquals(5 + $i, $id); } $this->repository->selectWorkspace('live'); for ($i = 1; $i <= 5; $i++) { $record = $this->repository->createRecord('New Record ' . (10 + $i)); $record->setProperty('article', 'Test ' . (10 + $i)); $id = $this->repository->saveRecord($record); $this->assertEquals(10 + $i, $id); } $this->repository->reset(); $c = $this->repository->countRecords(); $this->assertEquals(5, $c); $this->repository->selectLanguage('es'); $c = $this->repository->countRecords(); $this->assertEquals(5, $c); $this->repository->selectWorkspace('live'); $c = $this->repository->countRecords(); $this->assertEquals(5, $c); $this->repository->selectLanguage('default'); $c = $this->repository->countRecords(); $this->assertEquals(0, $c); }
public function testRecordCanAccessRepository() { $repository = new Repository('phpunit', $this->connection); $repository->selectContentType('example01'); $definition = $repository->getContentTypeDefinition(); $records = []; for ($i = 1; $i <= 5; $i++) { $record = new Record($definition, 'Test ' . $i); $records[] = $record; } $repository->saveRecords($records); $record = $repository->getRecord(1); $this->assertInstanceOf('AnyContent\\Client\\Repository', $record->getRepository()); $records = $repository->getRecords(); $record = array_shift($records); $this->assertInstanceOf('AnyContent\\Client\\Repository', $record->getRepository()); }
/** * Test showing the flaws of the full flash cache strategy * * @throws \AnyContent\AnyContentClientException */ public function testCacheStrategyFailure() { $repository = $this->repository; $repository->enableSingleContentRecordCaching(60); $repository->enableAllContentRecordsCaching(60); $repository->selectContentType('profiles'); $record = $repository->getRecord(1); $this->assertEquals('UDG', $record->getName()); $nonCachingRepository = new Repository('phpunit', $this->connection); $nonCachingRepository->selectContentType('profiles'); $record = $nonCachingRepository->getRecord(1); $this->assertEquals('UDG', $record->getName()); $record->setName(''); $nonCachingRepository->saveRecord($record); $record = $nonCachingRepository->getRecord(1); $this->assertEquals('', $record->getName()); $record = $repository->getRecord(1); $this->assertEquals('UDG', $record->getName()); }
public function testSetSequenceProperty() { $this->repository->selectContentType('profiles'); $record = $this->repository->getRecord(5); $sequence = $record->getSequence('standorte'); for ($i = 1; $i <= 5; $i++) { $item = new SequenceItem($record->getDataTypeDefinition(), 'standorte', 'standort'); $item->setProperty('standort_name', 'Location ' . $i); $sequence->addItem($item); $this->assertEquals($i, count($sequence)); } $record->setProperty('standorte', $sequence); $sequence = $record->getSequence('standorte'); $i = 0; foreach ($sequence as $item) { $i++; $this->assertEquals('Location ' . $i, $item->getProperty('standort_name')); $this->assertEquals('standort', $item->getItemType()); $this->assertInstanceOf('AnyContent\\Client\\SequenceItem', $item); } $this->assertEquals(5, $i); }
public function testGetRecords() { $repository = new Repository('phpunit', $this->connection); $repository->selectContentType('example01'); $records = $repository->getRecords(); $this->assertCount(5, $records); $this->assertEquals(5, $repository->countRecords()); $i = 0; foreach ($records as $id => $record) { $i++; $this->assertEquals($i, $id); $this->assertEquals('Test ' . $i, $record->getProperty('article')); } $repository->registerRecordClassForContentType('example01', 'AnyContent\\Client\\AlternateRecordClass'); $records = $repository->getRecords(); $i = 0; foreach ($records as $id => $record) { $i++; $this->assertInstanceOf('AnyContent\\Client\\AlternateRecordClass', $record); $this->assertEquals($i, $id); $this->assertEquals('New Record ' . $i, $record->getName()); $this->assertEquals('Test ' . $i, $record->getProperty('article')); } }
public static function setUpBeforeClass() { if (defined('PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_HOST')) { $source = __DIR__ . '/../../resources/ContentArchiveExample1/cmdl'; $target = __DIR__ . '/../../../tmp/MySqlSchemaLessCMDL'; $fs = new Filesystem(); if (file_exists($target)) { $fs->remove($target); } $fs->mirror($source, $target); $configuration = new MySQLSchemalessConfiguration(); $configuration->initDatabase(PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_HOST, PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_DBNAME, PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_USERNAME, PHPUNIT_CREDENTIALS_MYSQL_SCHEMALESS_PASSWORD); $configuration->setCMDLFolder($target); $configuration->setRepositoryName('phpunit'); $configuration->addContentTypes(); $database = $configuration->getDatabase(); $database->execute('DROP TABLE IF EXISTS _cmdl_'); $database->execute('DROP TABLE IF EXISTS _counter_'); $database->execute('DROP TABLE IF EXISTS phpunit$profiles'); $connection = $configuration->createReadWriteConnection(); $repository = new Repository('phpunit', $connection); $repository->selectContentType('profiles'); $record = $repository->createRecord('Agency 1', 1); $repository->saveRecord($record); $record = $repository->createRecord('Agency 2', 2); $repository->saveRecord($record); $record = $repository->createRecord('Agency 5', 5); $repository->saveRecord($record); $repository->selectWorkspace('live'); $record = $repository->createRecord('Agency 1', 1); $repository->saveRecord($record); $record = $repository->createRecord('Agency 2', 2); $repository->saveRecord($record); KVMLoggerFactory::createWithKLogger(__DIR__ . '/../../../tmp'); } }
public function importXLSX(Repository $repository, $contentTypeName, $filename, $workspace = 'default', $language = 'default', $viewName = 'exchange') { $this->count = 0; $this->records = null; $this->stash = array(); $this->error = false; $repository->selectContentType($contentTypeName); // Select view and fallback if necessary $contentTypeDefinition = $repository->getContentTypeDefinition(); $viewDefinition = $contentTypeDefinition->getExchangeViewDefinition($viewName); $viewName = $viewDefinition->getName(); $repository->selectWorkspace($workspace); $repository->selectLanguage($language); $repository->selectView($viewName); $objPHPExcel = \PHPExcel_IOFactory::load($filename); if ($objPHPExcel) { if ($this->isTruncateRecords()) { $this->deleteEffectiveRecords($repository, $workspace, $viewName, $language); } $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5 $idColumnIndex = null; $propertiesColumnIndices = array(); for ($i = 0; $i <= $highestColumnIndex; $i++) { $value = trim($objWorksheet->getCellByColumnAndRow($i, 1)->getValue()); if ($value != '') { if (substr($value, 0, 1) == '.') { if ($value == '.id') { $idColumnIndex = $i; } } else { $value = Util::generateValidIdentifier($value); if ($contentTypeDefinition->hasProperty($value, $viewName)) { $this->writeln('Detected valid property ' . $value); $propertiesColumnIndices[$value] = $i; } } } } $this->writeln(''); if (count($propertiesColumnIndices) != 0) { for ($row = 2; $row <= $highestRow; ++$row) { $id = null; if ($idColumnIndex !== null) { if (!$this->isGenerateNewIDs()) { $id = $objWorksheet->getCellByColumnAndRow($idColumnIndex, $row)->getValue(); } } $properties = array(); foreach ($propertiesColumnIndices as $property => $col) { $value = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); $properties[$property] = $value; } $record = new Record($contentTypeDefinition, 'Imported Record', $viewName, $workspace, $language); $record->setProperties($properties); $record->setID($id); $msg = $this->stashRecord($repository, $record, $workspace, $viewName, $language); $this->writeln($msg); } $this->writeln(''); $this->writeln('Found ' . $this->count . ' records to import'); $this->writeln(''); if ($this->count != 0) { $this->writeln('Starting bulk import'); $this->writeln(''); $this->saveRecords($repository); $this->writeln(''); $this->writeln(''); } } else { $this->writeln('Excel does not contain matching property columns.'); } } else { $this->writeln('Error parsing Excel file.'); $this->error = true; } return !$this->error; }
public static function getBreadcrumb(Repository $repository, $contentTypeName, $recordId) { $repository->selectContentType($contentTypeName); return $repository->getSortedRecords($recordId, true, 0, 99); }