Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Infrastructure/ActivesyncTest.php
<?php | <?php | ||||
namespace Tests\Infrastructure; | namespace Tests\Infrastructure; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
use Illuminate\Support\Str; | use Illuminate\Support\Str; | ||||
class ActivesyncTest extends TestCase | class ActivesyncTest extends TestCase | ||||
{ | { | ||||
private static ?\GuzzleHttp\Client $client = null; | private static ?\GuzzleHttp\Client $client = null; | ||||
private static ?\App\User $user = null; | private static ?\App\User $user = null; | ||||
private static ?string $deviceId = null; | private static ?string $deviceId = null; | ||||
private static function toWbxml($xml) | private static function toWbxml($xml) | ||||
{ | { | ||||
$outputStream = fopen("php://temp", 'r+'); | $outputStream = fopen("php://temp", 'r+'); | ||||
$encoder = new \Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3); | $encoder = new \Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3); | ||||
Lint: Instantiated class Syncroton_Wbxml_Encoder not found.: Instantiated class Syncroton_Wbxml_Encoder not found. | |||||
$dom = new \DOMDocument(); | $dom = new \DOMDocument(); | ||||
$dom->loadXML($xml); | $dom->loadXML($xml); | ||||
$encoder->encode($dom); | $encoder->encode($dom); | ||||
Lint: Call to method encode() on an unknown class Syncroton_Wbxml_Encoder. Call to method encode() on an unknown class Syncroton_Wbxml_Encoder. Lint: Call to method encode() on an unknown class Syncroton_Wbxml_Encoder.: Call to method encode() on an unknown class Syncroton_Wbxml_Encoder. | |||||
rewind($outputStream); | rewind($outputStream); | ||||
return stream_get_contents($outputStream); | return stream_get_contents($outputStream); | ||||
} | } | ||||
private static function fromWbxml($binary) | private static function fromWbxml($binary) | ||||
{ | { | ||||
$stream = fopen('php://memory', 'r+'); | $stream = fopen('php://memory', 'r+'); | ||||
fwrite($stream, $binary); | fwrite($stream, $binary); | ||||
rewind($stream); | rewind($stream); | ||||
$decoder = new \Syncroton_Wbxml_Decoder($stream); | $decoder = new \Syncroton_Wbxml_Decoder($stream); | ||||
Lint: Instantiated class Syncroton_Wbxml_Decoder not found. Instantiated class Syncroton_Wbxml_Decoder not found. Lint: Instantiated class Syncroton_Wbxml_Decoder not found.: Instantiated class Syncroton_Wbxml_Decoder not found. | |||||
return $decoder->decode(); | return $decoder->decode(); | ||||
Lint: Call to method decode() on an unknown class Syncroton_Wbxml_Decoder. Call to method decode() on an unknown class Syncroton_Wbxml_Decoder. Lint: Call to method decode() on an unknown class Syncroton_Wbxml_Decoder.: Call to method decode() on an unknown class Syncroton_Wbxml_Decoder. | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
if (!self::$user) { | |||||
self::$user = $this->getTestUser('activesynctest@kolab.org', ['password' => 'simple123'], true); | |||||
} | |||||
if (!self::$deviceId) { | if (!self::$deviceId) { | ||||
// By always creating a new device we force syncroton to initialize. | // By always creating a new device we force syncroton to initialize. | ||||
// Otherwise we work against uninitialized metadata (subscription states), | // Otherwise we work against uninitialized metadata (subscription states), | ||||
// because the account has been removed, but syncroton doesn't reinitalize the metadata for known devices. | // because the account has been removed, but syncroton doesn't reinitalize the metadata for known devices. | ||||
self::$deviceId = (string) Str::uuid(); | self::$deviceId = (string) Str::uuid(); | ||||
} | } | ||||
$deviceId = self::$deviceId; | |||||
\config(['imap.default_folders' => [ | |||||
'Drafts' => [ | |||||
'metadata' => [ | |||||
'/private/vendor/kolab/folder-type' => 'mail.drafts', | |||||
'/private/vendor/kolab/activesync' => "{\"FOLDER\":{\"{$deviceId}\":{\"S\":1}}}" | |||||
], | |||||
], | |||||
'Calendar' => [ | |||||
'metadata' => [ | |||||
'/private/vendor/kolab/folder-type' => 'event.default', | |||||
'/private/vendor/kolab/activesync' => "{\"FOLDER\":{\"{$deviceId}\":{\"S\":1}}}" | |||||
], | |||||
], | |||||
'Contacts' => [ | |||||
'metadata' => [ | |||||
'/private/vendor/kolab/folder-type' => 'contact.default', | |||||
'/private/vendor/kolab/activesync' => "{\"FOLDER\":{\"{$deviceId}\":{\"S\":1}}}" | |||||
], | |||||
], | |||||
]]); | |||||
if (!self::$user) { | |||||
self::$user = $this->getTestUser('activesynctest@kolab.org', ['password' => 'simple123'], true); | |||||
} | |||||
if (!self::$client) { | if (!self::$client) { | ||||
self::$client = new \GuzzleHttp\Client([ | self::$client = new \GuzzleHttp\Client([ | ||||
'http_errors' => false, // No exceptions | 'http_errors' => false, // No exceptions | ||||
'base_uri' => \config("services.activesync.uri"), | 'base_uri' => \config("services.activesync.uri"), | ||||
'verify' => false, | 'verify' => false, | ||||
'auth' => [self::$user->email, 'simple123'], | 'auth' => [self::$user->email, 'simple123'], | ||||
'connect_timeout' => 10, | 'connect_timeout' => 10, | ||||
'timeout' => 10, | 'timeout' => 10, | ||||
Show All 40 Lines | public function testList() | ||||
$this->assertEquals(200, $response->getStatusCode()); | $this->assertEquals(200, $response->getStatusCode()); | ||||
$dom = self::fromWbxml($response->getBody()); | $dom = self::fromWbxml($response->getBody()); | ||||
$xml = $dom->saveXML(); | $xml = $dom->saveXML(); | ||||
$this->assertStringContainsString('INBOX', $xml); | $this->assertStringContainsString('INBOX', $xml); | ||||
// The hash is based on the name, so it's always the same | // The hash is based on the name, so it's always the same | ||||
$inboxId = '38b950ebd62cd9a66929c89615d0fc04'; | $inboxId = '38b950ebd62cd9a66929c89615d0fc04'; | ||||
$this->assertStringContainsString($inboxId, $xml); | $this->assertStringContainsString($inboxId, $xml); | ||||
//TODO for this to work we need to create the default folders in IMAP::createUser | $this->assertStringContainsString('Calendar', $xml); | ||||
// $this->assertStringContainsString('Drafts', $result); | $this->assertStringContainsString('Contacts', $xml); | ||||
machniakUnsubmitted Not Done Inline ActionsWhat about Drafts? machniak: What about Drafts? | |||||
// $this->assertStringContainsString('Sent', $result); | |||||
// $this->assertStringContainsString('Trash', $result); | |||||
// $this->assertStringContainsString('Calendar', $result); | |||||
// $this->assertStringContainsString('Contacts', $result); | |||||
// Find the inbox for the next step | // Find the inbox for the next step | ||||
// $collectionIds = $dom->getElementsByTagName('ServerId'); | // $collectionIds = $dom->getElementsByTagName('ServerId'); | ||||
// $inboxId = $collectionIds[0]->nodeValue; | // $inboxId = $collectionIds[0]->nodeValue; | ||||
return $inboxId; | return $inboxId; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |
Instantiated class Syncroton_Wbxml_Encoder not found.