initial commit

This commit is contained in:
2021-12-20 12:50:53 +01:00
commit 839913d51a
51 changed files with 13051 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testConvertToEan13 extends TestCase
{
public function testFormatEan13()
{
$ean13 = Isbn::convertToEan13("978-2-207-25804-0");
$this->assertEquals(
"9782207258040",
$ean13,
"It should convert to EAN-13"
);
}
public function testFormatEan13InvalidIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::convertToEan13("ABC-80-7203-7");
}
}

View File

@ -0,0 +1,51 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testConvertToGtin14 extends TestCase
{
public function testFormatGtin14()
{
$gtin14 = Isbn::convertToGtin14("9783464603529", 2);
$this->assertEquals(
"29783464603523",
$gtin14,
"It should convert to GTIN-14"
);
}
public function testFormatGtin14WithDefaultPrefix()
{
$gtin14 = Isbn::convertToGtin14("9783464603529");
$this->assertEquals(
"19783464603526",
$gtin14,
"It should convert to GTIN-14 using 1 as default prefix"
);
}
public function testFormatGtin14InvalidIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::convertToGtin14("ABC-80-7203-7", 1);
}
}

View File

@ -0,0 +1,52 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testConvertToIsbn10 extends TestCase
{
public function testFormatIsbn10()
{
$isbn10 = Isbn::convertToIsbn10("9783464603529");
$this->assertEquals(
"3-464-60352-0",
$isbn10,
"It should convert to ISBN-10"
);
}
public function testFormatIsbn10WithX()
{
$isbn10 = Isbn::convertToIsbn10("978-80-7203-717-9");
$this->assertEquals(
"80-7203-717-X",
$isbn10,
"It should convert to ISBN-10 with X as a checksum character"
);
}
public function testFormatIsbn10InvalidIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
// FIXME: Improve message: Input contains invalid characters "ABC"
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::convertToIsbn10("ABC-80-7203-7");
}
}

View File

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testConvertToIsbn13 extends TestCase
{
public function testFormatIsbn13()
{
$Isbn13 = Isbn::convertToIsbn13("9782207258040");
$this->assertEquals(
"978-2-207-25804-0",
$Isbn13,
"It should convert to ISBN-13"
);
}
public function testFormatIsbn13InvalidIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::convertToIsbn13("ABC-80-7203-7");
}
}

View File

@ -0,0 +1,34 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testConstructor extends TestCase
{
/**
* Non-regression test for Github issue #5
* https://github.com/biblys/isbn/pull/5
*/
public function testUnknownPrefix()
{
$isbn = new Isbn("9790706801940");
$this->expectNotToPerformAssertions("Should not throw");
}
}

View File

@ -0,0 +1,76 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testFormatIsbn extends TestCase
{
protected function setUp(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
}
public function testDeprecatedNotice()
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->format is deprecated and will be removed in the future. Use the Isbn::convertToIsbn13 method instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn('9782207258040');
$isbn->format('ISBN-13');
}
public function testFormatIsbn13()
{
$isbn = new Isbn('9782207258040');
$this->assertEquals($isbn->format('ISBN-13'), "978-2-207-25804-0");
}
public function testFormatIsbn10()
{
$isbn10 = new Isbn('9783464603529');
$this->assertEquals($isbn10->format('ISBN-10'), "3-464-60352-0");
}
public function testFormatEan13()
{
$isbn10 = new Isbn("978-2-207-25804-0");
$this->assertEquals($isbn10->format('EAN'), "9782207258040");
}
public function testFormatEan_13()
{
$isbn10 = new Isbn("978-2-207-25804-0");
$this->assertEquals($isbn10->format('EAN-13'), "9782207258040");
}
public function testFormatGtin14()
{
$isbn = new Isbn('9783464603529');
$this->assertEquals($isbn->format('GTIN-14'), '19783464603526');
}
public function testMauritiusRange()
{
$isbn = new Isbn('9786130971311');
$this->assertEquals($isbn->format('ISBN-13'), "978-613-0-97131-1");
}
}

View File

@ -0,0 +1,42 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testGetErrors extends TestCase
{
public function testDeprecatedNotice()
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->getErrors is deprecated and will be removed in the future. Use Isbn::validateAs… methods instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn("6897896354577");
$isbn->getErrors();
}
public function testInvalidIsbn()
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
$isbn = new Isbn("6897896354577");
$this->assertEquals($isbn->getErrors(), '[6897896354577] Product code should be 978 or 979');
}
}

View File

@ -0,0 +1,65 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testIsbnIsValid extends TestCase
{
protected function setUp(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
}
public function testDeprecationNotice(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->isValid is deprecated and will be removed in the future. Use Isbn::validateAs… methods instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn('9782207258040');
$isbn->isValid();
}
public function testIsValid()
{
$isbn = new Isbn('9782207258040');
$this->assertTrue($isbn->isValid());
}
public function testIsNotValid()
{
$invalid = new Isbn('5780AAC728440');
$this->assertFalse($invalid->isValid());
}
public function testIsbn10WithChecksumX()
{
$isbn = new ISBN('80-7203-717-X');
$this->assertTrue($isbn->isValid());
}
public function testValidateMexicanIsbn()
{
$isbn = new Isbn("9700764923");
$this->assertTrue($isbn->isValid());
}
}

