Skip to content
Snippets Groups Projects
Verified Commit 57fd6cea authored by Jibran Ijaz's avatar Jibran Ijaz Committed by Jibran Ijaz
Browse files

Issue #3328193 by jibran, alan.cole: Destination file storage should clear...

Issue #3328193 by jibran, alan.cole: Destination file storage should clear existing file on dataset update
parent b1ec4a76
No related branches found
No related tags found
1 merge request!17Issue #3328193 by jibran, alan.cole: Destination file storage should clear...
Pipeline #65629 passed
......@@ -250,7 +250,9 @@ abstract class FileDestinationBase extends DatasetDestinationPluginBase implemen
]));
return FALSE;
}
touch($this->getFilePath($dataset));
$filePath = $this->getFilePath($dataset);
$this->fileSystem->delete($filePath);
touch($filePath);
return TRUE;
}
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\data_pipelines\Unit\Plugin\DatasetDestination;
use Drupal\Component\Serialization\Json;
use Drupal\data_pipelines\Plugin\DatasetDestination\JsonDestination;
use Drupal\Tests\data_pipelines\Kernel\DatasetKernelTestBase;
......@@ -15,10 +14,11 @@ use Drupal\Tests\data_pipelines\Kernel\DatasetKernelTestBase;
class JsonDestinationTest extends DatasetKernelTestBase {
/**
* @covers ::saveDataSet
* @covers ::beginProcessing
* @covers ::processChunk
* @covers ::deleteDataSet
*/
public function testSaveDataDeleteData() {
public function testJsonDestinationCreateUpdateDelete() {
$destinationId = $this->randomMachineName();
$destination = $this->createTestMemoryDestination(['id' => $destinationId]);
$dataset = $this->createTestDataset(['destinations' => $destination]);
......@@ -32,11 +32,21 @@ class JsonDestinationTest extends DatasetKernelTestBase {
$plugin_id = 'foo';
$plugin_definition = [];
$destinationPlugin = new JsonDestination($configuration, $plugin_id, $plugin_definition, $fileSystem, $streamWrapperManager);
$file_path = $destinationPlugin->getFilePath($dataset);
// Create.
$this->assertTrue($destinationPlugin->beginProcessing($dataset));
$this->assertTrue($destinationPlugin->processChunk($dataset, iterator_to_array($dataset->getDataIterator())));
$file_path = 'public://' . $dataset->getMachineName() . '.json';
$this->assertEquals(Json::encode(iterator_to_array($dataset->getDataIterator())), file_get_contents($file_path));
$this->assertEquals('[{"should_we":true,"full_name":"bloggs, joe"},{"should_we":false,"full_name":"bloggs, betty"}]', file_get_contents($file_path));
// Update.
$dataset->csv_text[0]->value .= "\nY,robin,scherbatsky";
$dataset->save();
$this->assertTrue($destinationPlugin->beginProcessing($dataset));
$this->assertTrue($destinationPlugin->processChunk($dataset, iterator_to_array($dataset->getDataIterator())));
$this->assertEquals('[{"should_we":true,"full_name":"bloggs, joe"},{"should_we":false,"full_name":"bloggs, betty"},{"should_we":true,"full_name":"scherbatsky, robin"}]', file_get_contents($file_path));
// Delete.
$this->assertTrue($destinationPlugin->deleteDataSet($dataset, $destination));
$this->assertFileDoesNotExist($file_path);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment