예제 #1
0
 public static function createCRUDServiceProvider()
 {
     self::$fileProcessor = new CRUDNullFileProcessor();
     $app = self::createAppAndDB();
     $crudServiceProvider = new CRUDServiceProvider();
     $dataFactory = new CRUDMySQLDataFactory($app['db']);
     $crudFile = __DIR__ . '/../crud.yml';
     $crudServiceProvider->init($dataFactory, $crudFile, self::$fileProcessor, true, $app);
     return $crudServiceProvider;
 }
예제 #2
0
 public function testFormatFloat()
 {
     $float = 4.0E-6;
     $crudServiceProvider = new CRUDServiceProvider();
     $read = $crudServiceProvider->formatFloat($float);
     $expected = '0.000004';
     $this->assertSame($read, $expected);
     $read = $crudServiceProvider->formatFloat(null);
     $this->assertNull($read);
     $read = $crudServiceProvider->formatFloat(1.0);
     $expected = '1.0';
     $this->assertSame($read, $expected);
     $float = 0.004;
     $read = $crudServiceProvider->formatFloat($float);
     $expected = '0.004';
     $this->assertSame($read, $expected);
 }
예제 #3
0
 /**
  * Implements ServiceProviderInterface::register() registering $app['crud'].
  * $app['crud'] contains an instance of the CRUDServiceProvider afterwards.
  *
  * @param Application $app
  * the Application instance of the Silex application
  */
 public function register(Application $app)
 {
     $app['crud'] = $app->share(function () use($app) {
         $result = new CRUDServiceProvider();
         $fileProcessor = $app->offsetExists('crud.fileprocessor') ? $app['crud.fileprocessor'] : new CRUDSimpleFilesystemFileProcessor();
         $manageI18n = $app->offsetExists('crud.manageI18n') ? $app['crud.manageI18n'] : true;
         $result->init($app['crud.datafactory'], $app['crud.file'], $fileProcessor, $manageI18n, $app);
         return $result;
     });
 }
 public function testInitialSort()
 {
     $crudServiceProvider = new CRUDServiceProvider();
     $app = new Application();
     $crudServiceProvider->init($this->dataFactory, $this->crudFile, new CRUDNullFileProcessor(), true, $app);
     $data = $crudServiceProvider->getData('library');
     $read = $data->getDefinition()->getInitialSortField();
     $expected = 'name';
     $read = $data->getDefinition()->getInitialSortAscending();
     $this->assertFalse($read);
     $data = $crudServiceProvider->getData('book');
     $read = $data->getDefinition()->getInitialSortField();
     $expected = 'id';
     $read = $data->getDefinition()->getInitialSortAscending();
     $this->assertTrue($read);
 }