Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change bag to extended when adding a fetch file #66

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}