Beispiel #1
0
 protected function setUp()
 {
     $di = new DependencyInjection();
     $di->set('session', function () use($di) {
         return new Session();
     });
     DI::setDefault($di);
 }
 /**
  * @depends testGet
  */
 public function testShare()
 {
     $di = new DependencyInjection();
     $di->set('router', function () {
         return new Router('index', '/');
     });
     $result1 = $di->share('router');
     $result2 = $di->share('router');
     $this->assertEquals(spl_object_hash($result1), spl_object_hash($result2));
 }
Beispiel #3
0
 /**
  * @dataProvider providerRender
  * @param $value
  * @param $params
  * @param $expected
  */
 public function testRender($value, $params, $expected)
 {
     $di = new DependencyInjection();
     $di->set('security', function () use($di) {
         $security = new Security($di);
         return $security;
     });
     $name = 'test';
     $text = new Element($name);
     $text->setDI($di);
     $text->setValue($value);
     ob_start();
     $text->render($params);
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($expected, $result);
 }
Beispiel #4
0
 /**
  * @dataProvider providerRender
  * @param $value
  * @param $params
  * @param $expected
  */
 public function testRender($value, $params, $expected)
 {
     $di = new DependencyInjection();
     $di->set('security', function () use($di) {
         $security = new Security($di);
         return $security;
     });
     $name = 'test';
     $text = new CheckBox($name);
     $text->setDI($di);
     $text->setValue($value);
     ob_start();
     $text->render($params);
     //TODO: viewの方はrenderではprintしないので名前的におかしい。値返すようにする。
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($expected, $result);
 }
Beispiel #5
0
 /**
  * TODO: View::rendorの方は描画せずに文字列返してるのでこちらもあわせる。
  *
  * @param array $params
  */
 public function render($params = [])
 {
     $security = $this->di->share('security');
     $attr = '';
     foreach ($params as $key => $value) {
         $attr = sprintf('%s %s="%s"', $attr, $security->sanitize($key), $security->sanitize($value));
     }
     printf('<input type="%s" name="%s" value="%s"%s/>', $security->sanitize($this->form_type), $security->sanitize($this->name), $security->sanitize($this->value), $attr);
 }