summary example

$test = EntityTestWithBundle::create(['type' => 'test', 'name' => $this->randomMachineName()]);
    $test->save();

    // Grab the bundle condition and configure it to check against bundle of     // 'article' and set the context to the page type entity.     /** @var \Drupal\Core\Entity\Plugin\Condition\EntityBundle $condition */
    $condition = $this->container->get('plugin.manager.condition')->createInstance('entity_bundle:entity_test_with_bundle')
      ->setConfig('bundles', ['article' => 'article'])
      ->setContextValue('entity_test_with_bundle', $page);
    $this->assertFalse($condition->execute(), 'Page type entities fail bundle checks for articles.');
    // Check for the proper summary.     $this->assertEquals('Test entity bundle is article', $condition->summary());
    $this->assertEquals('entity_test', $condition->getPluginDefinition()['provider']);

    // Set the bundle check to page.     $condition->setConfig('bundles', ['page' => 'page']);
    $this->assertTrue($condition->execute(), 'Page type entities pass bundle checks for pages');
    // Check for the proper summary.     $this->assertEquals('Test entity bundle is page', $condition->summary());

    // Set the bundle check to page or article.     $condition->setConfig('bundles', ['page' => 'page', 'article' => 'article']);
    $this->assertTrue($condition->execute(), 'Page type entities pass bundle checks for pages or articles');
    
// Get the request path condition and test and configure it to check against     // different patterns and requests.
    $pages = "/my/pass/page\r\n/my/pass/page2\r\n/foo";

    $request = Request::create('/my/pass/page2');
    $this->requestStack->push($request);

    /** @var \Drupal\system\Plugin\Condition\RequestPath $condition */
    $condition = $this->pluginManager->createInstance('request_path');
    $this->assertEquals('No page is specified', $condition->summary());
    $condition->setConfig('pages', $pages);

    $this->aliasManager->addAlias('/my/pass/page2', '/my/pass/page2');

    $this->assertTrue($condition->execute(), 'The request path matches a standard path');
    $this->assertEquals('Return true on the following pages: /my/pass/page, /my/pass/page2, /foo', $condition->summary(), 'The condition summary matches for a standard path');

    // Test an aliased path.     $this->currentPath->setPath('/my/aliased/page', $request);
    $this->requestStack->pop();
    $this->requestStack->push($request);

    

  public function testConditions() {
    // Grab the language condition and configure it to check the content     // language.     $language = \Drupal::languageManager()->getLanguage('en');
    $condition = $this->manager->createInstance('language')
      ->setConfig('langcodes', ['en' => 'en', 'it' => 'it'])
      ->setContextValue('language', $language);
    $this->assertTrue($condition->execute(), 'Language condition passes as expected.');
    // Check for the proper summary.     $this->assertEquals('The language is English, Italian.', $condition->summary());

    // Change to Italian only.     $condition->setConfig('langcodes', ['it' => 'it']);
    $this->assertFalse($condition->execute(), 'Language condition fails as expected.');
    // Check for the proper summary.     $this->assertEquals('The language is Italian.', $condition->summary());

    // Negate the condition     $condition->setConfig('negate', TRUE);
    $this->assertTrue($condition->execute(), 'Language condition passes as expected.');
    // Check for the proper summary.
public function testCurrentTheme() {
    \Drupal::service('theme_installer')->install(['test_theme']);

    $manager = \Drupal::service('plugin.manager.condition');
    /** @var \Drupal\Core\Condition\ConditionInterface $condition */
    $condition = $manager->createInstance('current_theme');
    $condition->setConfiguration(['theme' => 'test_theme']);
    /** @var \Drupal\Core\Condition\ConditionInterface $condition_negated */
    $condition_negated = $manager->createInstance('current_theme');
    $condition_negated->setConfiguration(['theme' => 'test_theme', 'negate' => TRUE]);

    $this->assertEquals(new FormattableMarkup('The current theme is @theme', ['@theme' => 'test_theme'])$condition->summary());
    $this->assertEquals(new FormattableMarkup('The current theme is not @theme', ['@theme' => 'test_theme'])$condition_negated->summary());

    // The expected theme has not been set up yet.     $this->assertFalse($condition->execute());
    $this->assertTrue($condition_negated->execute());

    // Set the expected theme to be used.     $this->config('system.theme')->set('default', 'test_theme')->save();
    \Drupal::theme()->resetActiveTheme();

    $this->assertTrue($condition->execute());
    

        $options = new MicrosoftTeamsOptions([
            'summary' => $summary = 'My summary',
        ]);

        $this->assertSame($summary$options->toArray()['summary']);
    }

    public function testSummaryViaSetter()
    {
        $options = (new MicrosoftTeamsOptions())
            ->summary($summary = 'My summary');

        $this->assertSame($summary$options->toArray()['summary']);
    }

    public function testTitleViaConstructor()
    {
        $options = new MicrosoftTeamsOptions([
            'title' => $title = 'My title',
        ]);

        $this->assertSame($title$options->toArray()['title']);
    }

  public function testConditions() {
    // Grab the user role condition and configure it to check against     // authenticated user roles.     /** @var \Drupal\Core\Condition\ConditionInterface $condition */
    $condition = $this->manager->createInstance('user_role')
      ->setConfig('roles', [RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID])
      ->setContextValue('user', $this->anonymous);
    $this->assertFalse($condition->execute(), 'Anonymous users fail role checks for authenticated.');
    // Check for the proper summary.     // Summaries require an extra space due to negate handling in summary().     $this->assertEquals('The user is a member of Authenticated user', $condition->summary());

    // Set the user role to anonymous.     $condition->setConfig('roles', [RoleInterface::ANONYMOUS_ID => RoleInterface::ANONYMOUS_ID]);
    $this->assertTrue($condition->execute(), 'Anonymous users pass role checks for anonymous.');
    // Check for the proper summary.     $this->assertEquals('The user is a member of Anonymous user', $condition->summary());

    // Set the user role to check anonymous or authenticated.     $condition->setConfig('roles', [RoleInterface::ANONYMOUS_ID => RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID]);
    $this->assertTrue($condition->execute(), 'Anonymous users pass role checks for anonymous or authenticated.');
    // Check for the proper summary.
$config = $this->condition->getConfig();
    foreach ($config['bundles'] as $bundle) {
      \Drupal::messenger()->addStatus('Bundle: ' . $bundle);
    }

    $article = Node::load(1);
    $this->condition->setContextValue('node', $article);
    if ($this->condition->execute()) {
      \Drupal::messenger()->addStatus($this->t('Executed successfully.'));
    }
    if ($this->conditionCurrentTheme->execute()) {
      \Drupal::messenger()->addStatus($this->conditionCurrentTheme->summary());
    }
  }

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