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

SDK-810: E2E Tests #48

Open
wants to merge 14 commits into
base: development
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ $ ./vendor/bin/phpunit tests
## API Coverage

* Activity Details
* [X] RememberMe ID `getRememberMeId()`
* [X] Remember Me ID `getRememberMeId()`
* [X] Parent Remember Me ID `getParentRememberMeId()`
* [X] Receipt ID `getReceiptId()`
* [X] Timestamp `getTimestamp()` // DateTime Object
* [X] Application Profile `getApplicationProfile()`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yoti/yoti-php-sdk",
"description": "Yoti SDK for quickly integrating your PHP backend with Yoti",
"version": "1.2.1",
"version": "2.0.0",
"keywords": [
"yoti",
"sdk"
Expand Down
13 changes: 13 additions & 0 deletions examples/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is a template for defining the environment variables
# Set the application config values here

YOTI_APP_ID=xxxxxxxxxxxxxxxxxx
YOTI_SCENARIO_ID=xxxxxxxxxxxxxxxx
YOTI_SDK_ID=xxxxxxxxxxxxxxxxxxxxx
# Below is the private key (in .pem format) associated with the Yoti Application you created on Dashboard
YOTI_KEY_FILE_PATH=/path_to_pem_dir/php-sdk-access-security.pem

# Change the API URLs (optional)
YOTI_CONNECT_API=xxxxxxxxxxxxxxxx
YOTI_QR_URL=xxxxxxxxxxxxxxxx
YOTI_CONNECT_URL=xxxxxxxxxxxxxxxx
24 changes: 12 additions & 12 deletions examples/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</head>
<body class="yoti-body">
<h2><a href="/">Home</a></h2>
<h3>Could not login user for the following reason: <?php echo isset($_GET['msg']) ? $_GET['msg'] : '' ?> </h3>
<h3>Could not login user for the following reason: <?php echo isset($_GET['msg']) ? htmlspecialchars($_GET['msg']) : '' ?> </h3>
</body>
</html>
8 changes: 7 additions & 1 deletion examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@

<script src="https://sdk.yoti.com/clients/browser.2.2.0.js"></script>
<script>
_ybg.init()
<?php if (getenv('YOTI_QR_URL')) { ?>
_ybg.config.qr = "<?php echo getenv('YOTI_QR_URL'); ?>";
<?php } ?>
<?php if (getenv('YOTI_CONNECT_URL')) { ?>
_ybg.config.service = "<?php echo getenv('YOTI_CONNECT_URL'); ?>";
<?php } ?>
_ybg.init();
</script>
</body>
</html>
8 changes: 7 additions & 1 deletion examples/profile.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
$token = isset($_GET['token']) ? $_GET['token'] : '';
$profileAttributes = [];

// Allow Connect API to be configured.
$connect_api = Yoti\YotiClient::DEFAULT_CONNECT_API;
if (!empty(getenv('YOTI_CONNECT_API'))) {
$connect_api = getenv('YOTI_CONNECT_API');
}

try {
$yotiClient = new Yoti\YotiClient(getenv('YOTI_SDK_ID'), getenv('YOTI_KEY_FILE_PATH'));
$yotiClient = new Yoti\YotiClient(getenv('YOTI_SDK_ID'), getenv('YOTI_KEY_FILE_PATH'), $connect_api);
$activityDetails = $yotiClient->getActivityDetails($token);
$profile = $activityDetails->getProfile();

Expand Down
90 changes: 72 additions & 18 deletions tests/ActivityDetailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Yoti\Entity\Image;
use Yoti\Entity\ApplicationProfile;

/**
* @coversDefaultClass \Yoti\ActivityDetails
*/
class ActivityDetailsTest extends TestCase
{
/**
Expand All @@ -26,48 +29,91 @@ class ActivityDetailsTest extends TestCase
*/
public $applicationProfile;

public $rememberMeId = 'Hig2yAT79cWvseSuXcIuCLa5lNkAPy70rxetUaeHlTJGmiwc/g1MWdYWYrexWvPU';
/**
* @var string Pem file contents.
*/
private $pem;

/**
* @var array Receipt array.
*/
private $receiptArr;

public function setUp()
{
$pem = file_get_contents(PEM_FILE);
$receiptArr = json_decode(file_get_contents(RECEIPT_JSON), true);
$receipt = new Receipt($receiptArr['receipt']);

$this->activityDetails = new ActivityDetails($receipt, $pem);
$this->pem = file_get_contents(PEM_FILE);
$this->receiptArr = json_decode(file_get_contents(RECEIPT_JSON), true)['receipt'];
$this->activityDetails = new ActivityDetails(
new Receipt($this->receiptArr),
$this->pem
);
$this->profile = $this->activityDetails->getProfile();
$this->applicationProfile = $this->activityDetails->getApplicationProfile();
}

/**
* Test getting ActivityDetails Instance
* Test getting ActivityDetails Instance.
*/
public function testActivityDetailsInstance()
{
$this->assertInstanceOf(ActivityDetails::class, $this->activityDetails);
}

/**
* Test getting RememberMeId
* @covers ::getRememberMeId
*/
public function testGetRememberMeId()
{
$this->assertEquals($this->rememberMeId, $this->activityDetails->getRememberMeId());
$rememberMeId = 'Hig2yAT79cWvseSuXcIuCLa5lNkAPy70rxetUaeHlTJGmiwc/g1MWdYWYrexWvPU';
$this->assertEquals($rememberMeId, $this->activityDetails->getRememberMeId());
}

/**
* @covers ::getRememberMeId
*/
public function testGetRememberMeIdNotPresent()
{
// Remove Remember Me ID from test receipt.
unset($this->receiptArr['remember_me_id']);
$receipt = new Receipt($this->receiptArr);

$activityDetails = new ActivityDetails($receipt, $this->pem);
$this->assertNull($activityDetails->getRememberMeId());
}

/**
* @covers ::getRememberMeId
*/
public function testGetRememberMeIdEmpty()
{
// Set Remember Me ID to empty string.
$this->receiptArr['remember_me_id'] = '';
$receipt = new Receipt($this->receiptArr);

$activityDetails = new ActivityDetails($receipt, $this->pem);
$this->assertEquals('', $activityDetails->getRememberMeId());
}

/**
* @covers ::getParentRememberMeId
*/
public function testGetParentRememberMeIdExists()
{
$this->assertTrue(method_exists($this->activityDetails, 'getParentRememberMeId'));
$parentRememberMeId = 'f5RjVQMyoKOvO/hkv43Ik+t6d6mGfP2tdrNijH4k4qafTG0FSNUgQIvd2Z3Nx1j8';
$this->assertEquals($parentRememberMeId, $this->activityDetails->getParentRememberMeId());
}

/**
* Test getting Given Names
* @covers ::getProfile
*/
public function testGetProfile()
{
$this->assertInstanceOf(Profile::class, $this->activityDetails->getProfile());
}

/**
* @covers ::getApplicationProfile
*/
public function testGetApplicationProfile()
{
$this->assertInstanceOf(
Expand All @@ -77,63 +123,71 @@ public function testGetApplicationProfile()
}

/**
* Test getting Family Name
* @covers \Yoti\Entity\Profile::getFamilyName
*/
public function testGetFamilyName()
{
$this->assertNull($this->profile->getFamilyName());
}

/**
* Test getting Full Name
* @covers \Yoti\Entity\Profile::getFullName
*/
public function testGetFullName()
{
$this->assertNull($this->profile->getFullName());
}

/**
* Test getting Date Of Birth
* @covers \Yoti\Entity\Profile::getDateOfBirth
*/
public function testGetDateOfBirth()
{
$this->assertNull($this->profile->getDateOfBirth());
}

/**
* Test getting Phone Number
* @covers \Yoti\Entity\Profile::getPhoneNumber
* @covers \Yoti\Entity\Attribute::getValue
*/
public function testGetPhoneNumber()
{
$this->assertEquals('+447474747474', $this->profile->getPhoneNumber()->getValue());
}

/**
* Test getting Email Address
* @covers \Yoti\Entity\Profile::getEmailAddress
*/
public function testGetEmailAddress()
{
$this->assertNull($this->profile->getEmailAddress());
}

/**
* Test getting Selfie
* @covers \Yoti\Entity\Profile::getSelfie
* @covers \Yoti\Entity\Attribute::getValue
*/
public function testGetSelfie()
{
$this->assertInstanceOf(Attribute::class, $this->profile->getSelfie());
$this->assertInstanceOf(Image::class, $this->profile->getSelfie()->getValue());
}

/**
* ::getTimestamp
*/
public function testGetTimestamp()
{
$timestamp = $this->activityDetails->getTimestamp();
$this->assertEquals('19-07-2016 08:55:38', $timestamp->format('d-m-Y H:i:s'));
}

/**
* ::getReceiptId
*/
public function testGetReceipt()
{
$receiptId = '9HNJDX5bEIN5TqBm0OGzVIc1LaAmbzfx6eIrwNdwpHvKeQmgPujyogC+r7hJCVPl';
$this->assertEquals($receiptId, $this->activityDetails->getReceiptId());
}
}
}
14 changes: 13 additions & 1 deletion tests/Entity/AnchorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
use YotiTest\Util\Profile\TestAnchors;
use Yoti\Util\Profile\AnchorListConverter;

/**
* @coversDefaultClass \Yoti\Entity\Anchor
*/
class AnchorTest extends TestCase
{
/**
* Check Anchor class exists.
*/
public function testAnchorClassExists()
{
$this->assertTrue(class_exists(Anchor::class));
}

/**
* @covers ::getType
* @covers ::getValue
* @covers ::getSignedTimeStamp
* @covers ::getOriginServerCerts
*/
public function testYotiAnchorEndpoints()
{
$dlAnchor = new \Attrpubapi\Anchor();
Expand Down Expand Up @@ -43,4 +55,4 @@ public function testYotiAnchorEndpoints()
$sourceAnchor->getOriginServerCerts()[0]
);
}
}
}
Loading