ObjectStoreTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  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 Test\Files\ObjectStore;
  22. use Test\TestCase;
  23. abstract class ObjectStoreTest extends TestCase {
  24. /**
  25. * @return \OCP\Files\ObjectStore\IObjectStore
  26. */
  27. abstract protected function getInstance();
  28. private function stringToStream($data) {
  29. $stream = fopen('php://temp', 'w+');
  30. fwrite($stream, $data);
  31. rewind($stream);
  32. return $stream;
  33. }
  34. public function testWriteRead() {
  35. $stream = $this->stringToStream('foobar');
  36. $instance = $this->getInstance();
  37. $instance->writeObject('1', $stream);
  38. $result = $instance->readObject('1');
  39. $instance->deleteObject('1');
  40. $this->assertEquals('foobar', stream_get_contents($result));
  41. }
  42. public function testDelete() {
  43. $stream = $this->stringToStream('foobar');
  44. $instance = $this->getInstance();
  45. $instance->writeObject('2', $stream);
  46. $instance->deleteObject('2');
  47. try {
  48. // to to read to verify that the object no longer exists
  49. $instance->readObject('2');
  50. $this->fail();
  51. } catch (\Exception $e) {
  52. // dummy assert to keep phpunit happy
  53. $this->assertEquals(1, 1);
  54. }
  55. }
  56. public function testReadNonExisting() {
  57. $instance = $this->getInstance();
  58. try {
  59. $instance->readObject('non-existing');
  60. $this->fail();
  61. } catch (\Exception $e) {
  62. // dummy assert to keep phpunit happy
  63. $this->assertEquals(1, 1);
  64. }
  65. }
  66. public function testDeleteNonExisting() {
  67. $instance = $this->getInstance();
  68. try {
  69. $instance->deleteObject('non-existing');
  70. $this->fail();
  71. } catch (\Exception $e) {
  72. // dummy assert to keep phpunit happy
  73. $this->assertEquals(1, 1);
  74. }
  75. }
  76. }