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 testGetRecord()
 {
     $repository = new Repository('phpunit', $this->connection);
     $repository->selectContentType('temp');
     $record = $repository->getRecord(1);
     $this->assertEquals(1, $record->getID());
 }
 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 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);
 }
 /**
  * @param $recordId
  *
  * @return Record
  */
 public function getRecord($recordId, $dataDimensions = null)
 {
     if ($dataDimensions == null) {
         $dataDimensions = $this->getCurrentDataDimensions();
     }
     if ($this->isSingleContentRecordCaching()) {
         $cacheKey = $this->createCacheKey('record', [$this->getCurrentContentTypeName(), $recordId], $dataDimensions);
         $data = $this->getCacheProvider()->fetch($cacheKey);
         if ($data) {
             $data = json_decode($data, true);
             $recordFactory = $this->getRecordFactory();
             $record = $recordFactory->createRecordFromJSON($this->getCurrentContentTypeDefinition(), $data);
             $record->setRepository($this);
             return $record;
         }
         $record = parent::getRecord($recordId, $dataDimensions);
         $data = json_encode($record);
         $this->getCacheProvider()->save($cacheKey, $data, $this->singleContentRecordCaching);
         return $record;
     }
     return parent::getRecord($recordId, $dataDimensions);
 }
 /**
  * @param $recordId
  *
  * @return Record
  */
 public function getRecord($recordId)
 {
     if ($this->isSingleContentRecordCaching()) {
         $cacheKey = $this->createCacheKey('record', [$this->getCurrentContentTypeName(), $recordId]);
         $data = $this->getCacheProvider()->fetch($cacheKey);
         if ($data) {
             $data = json_decode($data, true);
             $recordFactory = new RecordFactory(['validateProperties' => false]);
             $record = $recordFactory->createRecordFromJSON($this->getCurrentContentTypeDefinition(), $data);
             return $record;
         }
         $record = parent::getRecord($recordId);
         $data = json_encode($record);
         $this->getCacheProvider()->save($cacheKey, $data, $this->singleContentRecordCaching);
         return $record;
     }
     return parent::getRecord($recordId);
 }