1
0

ClientMapperTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace OCA\OAuth2\Tests\Db;
  22. use OCA\OAuth2\Db\Client;
  23. use OCA\OAuth2\Db\ClientMapper;
  24. use Test\TestCase;
  25. /**
  26. * @group DB
  27. */
  28. class ClientMapperTest extends TestCase {
  29. /** @var ClientMapper */
  30. private $clientMapper;
  31. public function setUp() {
  32. parent::setUp();
  33. $this->clientMapper = new ClientMapper(\OC::$server->getDatabaseConnection());
  34. }
  35. public function testGetByIdentifier() {
  36. $client = new Client();
  37. $client->setClientIdentifier('MyAwesomeClientIdentifier');
  38. $client->setName('Client Name');
  39. $client->setRedirectUri('https://example.com/');
  40. $client->setSecret('TotallyNotSecret');
  41. $this->clientMapper->insert($client);
  42. $client->resetUpdatedFields();
  43. $this->assertEquals($client, $this->clientMapper->getByIdentifier('MyAwesomeClientIdentifier'));
  44. }
  45. /**
  46. * @expectedException \OCA\OAuth2\Exceptions\ClientNotFoundException
  47. */
  48. public function testGetByIdentifierNotExisting() {
  49. $this->clientMapper->getByIdentifier('MyTotallyNotExistingClient');
  50. }
  51. public function testGetByUid() {
  52. $client = new Client();
  53. $client->setClientIdentifier('MyNewClient');
  54. $client->setName('Client Name');
  55. $client->setRedirectUri('https://example.com/');
  56. $client->setSecret('TotallyNotSecret');
  57. $this->clientMapper->insert($client);
  58. $client->resetUpdatedFields();
  59. $this->assertEquals($client, $this->clientMapper->getByUid($client->getId()));
  60. }
  61. /**
  62. * @expectedException \OCA\OAuth2\Exceptions\ClientNotFoundException
  63. */
  64. public function testGetByUidNotExisting() {
  65. $this->clientMapper->getByUid(1234);
  66. }
  67. public function testGetClients() {
  68. $this->assertSame('array', gettype($this->clientMapper->getClients()));
  69. }
  70. }