function testSaveUpdateDelete()
 {
     $backup = './messages/messages_mysql.sql';
     $source = MessageSource::factory($this->type, $this->source);
     $source->setCulture('en_AU');
     $source->setCache(new MessageCache('./tmp'));
     //restore using the back file
     $this->restore($backup, $source->connection());
     //test that the back file doesn't contain the 'Testing123' string.
     $contents = $this->getAllContents($source->connection());
     $this->assertNoUnwantedPattern('/Testing123/', $contents);
     $formatter = new MessageFormat($source);
     $formatter->setUntranslatedPS(array('[t]', '[/t]'));
     //add a untranslated string
     $this->assertEqual($formatter->format('Testing123'), '[t]Testing123[/t]');
     //save it
     $this->assertTrue($formatter->getSource()->save());
     //check the contents
     $contents = $this->getAllContents($source->connection());
     $this->assertWantedPattern('/Testing123/', $contents);
     //testing for update.
     $this->assertTrue($formatter->getSource()->update('Testing123', '123Test', 'update comments'));
     $contents = $this->getAllContents($source->connection());
     $this->assertWantedPattern('/123Test/', $contents);
     $this->assertWantedPattern('/update comments/', $contents);
     //var_dump(htmlspecialchars($contents));
     //now doing some delete
     //doesn't detect missing source
     $this->assertFalse($formatter->getSource()->delete('Test123'));
     $this->assertTrue($formatter->getSource()->delete('Testing123'));
     $contents = $this->getAllContents($source->connection());
     $this->assertNoUnwantedPattern('/Testing123/', $contents);
     //restore using the backup file.
     $this->restore($backup, $source->connection());
 }
 /**
  * Save untranslated messages to the catalogue.
  */
 public static function saveMessages()
 {
     static $onceonly = true;
     if (!is_null(self::$formatter)) {
         if ($onceonly) {
             $app = pradoGetApplication()->getGlobalization();
             if (isset($app->Translation['autosave'])) {
                 $catalogue = null;
                 if (isset($app->Translation['catalogue'])) {
                     $catalogue = $app->Translation['catalogue'];
                 }
                 $auto = $app->Translation['autosave'];
                 if ($auto == 'true') {
                     self::$formatter->getSource()->save($catalogue);
                 } else {
                     self::$formatter->getSource()->setCulture($app->getDefaultCulture());
                     self::$formatter->getSource()->save($auto);
                 }
             }
         }
         $onceonly = false;
     }
 }
 function testDirectoryTypeSaveUpdateDelete()
 {
     $MObackup = './messages/en_AU/tests.mo.bak';
     $MOfile = './messages/en_AU/tests.mo';
     $PObackup = './messages/en_AU/tests.po.bak';
     $POfile = './messages/en_AU/tests.po';
     //restore using the back file
     copy($MObackup, $MOfile);
     copy($PObackup, $POfile);
     //test that the back file doesn't contain the 'Testing123' string.
     $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($MOfile));
     $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($POfile));
     $source = MessageSource::factory($this->type, $this->source);
     $source->setCulture('en_AU');
     $source->setCache(new MessageCache('./tmp'));
     $formatter = new MessageFormat($source);
     //add a untranslated string, note, doesn't matter which catalogue
     $this->assertEqual($formatter->format('Testing123'), 'Testing123');
     //save it to the 'tests' catalgoue
     $this->assertTrue($formatter->getSource()->save('tests'));
     //check the contents
     //$this->assertWantedPattern('/Testing123/',file_get_contents($MOfile));
     $this->assertWantedPattern('/Testing123/', file_get_contents($POfile));
     //testing for update. Update it to the 'tests' catalogue
     $this->assertTrue($formatter->getSource()->update('Testing123', '123Test', 'update comments', 'tests'));
     $this->assertWantedPattern('/123Test/', file_get_contents($MOfile));
     //now doing some delete	from the 'tests' catalogue
     $this->assertFalse($formatter->getSource()->delete('Test123', 'tests'));
     $this->assertTrue($formatter->getSource()->delete('Testing123', 'tests'));
     $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($MOfile));
     $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($POfile));
     //restore using the backup file.
     copy($MObackup, $MOfile);
     copy($PObackup, $POfile);
 }