Skip to content

Commit

Permalink
Change bag to extended when adding a fetch file
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj committed Apr 17, 2024
1 parent b831fc9 commit c0e8a81
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Bag.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ public function addFetchFile(string $url, string $destination, int $size = null)
$this->fetchFile = new Fetch($this, false);
}
$this->fetchFile->addFile($url, $destination, $size);
$this->setExtended(true);
$this->changed = true;
}

Expand Down
37 changes: 29 additions & 8 deletions tests/FetchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ class FetchTest extends BagItTestFramework
/**
* A mock webserver for some remote download tests.
*
* @var \donatj\MockWebServer\MockWebServer
* @var MockWebServer
*/
private static $webserver;
private static MockWebServer $webserver;

/**
* Array of file contents for use with comparing against requests against the same index in self::$remote_urls
*
* @var array
* @var array<int, mixed>
*/
private static $response_content = [];
private static array $response_content = [];

/**
* Array of mock urls to get responses from. Match response bodies against matching key in self::$response_content
*
* @var array
* @var array<int, string>
*/
private static $remote_urls = [];
private static array $remote_urls = [];

/**
* {@inheritdoc}
Expand Down Expand Up @@ -118,9 +118,9 @@ public static function tearDownAfterClass(): void
* Utility to make a bag with a specific fetch file and return the fetch.
* @param string $fetchFile
* The name of the file in the FETCH_FILES directory.
* @return \whikloj\BagItTools\Fetch
* @return Fetch
* The Fetch object.
* @throws \whikloj\BagItTools\Exceptions\BagItException
* @throws BagItException
* If we can't read the fetch.txt
*/
private function setupBag(string $fetchFile): Fetch
Expand Down Expand Up @@ -725,6 +725,9 @@ public function testCreateFetchWithEncodedCharacters(): void
$this->assertArrayEquals($expected_in_memory, array_keys($manifest->getHashes()));
}

/**
* @covers ::getData
*/
public function testReadCRLineEndings(): void
{
$fetch = $this->setupBag('fetch-CR.txt');
Expand All @@ -735,6 +738,9 @@ public function testReadCRLineEndings(): void
$this->assertTrue(in_array('http://example.org/some/file/2', array_column($cr_data, 'uri')));
}

/**
* @covers ::getData
*/
public function testReadLFLineEndings(): void
{
$fetch = $this->setupBag('fetch-LF.txt');
Expand All @@ -745,6 +751,9 @@ public function testReadLFLineEndings(): void
$this->assertTrue(in_array('http://example.org/some/file/2', array_column($cr_data, 'uri')));
}

/**
* @covers ::getData
*/
public function testReadCRLFLineEndings(): void
{
$fetch = $this->setupBag('fetch-CRLF.txt');
Expand All @@ -754,4 +763,16 @@ public function testReadCRLFLineEndings(): void
$this->assertTrue(in_array('http://example.org/some/file/1', array_column($cr_data, 'uri')));
$this->assertTrue(in_array('http://example.org/some/file/2', array_column($cr_data, 'uri')));
}

/**
* Test that we now automatically set the bag to extended when adding a fetch file.
* @covers \whikloj\BagItTools\Bag::addFetchFile
*/
public function testAddFetchAutoSetExtended(): void
{
$bag = Bag::create($this->tmpdir);
$this->assertFalse($bag->isExtended());
$bag->addFetchFile(self::$remote_urls[0], 'data/first.txt');
$this->assertTrue($bag->isExtended());
}
}

0 comments on commit c0e8a81

Please sign in to comment.