-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools; | ||
|
||
use CurlHandle; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools; | ||
|
||
use whikloj\BagItTools\Exceptions\BagItException; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test; | ||
|
||
use donatj\MockWebServer\MockWebServer; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test; | ||
|
||
use whikloj\BagItTools\DownloadFile; | ||
use whikloj\BagItTools\Exceptions\BagItException; | ||
|
||
/** | ||
* Class DownloadFileTest | ||
* @package whikloj\BagItTools\Test | ||
* @coversDefaultClass \whikloj\BagItTools\DownloadFile | ||
* @since 5.0.0 | ||
* @author whikloj | ||
*/ | ||
class DownloadFileTest extends BagItTestFramework | ||
{ | ||
/** | ||
* @covers ::__construct | ||
* @covers ::getUrl | ||
* @covers ::getDestination | ||
* @covers ::getSize | ||
* @covers ::getSizeString | ||
*/ | ||
public function testCreateAndGet(): void | ||
{ | ||
$file = new DownloadFile('uri', 'data/destination.txt'); | ||
$this->assertInstanceOf(DownloadFile::class, $file); | ||
$this->assertEquals('uri', $file->getUrl()); | ||
$this->assertEquals('data/destination.txt', $file->getDestination()); | ||
$this->assertNull($file->getSize()); | ||
$this->assertEquals("-", $file->getSizeString()); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::getUrl | ||
* @covers ::getDestination | ||
* @covers ::getSize | ||
* @covers ::getSizeString | ||
*/ | ||
public function testCreateAndGetSize(): void | ||
{ | ||
$file = new DownloadFile('uri', 'data/destination.txt', 1024); | ||
$this->assertInstanceOf(DownloadFile::class, $file); | ||
$this->assertEquals('uri', $file->getUrl()); | ||
$this->assertEquals('data/destination.txt', $file->getDestination()); | ||
$this->assertEquals(1024, $file->getSize()); | ||
$this->assertEquals("1024", $file->getSizeString()); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::validateDownload | ||
* @covers ::validateUrl | ||
* @covers ::internalValidateUrl | ||
*/ | ||
public function testValidate(): void | ||
{ | ||
$file = new DownloadFile('http://somehost.io/filename', 'data/destination.txt'); | ||
$file->validateDownload(); | ||
$this->assertTrue(true); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::validateDownload | ||
* @covers ::validateUrl | ||
*/ | ||
public function testInvalidUrl(): void | ||
{ | ||
$file = new DownloadFile('//somehost.io/filename', 'data/destination.txt'); | ||
$this->expectException(BagItException::class); | ||
$file->validateDownload(); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::validateDownload | ||
* @covers ::validateUrl | ||
* @covers ::internalValidateUrl | ||
*/ | ||
public function testInvalidUrlScheme(): void | ||
{ | ||
$file = new DownloadFile('ftp://somehost.io/filename', 'data/destination.txt'); | ||
$this->expectException(BagItException::class); | ||
$file->validateDownload(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
use Exception; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
use ReflectionException; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
use whikloj\BagItTools\Profiles\ProfileTags; | ||
use whikloj\BagItTools\Test\BagItTestFramework; | ||
|
||
/** | ||
* Class ProfileTagTest | ||
* @package whikloj\BagItTools\Test\Profiles | ||
* @coversDefaultClass \whikloj\BagItTools\Profiles\ProfileTags | ||
* @since 5.0.0 | ||
* @group Profiles | ||
* @author whikloj | ||
*/ | ||
class ProfileTagTest extends BagItTestFramework | ||
{ | ||
/** | ||
* @covers ::__construct | ||
* @covers ::getTag | ||
* @covers ::isRequired | ||
* @covers ::getValues | ||
* @covers ::isRepeatable | ||
* @covers ::getDescription | ||
*/ | ||
public function testBasicTag(): void | ||
{ | ||
$tag = new ProfileTags( | ||
'Bag-Size', | ||
true, | ||
[ | ||
'some value', | ||
], | ||
false, | ||
'The size of the bag in bytes' | ||
); | ||
$this->assertEquals('Bag-Size', $tag->getTag()); | ||
$this->assertTrue($tag->isRequired()); | ||
$this->assertArrayEquals(['some value'], $tag->getValues()); | ||
$this->assertFalse($tag->isRepeatable()); | ||
$this->assertEquals('The size of the bag in bytes', $tag->getDescription()); | ||
} | ||
|
||
/** | ||
* @covers ::setOtherTagOptions | ||
* @covers ::getOtherTagOptions | ||
*/ | ||
public function testOtherTags(): void | ||
{ | ||
$tag = new ProfileTags( | ||
'Bag-Size', | ||
true, | ||
[ | ||
'some value', | ||
], | ||
false, | ||
'The size of the bag in bytes' | ||
); | ||
|
||
$otherOptions = [ | ||
'some' => 'value', | ||
'another' => 'thing', | ||
]; | ||
|
||
$method = $this->getReflectionMethod('\whikloj\BagItTools\Profiles\ProfileTags', 'setOtherTagOptions'); | ||
|
||
$method->invoke($tag, $otherOptions); | ||
|
||
$this->assertArrayEquals($otherOptions, $tag->getOtherTagOptions()); | ||
} | ||
|
||
/** | ||
* @covers ::fromJson | ||
* @covers ::getTag | ||
* @covers ::isRequired | ||
* @covers ::getValues | ||
* @covers ::isRepeatable | ||
* @covers ::getDescription | ||
*/ | ||
public function testFromJsonBasic(): void | ||
{ | ||
$json = '{"required": true, "values": ["some value"], "repeatable": false, ' | ||
. '"description": "The size of the bag in bytes"}'; | ||
$decoded = json_decode($json, true); | ||
$tag = ProfileTags::fromJson("Bag-Size", $decoded); | ||
$this->assertEquals('Bag-Size', $tag->getTag()); | ||
$this->assertTrue($tag->isRequired()); | ||
$this->assertArrayEquals(['some value'], $tag->getValues()); | ||
$this->assertFalse($tag->isRepeatable()); | ||
$this->assertEquals('The size of the bag in bytes', $tag->getDescription()); | ||
} | ||
|
||
/** | ||
* @covers ::fromJson | ||
* @covers ::getTag | ||
* @covers ::isRequired | ||
* @covers ::getValues | ||
* @covers ::isRepeatable | ||
* @covers ::getDescription | ||
* @covers ::getOtherTagOptions | ||
*/ | ||
public function testFromJsonExtended(): void | ||
{ | ||
$json = '{"required": true, "values": ["some value"], "repeatable": false, ' | ||
. '"description": "The size of the bag in bytes", "other": {"some": "value", "another": "thing"}}'; | ||
$decoded = json_decode($json, true); | ||
$tag = ProfileTags::fromJson("Bag-Size", $decoded); | ||
$this->assertEquals('Bag-Size', $tag->getTag()); | ||
$this->assertTrue($tag->isRequired()); | ||
$this->assertArrayEquals(['some value'], $tag->getValues()); | ||
$this->assertFalse($tag->isRepeatable()); | ||
$this->assertEquals('The size of the bag in bytes', $tag->getDescription()); | ||
$other = $tag->getOtherTagOptions(); | ||
$this->assertArrayHasKey('other', $other); | ||
$this->assertArrayEquals(['some' => 'value', 'another' => 'thing'], $other['other']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
use whikloj\BagItTools\Bag; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace whikloj\BagItTools\Test\Profiles; | ||
|
||
use whikloj\BagItTools\Bag; | ||
|