View File

@ -0,0 +1,66 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testValidateIsbn extends TestCase
{
protected function setUp(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
}
public function testDeprecatedNotice(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->validate is deprecated and will be removed in the future. Use Isbn::validateAs… methods instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn('9782843449499');
$isbn->validate();
}
public function testValidateValidIsbn()
{
$isbn = new Isbn('9782843449499');
$this->assertTrue($isbn->validate());
}
/**
* Non-regression test for Github issue #6
* https://github.com/biblys/isbn/issues/6
*/
public function testValidateIsbn10WithChecksumX()
{
$isbn = new Isbn('80-7203-717-X');
$this->assertTrue($isbn->validate());
}
/**
* Non-regression test for Github issue #21
* https://github.com/biblys/isbn/issues/21
*/
public function testValidateMexicanIsbn()
{
$isbn = new Isbn("9700764923");
$this->assertTrue($isbn->validate());
}
}

View File

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testIsParsable extends TestCase
{
public function testParsableIsbn()
{
$isParsable = Isbn::isParsable("9782207258040");
$this->assertTrue($isParsable);
}
public function testUnparsableIsbn()
{
$isParsable = Isbn::isParsable("9782SPI258040");
$this->assertFalse($isParsable);
}
}

View File

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testValidateAsEan13 extends TestCase
{
public function testValidIsbn()
{
Isbn::validateAsEan13("9782207258040");
$this->expectNotToPerformAssertions("It should not throw");
}
public function testUnparsableIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::validateAsEan13("9782SPI258040");
}
public function testIsbnWithHyphens()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("978-2-207-25804-0 is not a valid EAN-13. Expected 9782207258040.");
Isbn::validateAsEan13("978-2-207-25804-0");
}
public function testIsbnWithIncorrectCheckum()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("9782207258049 is not a valid EAN-13. Expected 9782207258040.");
Isbn::validateAsEan13("9782207258049");
}
}

View File

@ -0,0 +1,62 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testValidateAsIsbn10 extends TestCase
{
public function testValidIsbn()
{
Isbn::validateAsIsbn10("3-464-60352-0");
$this->expectNotToPerformAssertions("It should not throw");
}
public function testUnparsableIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::validateAsIsbn10("3-ABC-60352-0");
}
public function testIsbnWithMisplacedHyphen()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("3-46460-352-0 is not a valid ISBN-10. Expected 3-464-60352-0.");
Isbn::validateAsIsbn10("3-46460-352-0");
}
public function testIsbnWithoutHyphens()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("3464603520 is not a valid ISBN-10. Expected 3-464-60352-0.");
Isbn::validateAsIsbn10("3464603520");
}
public function testIsbnWithIncorrectCheckum()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("3-46460-352-X is not a valid ISBN-10. Expected 3-464-60352-0.");
Isbn::validateAsIsbn10("3-46460-352-X");
}
}

View File

@ -0,0 +1,107 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';
use Biblys\Isbn\Isbn;
use PHPUnit\Framework\TestCase;
class testValidateAsIsbn13 extends TestCase
{
public function testValidIsbn()
{
Isbn::validateAsIsbn13("978-2-207-25804-0");
$this->expectNotToPerformAssertions("It should not throw");
}
public function testUnparsableIsbn()
{
$this->expectException("Biblys\Isbn\IsbnParsingException");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::validateAsIsbn13("978-2-SPI-25804-0");
}
public function testIsbnWithMisplacedHyphen()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("978-220-7-25804-0 is not a valid ISBN-13. Expected 978-2-207-25804-0.");
Isbn::validateAsIsbn13("978-220-7-25804-0");
}
public function testIsbnWithoutHyphens()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("9782207258040 is not a valid ISBN-13. Expected 978-2-207-25804-0.");
Isbn::validateAsIsbn13("9782207258040");
}
public function testIsbnWithIncorrectCheckum()
{
$this->expectException("Biblys\Isbn\IsbnValidationException");
$this->expectExceptionMessage("978-2-207-25804-2 is not a valid ISBN-13. Expected 978-2-207-25804-0.");
Isbn::validateAsIsbn13("978-2-207-25804-2");
}
public function testValidateInvalidProductCode()
{
$this->expectException("Exception");
$this->expectExceptionMessage("Product code should be 978 or 979");
Isbn::validateAsIsbn13('6752843449499');
}
public function testValidateInvalidCharacters()
{
$this->expectException("Exception");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::validateAsIsbn13('5780AAC728440');
}
public function testIsbnWithInvalidProductCode()
{
$this->expectException("Exception");
$this->expectExceptionMessage("Product code should be 978 or 979");
Isbn::validateAsIsbn13('6897896354577');
}
public function testIsbnWithInvalidCountryCode()
{
$this->expectException("Exception");
$this->expectExceptionMessage("Country code is unknown");
Isbn::validateAsIsbn13('9792887382562');
}
/**
* Non regression-test for Github issue #22
* https://github.com/biblys/isbn/issues/22
*/
public function testOtherInvalidIsbn()
{
$this->expectException("Exception");
$this->expectExceptionMessage("Invalid characters in the code");
Isbn::validateAsIsbn13("34995031X");
}
}