/** * {@inheritdoc} */ public final function setParameter($name, $value) { if (!$this->hasParameter($name)) { throw new FormatterException(sprintf('The %s doesn\'t support "%s" parameter', get_class($this), $name)); } $this->parameters->set($name, $value); }
/** * Executes this command. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $parameters = new ParameterBag(); $parameters->set('configuration.file', $input->getOption('project-dir') . DIRECTORY_SEPARATOR . 'accompli.json'); $parameters->set('console.output_interface', $output); $accompli = new Accompli($parameters); $accompli->initialize(); $successfulInstall = $accompli->deploy($input->getArgument('version'), $input->getArgument('stage')); if ($successfulInstall) { return 0; } return 1; }
/** * Tests the method for checking access to routes. * * @dataProvider providerTestAccess */ public function testAccess($entity_bundle, $requirement, $access, $expected, $expect_permission_context = TRUE) { // Set up the access result objects for allowing or denying access. $access_result = $access ? AccessResult::allowed()->cachePerPermissions() : AccessResult::neutral()->cachePerPermissions(); $expected_access_result = $expected ? AccessResult::allowed() : AccessResult::neutral(); if ($expect_permission_context) { $expected_access_result->cachePerPermissions(); } $entity_manager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'); // Don't expect a call to the access control handler when we have a bundle // argument requirement but no bundle is provided. if ($entity_bundle || strpos($requirement, '{') === FALSE) { $access_control_handler = $this->getMock('Drupal\\Core\\Entity\\EntityAccessControlHandlerInterface'); $access_control_handler->expects($this->once())->method('createAccess')->with($entity_bundle)->will($this->returnValue($access_result)); $entity_manager->expects($this->any())->method('getAccessControlHandler')->will($this->returnValue($access_control_handler)); } $applies_check = new EntityCreateAccessCheck($entity_manager); $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); $route->expects($this->any())->method('getRequirement')->with('_entity_create_access')->will($this->returnValue($requirement)); $raw_variables = new ParameterBag(); if ($entity_bundle) { $raw_variables->set('bundle_argument', $entity_bundle); } $route_match = $this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'); $route_match->expects($this->any())->method('getRawParameters')->will($this->returnValue($raw_variables)); $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $this->assertEquals($expected_access_result, $applies_check->access($route, $route_match, $account)); }
/** * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::get * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::set */ public function testGetSet() { $bag = new ParameterBag(array('foo' => 'bar')); $bag->set('bar', 'foo'); $this->assertEquals('foo', $bag->get('bar'), '->set() sets the value of a new parameter'); $bag->set('foo', 'baz'); $this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter'); $bag->set('Foo', 'baz1'); $this->assertEquals('baz1', $bag->get('foo'), '->set() converts the key to lowercase'); $this->assertEquals('baz1', $bag->get('FOO'), '->get() converts the key to lowercase'); try { $bag->get('baba'); $this->fail('->get() throws an \\InvalidArgumentException if the key does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->get() throws an \\InvalidArgumentException if the key does not exist'); $this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->get() throws an \\InvalidArgumentException if the key does not exist'); } }
/** * Tests the method for checking access to routes. * * @dataProvider providerTestAccess */ public function testAccess($entity_bundle, $requirement, $access, $expected) { $entity_manager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'); // Don't expect a call to the access controller when we have a bundle // argument requirement but no bundle is provided. if ($entity_bundle || strpos($requirement, '{') === FALSE) { $access_controller = $this->getMock('Drupal\\Core\\Entity\\EntityAccessControllerInterface'); $access_controller->expects($this->once())->method('createAccess')->with($entity_bundle)->will($this->returnValue($access)); $entity_manager->expects($this->any())->method('getAccessController')->will($this->returnValue($access_controller)); } $applies_check = new EntityCreateAccessCheck($entity_manager); $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); $route->expects($this->any())->method('getRequirement')->with('_entity_create_access')->will($this->returnValue($requirement)); $request = new Request(); $raw_variables = new ParameterBag(); if ($entity_bundle) { // Add the bundle as a raw variable and an upcasted attribute. $request->attributes->set('bundle_argument', new \stdClass()); $raw_variables->set('bundle_argument', $entity_bundle); } $request->attributes->set('_raw_variables', $raw_variables); $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $this->assertEquals($expected, $applies_check->access($route, $request, $account)); }
/** * Sets formatter parameter. * * @param string $name * @param mixed $value */ public final function setParameter($name, $value) { $this->parameters->set($name, $value); }
/** * Override of set() that returns $this * * @param string $name * @param mixed $value * * @return $this */ public function set($name, $value) { parent::set($name, $value); return $this; }
/** * Collect the parameter bag. * * @param ComposerInformation $information The composer information. * * @param string[] $baseParameters The base parameters. * * @return ParameterBag */ private function collectParameters(ComposerInformation $information, $baseParameters) { $parameterBag = new ParameterBag($baseParameters); foreach ($information->getPackageNames() as $packageName) { $parameterBag->set(sprintf('package:%s', $packageName), $information->getPackageDirectory($packageName)); $parameterBag->set(sprintf('version:%s', $packageName), $information->getPackageVersion($packageName)); $parameterBag->set(sprintf('date:%s', $packageName), $information->getPackageReleaseDate($packageName)); } return $parameterBag; }
/** * Tests the getRouteParameters method for a route with upcasted parameters. * * @see \Drupal\Core\Menu\LocalTaskDefault::getRouteParameters() */ public function testGetRouteParametersForDynamicRouteWithUpcastedParameters() { $this->pluginDefinition = array('route_name' => 'test_route'); $this->routeProvider->expects($this->once())->method('getRouteByName')->with('test_route')->will($this->returnValue(new Route('/test-route/{parameter}'))); $this->setupLocalTaskDefault(); $request = new Request(); $raw_variables = new ParameterBag(); $raw_variables->set('parameter', 'example'); $request->attributes->set('parameter', (object) array('example2')); $request->attributes->set('_raw_variables', $raw_variables); $this->assertEquals(array('parameter' => 'example'), $this->localTaskBase->getRouteParameters($request)); }