public function createService(ServiceLocatorInterface $sm) { $config = $sm->get('config'); if (!isset($config['ZfcDatagrid'])) { throw new InvalidArgumentException('Config key "ZfcDatagrid" is missing'); } /* @var $application \Zend\Mvc\Application */ $application = $sm->get('application'); $grid = new Datagrid(); $grid->setOptions($config['ZfcDatagrid']); $grid->setMvcEvent($application->getMvcEvent()); if ($sm->has('translator') === true) { $grid->setTranslator($sm->get('translator')); } $grid->init(); return $grid; }
public function testRendererName() { // Default on HTTP $this->assertEquals('bootstrapTable', $this->grid->getRendererName()); // Default on CLI $_SERVER['argv'] = ['foo.php', 'foo' => 'baz', 'bar']; $_ENV["FOO_VAR"] = "bar"; $request = new \Zend\Console\Request(); $mvcEvent = $this->getMock('Zend\\Mvc\\MvcEvent'); $mvcEvent->expects($this->any())->method('getRequest')->will($this->returnValue($request)); $this->grid->setMvcEvent($mvcEvent); $this->assertEquals('zendTable', $this->grid->getRendererName()); // change default $this->grid->setRendererName('myRenderer'); $this->assertEquals('myRenderer', $this->grid->getRendererName()); // by HTTP request $_GET['rendererType'] = 'jqGrid'; $request = new \Zend\Http\PhpEnvironment\Request(); $mvcEvent = $this->getMock('Zend\\Mvc\\MvcEvent'); $mvcEvent->expects($this->any())->method('getRequest')->will($this->returnValue($request)); $this->grid->setMvcEvent($mvcEvent); $this->assertEquals('jqGrid', $this->grid->getRendererName()); }