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 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');
     }
 }
Ejemplo n.º 3
0
 public function testGetSortedRecords()
 {
     $this->repository->selectContentType('example01');
     for ($i = 1; $i <= 10; $i++) {
         $record = $this->repository->createRecord('New Record');
         $record->setPosition(11 - $i);
         $id = $this->repository->saveRecord($record);
         $this->assertEquals($i, $id);
     }
     $records = $this->repository->getSortedRecords(0);
     $this->assertEquals([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], array_keys($records));
 }
 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 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'));
 }
Ejemplo n.º 6
0
 public function testSliceRecords()
 {
     $this->repository->selectContentType('example01');
     for ($i = 1; $i <= 10; $i++) {
         $record = $this->repository->createRecord('New Record');
         $record->setProperty('source', $i);
         $id = $this->repository->saveRecord($record);
         $this->assertEquals($i, $id);
     }
     $records = $this->repository->getRecords('', ['.id'], 1, 5);
     $this->assertCount(5, $records);
     $records = $this->repository->getRecords('', ['.id'], 2, 5);
     $this->assertCount(5, $records);
     $records = $this->repository->getRecords('', ['.id'], 3, 5);
     $this->assertCount(0, $records);
     $records = $this->repository->getRecords('', ['.id'], 99, 99);
     $this->assertCount(0, $records);
     $records = $this->repository->getRecords('', ['.id'], 1, 6);
     $this->assertCount(6, $records);
     $records = $this->repository->getRecords('', ['.id'], 2, 6);
     $this->assertCount(4, $records);
 }
Ejemplo n.º 7
0
 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);
     }
     for ($i = 2; $i <= 5; $i++) {
         $record = $this->repository->createRecord('New Record 1 - Revision ' . $i);
         $record->setId(1);
         $id = $this->repository->saveRecord($record);
         $this->assertEquals(1, $id);
         $this->assertEquals($i, $record->getRevision());
     }
     $record = $this->repository->getRecord(1);
     $this->assertEquals(5, $record->getRevision());
     $records = $this->repository->getRecords();
     $this->assertCount(5, $records);
     $this->assertEquals(5, $this->repository->countRecords());
     $record = $this->repository->getRecord(99);
     $this->assertFalse($record);
 }
 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 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');
     }
 }