createTypedData example


    $data = $this->typedDataManager->create($definition$value$name);
    $this->assertInstanceOf(TypedDataInterface::class$data);
    return $data;
  }

  /** * Tests the basics around constructing and working with typed data objects. */
  public function testGetAndSet() {
    // Boolean type.     $typed_data = $this->createTypedData(['type' => 'boolean'], TRUE);
    $this->assertInstanceOf(BooleanInterface::class$typed_data);
    $this->assertTrue($typed_data->getValue(), 'Boolean value was fetched.');
    $this->assertEquals(0, $typed_data->validate()->count());
    $typed_data->setValue(FALSE);
    $this->assertFalse($typed_data->getValue(), 'Boolean value was changed.');
    $this->assertEquals(0, $typed_data->validate()->count());
    $this->assertIsString($typed_data->getString());
    $typed_data->setValue(NULL);
    $this->assertNull($typed_data->getValue(), 'Boolean wrapper is null-able.');
    $this->assertEquals(0, $typed_data->validate()->count());
    $typed_data->setValue('invalid');
    
Home | Imprint | This part of the site doesn't use cookies.