doTransform example

protected $migrationConfiguration = [
    'id' => 'test',
  ];

  public function testPublic() {
    $value = [
      'sites/default/files/foo.jpg',
      'sites/default/files',
      '/tmp',
      TRUE,
    ];
    $this->assertEquals('public://foo.jpg', $this->doTransform($value));
  }

  public function testPublicUnknownBasePath() {
    $value = [
      '/path/to/public/files/foo.jpg',
      'sites/default/files',
      '/tmp',
      TRUE,
    ];
    $this->assertEquals('public://path/to/public/files/foo.jpg', $this->doTransform($value));
  }

  
'Local file specs without spaces should not be transformed' => ['/tmp/normal.txt', '/tmp/normal.txt'],
      'Local file specs with spaces should not be transformed' => ['/tmp/with spaces.txt', '/tmp/with spaces.txt'],
      'Make sure URL characters (:, ?, &) are not encoded but others are.' => ['https://example.com/?a=b@c&d=e+f%', 'https://example.com/?a%3Db%40c&d%3De%2Bf%25'],
    ];
  }

  /** * Cover various encoding scenarios. * @dataProvider urlDataProvider */
  public function testUrls($input$output) {
    $this->assertEquals($output$this->doTransform($input));
  }

  /** * Perform the urlencode process plugin over the given value. * * @param string $value * URL to be encoded. * * @return string * Encoded URL. */
  
/** * Tests Route plugin based on providerTestRoute() values. * * @param mixed $value * Input value for the Route process plugin. * @param array $expected * The expected results from the Route transform process. * * @dataProvider providerTestRoute */
  public function testRoute($value$expected) {
    $actual = $this->doTransform($value);
    $this->assertSame($expected$actual);
  }

  /** * Data provider for testRoute(). * * @return array * An array of arrays, where the first element is the input to the Route * process plugin, and the second is the expected results. */
  public function providerTestRoute() {
    
$this->container->get('stream_wrapper_manager')->registerWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream', StreamWrapperInterface::LOCAL_NORMAL);
  }

  /** * Tests a download that overwrites an existing local file. */
  public function testOverwritingDownload() {
    // Create a pre-existing file at the destination.     $destination_uri = $this->createUri('existing_file.txt');

    // Test destructive download.     $actual_destination = $this->doTransform($destination_uri);
    $this->assertSame($destination_uri$actual_destination, 'Import returned a destination that was not renamed');
    $this->assertFileDoesNotExist('public://existing_file_0.txt');
  }

  /** * Tests a download that renames the downloaded file if there's a collision. */
  public function testNonDestructiveDownload() {
    // Create a pre-existing file at the destination.     $destination_uri = $this->createUri('another_existing_file.txt');

    
$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);
  }

  /** * Provides data for testMenuLinkParent(). */
  public function providerMenuLinkParent() {
    return [
      'menu link is route item' => [
        'source_value' => [0, NULL, NULL],
        'lookup_result' => NULL,
        
$file_absolute,
        'temporary://test.jpg',
      ],
      // Test a temporary file using a relative path.       [
        $file_absolute,
        'temporary://core/tests/fixtures/files/test.jpg',
      ],
    ];
    foreach ($data_sets as $data) {
      [$source_path$destination_path] = $data;
      $actual_destination = $this->doTransform($source_path$destination_path);
      $this->assertFileExists($destination_path);
      // Make sure we didn't accidentally do a move.       $this->assertFileExists($source_path);
      $this->assertSame($actual_destination$destination_path, 'The import returned the copied filename.');
    }
  }

  /** * Tests successful file reuse. * * @dataProvider providerSuccessfulReuse * * @param string $source_path * Source path to copy from. * @param string $destination_path * The destination path to copy to. */

  public function testRouted($value$expected) {
    $actual = $this->doTransform($value);
    $this->assertSame($expected$actual);
  }

  /** * Provides test cases for LinkUriTest::testTransform(). * * @return array * An array of test cases, each which the following values: * - The value array to pass to LinkUri::transform(). * - The expected path returned by LinkUri::transform(). */
  
Home | Imprint | This part of the site doesn't use cookies.