MenuLinkDefault example

/** * @covers ::extractFormValues */
  public function testExtractFormValues() {
    $menu_link_manager = $this->prophesize(MenuLinkManagerInterface::class);
    $menu_parent_form_selector = $this->prophesize(MenuParentFormSelectorInterface::class);
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $menu_link_form = new MenuLinkDefaultForm($menu_link_manager->reveal()$menu_parent_form_selector->reveal()$this->getStringTranslationStub()$module_handler->reveal());

    $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
    $menu_link = new MenuLinkDefault([], 'my_plugin_id', []$static_override->reveal());
    $menu_link_form->setMenuLinkInstance($menu_link);

    $form_state = new FormState();
    $form_state->setValue('id', 'my_plugin_id');
    $form_state->setValue('enabled', FALSE);
    $form_state->setValue('weight', 5);
    $form_state->setValue('expanded', TRUE);
    $form_state->setValue('menu_parent', 'foo:bar');

    $form = [];
    $result = $menu_link_form->extractFormValues($form$form_state);

    
'menu_name' => 'admin',
      'parent' => '',
      'weight' => 10,
    ];
    $expected_plugin_definition = $plugin_definition;
    $expected_plugin_definition['weight'] = -10;

    $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
    $static_override->saveOverride('example_menu_link', $expected_plugin_definition);
    $static_override = $static_override->reveal();

    $menu_link = new MenuLinkDefault([], 'example_menu_link', $plugin_definition$static_override);

    $this->assertEquals($expected_plugin_definition$menu_link->updateLink(['weight' => -10], TRUE));
  }

  /** * @covers ::updateLink */
  public function testUpdateLinkWithoutPersist() {
    $plugin_definition = [
      'title' => 'Hey jude',
      'enabled' => 1,
      

  public function testMenuLinkParent(array $source_value$lookup_result$plugin_id$route_name$expected_result) {
    [$parent_id$menu_name$parent_link_path] = $source_value;
    $this->migrateLookup->lookup(NULL, [$parent_id])
      ->willReturn([['id' => $lookup_result]]);
    if ($route_name) {
      $plugin_definition = ['menu_name' => $menu_name];
      $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
      $static_override = $static_override->reveal();
      $menu_link = new MenuLinkDefault([]$plugin_id$plugin_definition$static_override);
      $this->menuLinkManager->loadLinksByRoute($route_name[], 'admin')
        ->willReturn([$plugin_id => $menu_link]);

      $url = new Url($route_name[][]);
      $this->pathValidator->getUrlIfValidWithoutAccessCheck($parent_link_path)
        ->willReturn($url);
    }
    $result = $this->doTransform($source_value$plugin_id);
    $this->assertSame($expected_result$result);
  }

  
Home | Imprint | This part of the site doesn't use cookies.