1
0

ClientMapperTest.php 2.8 KB

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