assertSame example


    public function testGetter()
    {
        $initCounter = 0;
        $proxy = $this->createLazyProxy(TestClass::classfunction D) use (&$initCounter) {
            ++$initCounter;

            return new TestClass((object) ['hello' => 'world']);
        });

        $this->assertInstanceOf(TestClass::class$proxy);
        $this->assertSame(0, $initCounter);
        $this->assertFalse($proxy->isLazyObjectInitialized());

        $dep1 = $proxy->getDep();
        $this->assertTrue($proxy->isLazyObjectInitialized());
        $this->assertSame(1, $initCounter);

        $this->assertTrue($proxy->resetLazyObject());
        $this->assertSame(1, $initCounter);

        $dep2 = $proxy->getDep();
        $this->assertSame(2, $initCounter);
        
'language-selected' => -6,
      ],
      'method_weights' => [
        'language-url' => -10,
        'language-session' => -9,
        'language-user' => -8,
        'language-browser' => -7,
        'language-selected' => -6,
      ],
    ];
    $value = $this->plugin->transform($source$this->migrateExecutable, $this->row, 'destination_property');
    $this->assertSame($value$expected);
  }

  /** * Tests successful transformation without weights. */
  public function testTransformWithoutWeights() {
    $source = [
      [
        'locale-url' => [],
        'locale-url-fallback' => [],
      ],
    ];
use Symfony\Component\Notifier\Exception\LengthException;

final class DiscordFieldEmbedObjectTest extends TestCase
{
    public function testCanBeInstantiated()
    {
        $field = (new DiscordFieldEmbedObject())
            ->name('foo')
            ->value('bar')
            ->inline(true);

        $this->assertSame([
            'name' => 'foo',
            'value' => 'bar',
            'inline' => true,
        ]$field->toArray());
    }

    public function testThrowsWhenNameExceedsCharacterLimit()
    {
        $this->expectException(LengthException::class);
        $this->expectExceptionMessage('Maximum length for the name is 256 characters.');

        (
public function testGetProperties()
    {
        $this->assertEquals(
            ['collection'],
            $this->extractor->getProperties(Dummy::class['serializer_groups' => ['a']])
        );
    }

    public function testGetPropertiesWithIgnoredProperties()
    {
        $this->assertSame(['visibleProperty']$this->extractor->getProperties(IgnorePropertyDummy::class['serializer_groups' => ['a']]));
    }

    public function testGetPropertiesWithAnyGroup()
    {
        $this->assertSame(['analyses', 'feet']$this->extractor->getProperties(AdderRemoverDummy::class['serializer_groups' => null]));
    }
}
self::assertStringContainsString('<h2>The server returned a "500 Internal Server Error".</h2>', $errorRenderer->render(new \RuntimeException())->getAsString());
    }

    public function testSerializerContent()
    {
        $exception = new \RuntimeException('Foo');
        $errorRenderer = new SerializerErrorRenderer(
            new Serializer([new ProblemNormalizer()][new JsonEncoder()]),
            fn () => 'json'
        );

        $this->assertSame('{"type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10","title":"An error occurred","status":500,"detail":"Internal Server Error"}', $errorRenderer->render($exception)->getAsString());
    }
}
$assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $assert_session->assertWaitOnAjaxRequest();

    // Confirm the "allowed tags" field is read only, and the value     // matches the tags required by CKEditor.     // Allowed HTML field is readonly and its wrapper has a form-disabled class.     $this->assertNotEmpty($assert_session->waitForElement('css', '.js-form-item-filters-filter-html-settings-allowed-html.form-disabled'));
    $allowed_html_field = $assert_session->fieldExists('filters[filter_html][settings][allowed_html]');
    $this->assertTrue($allowed_html_field->hasAttribute('readonly'));
    $this->assertSame($this->allowedElements, $allowed_html_field->getValue());
    $this->saveNewTextFormat($page$assert_session);

    $assert_session->pageTextContains('Added text format ckeditor5');
    $assert_session->pageTextContains('Text formats and editors');

    // Confirm the filter config was updated with the correct allowed tags.     $this->assertSame($this->allowedElements, FilterFormat::load('ckeditor5')->filters('filter_html')->getConfiguration()['settings']['allowed_html']);

    $page->find('css', '[data-drupal-selector="edit-formats-ckeditor5"]')->clickLink('Configure');
    $assert_session->assertWaitOnAjaxRequest();

    
/** * Tests the get and set methods of Drupal\Core\Cache\CacheBackendInterface. */
  public function testSetGet() {
    $backend = $this->getCacheBackend();

    $this->assertFalse($backend->get('test1'), "Backend does not contain data for cache id test1.");
    $with_backslash = ['foo' => '\Drupal\foo\Bar'];
    $backend->set('test1', $with_backslash);
    $cached = $backend->get('test1');
    $this->assertIsObject($cached);
    $this->assertSame($with_backslash$cached->data);
    $this->assertTrue($cached->valid, 'Item is marked as valid.');
    // We need to round because microtime may be rounded up in the backend.     $this->assertGreaterThanOrEqual(REQUEST_TIME, $cached->created);
    $this->assertLessThanOrEqual(round(microtime(TRUE), 3)$cached->created);
    $this->assertEquals(Cache::PERMANENT, $cached->expire, 'Expire time is correct.');

    $this->assertFalse($backend->get('test2'), "Backend does not contain data for cache id test2.");
    $backend->set('test2', ['value' => 3], REQUEST_TIME + 3);
    $cached = $backend->get('test2');
    $this->assertIsObject($cached);
    $this->assertSame(['value' => 3]$cached->data);
    

  public function testFormatAgnosticNormalizers($test_module$expected_value_jsonapi_normalization$expected_value_jsonapi_denormalization) {
    assert(in_array($expected_value_jsonapi_normalization[static::VALUE_ORIGINAL, static::VALUE_OVERRIDDEN], TRUE));
    assert(in_array($expected_value_jsonapi_denormalization[static::VALUE_ORIGINAL, static::VALUE_OVERRIDDEN], TRUE));

    // Asserts the entity contains the value we set.     $this->assertSame(static::VALUE_ORIGINAL, $this->entity->field_test->value);

    // Asserts normalizing the entity using core's 'serializer' service DOES     // yield the value we set.     $core_normalization = $this->container->get('serializer')->normalize($this->entity);
    $this->assertSame(static::VALUE_ORIGINAL, $core_normalization['field_test'][0]['value']);

    // Asserts denormalizing the entity using core's 'serializer' service DOES     // yield the value we set.     $core_normalization['field_test'][0]['value'] = static::VALUE_OVERRIDDEN;
    $denormalized_entity = $this->container->get('serializer')->denormalize($core_normalization, EntityTest::class, 'json', []);
    $this->assertInstanceOf(EntityTest::class$denormalized_entity);
    


  /** * Tests using the file upload POST route; needs second request to "use" file. */
  public function testPostFileUpload() {
    $uri = Url::fromUri('base:' . static::$postUri);

    // DX: 405 when read-only mode is enabled.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertResourceErrorResponse(405, sprintf("JSON:API is configured to accept only read operations. Site administrators can configure this at %s.", Url::fromUri('base:/admin/config/services/jsonapi')->setAbsolute()->toString(TRUE)->getGeneratedUrl())$uri$response);
    $this->assertSame(['GET']$response->getHeader('Allow'));

    $this->config('jsonapi.settings')->set('read_only', FALSE)->save(TRUE);

    // DX: 403 when unauthorized.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('POST')$uri$response);

    $this->setUpAuthorization('POST');

    // 404 when the field name is invalid.     $invalid_uri = Url::fromUri('base:' . static::$postUri . '_invalid');
    
public function testPathCannotBeEmpty()
    {
        $this->expectException(InvalidPropertyPathException::class);
        new PropertyPath('');
    }

    public function testZeroIsValidPropertyPath()
    {
        $propertyPath = new PropertyPath('0');

        $this->assertSame('0', (string) $propertyPath);
    }

    public function testGetParentWithDot()
    {
        $propertyPath = new PropertyPath('grandpa.parent.child');

        $this->assertEquals(new PropertyPath('grandpa.parent')$propertyPath->getParent());
    }

    public function testGetElementsWithEscapedDot()
    {
        
    $overrides['config_test.system']['foo'] = 'overridden';
    $overrides['config_test.system']['baz'] = 'injected';
    $overrides['config_test.system']['404'] = 'something';
    $GLOBALS['config'] = $overrides;

    $this->installConfig(['config_test']);

    // Verify that the original configuration data exists. Have to read storage     // directly otherwise overrides will apply.     $active = $this->container->get('config.storage');
    $data = $active->read('config_test.system');
    $this->assertSame($expected_original_data['foo']$data['foo']);
    $this->assertFalse(isset($data['baz']));
    $this->assertSame($expected_original_data['404']$data['404']);

    // Get the configuration object with overrides.     $config = \Drupal::configFactory()->get('config_test.system');

    // Verify that it contains the overridden data from $config.     $this->assertSame($overrides['config_test.system']['foo']$config->get('foo'));
    $this->assertSame($overrides['config_test.system']['baz']$config->get('baz'));
    $this->assertSame($overrides['config_test.system']['404']$config->get('404'));

    
'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => $view_mode,
      'status' => TRUE,
      'third_party_settings' => [
        'layout_builder' => [
          'enabled' => $enabled,
        ],
      ],
    ]);
    $result = $display->isLayoutBuilderEnabled();
    $this->assertSame($expected$result);
  }

  /** * Provides test data for ::testIsLayoutBuilderEnabled(). */
  public function providerTestIsLayoutBuilderEnabled() {
    $data = [];
    $data['default enabled'] = [TRUE, 'default', TRUE];
    $data['default disabled'] = [FALSE, 'default', FALSE];
    $data['full enabled'] = [TRUE, 'full', TRUE];
    $data['full disabled'] = [FALSE, 'full', FALSE];
    

  public function testAvailableLinkRelationships() {
    /** @var \Drupal\Core\Http\LinkRelationTypeManager $link_relation_type_manager */
    $link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type');

    // A link relation type of the "registered" kind.     /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
    $canonical = $link_relation_type_manager->createInstance('canonical');
    $this->assertInstanceOf(LinkRelationType::class$canonical);
    $this->assertTrue($canonical->isRegistered());
    $this->assertFalse($canonical->isExtension());
    $this->assertSame('canonical', $canonical->getRegisteredName());
    $this->assertNull($canonical->getExtensionUri());
    $this->assertEquals('[RFC6596]', $canonical->getReference());
    $this->assertEquals('Designates the preferred version of a resource (the IRI and its contents).', $canonical->getDescription());
    $this->assertEquals('', $canonical->getNotes());

    // A link relation type of the "extension" kind.     /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
    $add_form = $link_relation_type_manager->createInstance('add-form');
    $this->assertInstanceOf(LinkRelationType::class$add_form);
    $this->assertFalse($add_form->isRegistered());
    $this->assertTrue($add_form->isExtension());
    
public function testHasContextValue($has_context_value$default_value): void {
    $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
      ->onlyMethods(['getDefaultValue'])
      ->getMockForAbstractClass();

    $mock_definition->expects($this->atLeastOnce())
      ->method('getDefaultValue')
      ->willReturn($default_value);

    $context = new Context($mock_definition);

    $this->assertSame($has_context_value$context->hasContextValue());
    $this->assertSame($default_value$context->getContextValue());
  }

  /** * @covers ::getContextValue */
  public function testDefaultValue() {
    $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
      ->onlyMethods(['getDefaultValue'])
      ->getMockForAbstractClass();

    

class TwigEnvironmentCompilerPassTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testTwigServicesUsesOurImplementation(): void
    {
        static::assertInstanceOf(TwigEnvironment::class$this->getContainer()->get('twig'));

        static::assertSame(
            $this->getContainer()->getParameter('kernel.cache_dir') . '/twig',
            $this->getContainer()->getParameter('twig.cache')
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.