PoolNamespaceTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * This file is part of the Stash package.
  4. *
  5. * (c) Robert Hafner <tedivm@tedivm.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Stash\Test;
  11. use Stash\Pool;
  12. /**
  13. * @package Stash
  14. * @author Robert Hafner <tedivm@tedivm.com>
  15. */
  16. class PoolNamespaceTest extends AbstractPoolTest
  17. {
  18. protected function getTestPool($skipNametest = false)
  19. {
  20. $pool = parent::getTestPool();
  21. if (!$skipNametest) {
  22. $pool->setNamespace('TestSpace');
  23. }
  24. return $pool;
  25. }
  26. public function testClearNamespacedCache()
  27. {
  28. $pool = $this->getTestPool(true);
  29. // No Namespace
  30. $item = $pool->getItem('base/one');
  31. $item->set($this->data)->save();
  32. // TestNamespace
  33. $pool->setNamespace('TestNamespace');
  34. $item = $pool->getItem('test/one');
  35. $item->set($this->data)->save();
  36. // TestNamespace2
  37. $pool->setNamespace('TestNamespace2');
  38. $item = $pool->getItem('test/one');
  39. $item->set($this->data)->save();
  40. // Clear TestNamespace
  41. $pool->setNamespace('TestNamespace');
  42. $this->assertTrue($pool->clear(), 'Clear succeeds with namespace selected.');
  43. // Return to No Namespace
  44. $pool->setNamespace();
  45. $item = $pool->getItem('base/one');
  46. $this->assertFalse($item->isMiss(), 'Base item exists after other namespace was cleared.');
  47. $this->assertEquals($this->data, $item->get(), 'Base item returns data after other namespace was cleared.');
  48. // Clear All
  49. $this->assertTrue($pool->clear(), 'Clear succeeds with no namespace.');
  50. // Return to TestNamespace2
  51. $pool->setNamespace('TestNamespace2');
  52. $item = $pool->getItem('base/one');
  53. $this->assertTrue($item->isMiss(), 'Namespaced item disappears after complete clear.');
  54. }
  55. public function testNamespacing()
  56. {
  57. $pool = $this->getTestPool(true);
  58. $this->assertAttributeEquals(null, 'namespace', $pool, 'Namespace starts empty.');
  59. $this->assertTrue($pool->setNamespace('TestSpace'), 'setNamespace returns true.');
  60. $this->assertAttributeEquals('TestSpace', 'namespace', $pool, 'setNamespace sets the namespace.');
  61. $this->assertEquals('TestSpace', $pool->getNamespace(), 'getNamespace returns current namespace.');
  62. $this->assertTrue($pool->setNamespace(), 'setNamespace returns true when setting null.');
  63. $this->assertAttributeEquals(null, 'namespace', $pool, 'setNamespace() empties namespace.');
  64. $this->assertFalse($pool->getNamespace(), 'getNamespace returns false when no namespace is set.');
  65. }
  66. }