Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
We cannot work with streams directly and compare them, because we need to
convert them to strings for the caching backend.
  • Loading branch information
yunosh committed Feb 24, 2014
1 parent 8afcf7b commit 7a82dd6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ public function testGetMissingAttachment()
public function testGetAttachment()
{
$resource = fopen('php://temp', 'r+');
fwrite($resource, 'test');
$this->horde_cache = $this->getMockCache();
$cache = $this->horde_cache->getDataCache(
array(
Expand All @@ -433,26 +434,30 @@ public function testGetAttachment()
$this->horde_cache->storeAttachment(
$cache->getDataId(), '100', '1', $resource
);
rewind($resource);
$this->assertSame(
$resource,
$cache->getAttachment('100', '1')
stream_get_contents($resource),
stream_get_contents($cache->getAttachment('100', '1'))
);
}

public function testGetStoredAttachment()
{
$data = 'test';
$resource = fopen('php://temp', 'r+');
fwrite($resource, $data);
$this->assertSame(
$resource,
$this->_getSyncedCacheWithAttachment($resource)
->getAttachment('100', '1')
$data,
stream_get_contents(
$this->_getSyncedCacheWithAttachment($data)
->getAttachment('100', '1')
)
);
}

public function testDeletedAttachment()
{
$resource = fopen('php://temp', 'r+');
$cache = $this->_getSyncedCacheWithAttachment($resource);
$cache = $this->_getSyncedCacheWithAttachment('');
$cache->store(
array(),
new Horde_Kolab_Storage_Folder_Stamp_Uids('c', 'd'),
Expand All @@ -470,7 +475,7 @@ public function testGetAttachmentByName()
array('1', '3'),
array_keys(
$this->_getSyncedCacheWithAttachment('Y')
->getAttachmentByName('100', 'test.txt')
->getAttachmentByName('100', 'test.txt')
)
);
}
Expand Down Expand Up @@ -569,8 +574,9 @@ private function _getSyncedCacheWithMoreData()
return $cache;
}

private function _getSyncedCacheWithAttachment($resource)
private function _getSyncedCacheWithAttachment($data)
{
$resource = Horde_Stream_Wrapper_String::getStream($data);
$cache = $this->getMockDataCache();
$cache->store(
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public function testLoadAttachment()

public function testStoreAttachment()
{

$this->cache->storeAttachment('test', '1', '1', $this->_getResource());
$this->assertEquals(
'test',
Expand All @@ -207,11 +206,15 @@ public function testStoreSameAttachment()
$resource2 = $this->_getResource();
$this->cache->storeAttachment('test', '1', '1', $resource);
$this->cache->storeAttachment('test', '1', '1', $resource2);
rewind($resource);
rewind($resource2);
$this->assertSame(
$resource2, $this->cache->loadAttachment('test', '1', '1')
stream_get_contents($resource2),
stream_get_contents($this->cache->loadAttachment('test', '1', '1'))
);
$this->assertNotSame(
$resource, $this->cache->loadAttachment('test', '1', '1')
$this->assertSame(
stream_get_contents($resource),
stream_get_contents($this->cache->loadAttachment('test', '1', '1'))
);
}

Expand All @@ -221,11 +224,15 @@ public function testStoreDifferentUidAttachment()
$resource2 = $this->_getResource();
$this->cache->storeAttachment('test', '1', '1', $resource);
$this->cache->storeAttachment('test', '2', '1', $resource2);
rewind($resource);
rewind($resource2);
$this->assertSame(
$resource, $this->cache->loadAttachment('test', '1', '1')
stream_get_contents($resource),
stream_get_contents($this->cache->loadAttachment('test', '1', '1'))
);
$this->assertSame(
$resource2, $this->cache->loadAttachment('test', '2', '1')
stream_get_contents($resource2),
stream_get_contents($this->cache->loadAttachment('test', '2', '1'))
);
}

Expand All @@ -235,11 +242,15 @@ public function testStoreDifferentAttachmentId()
$resource2 = $this->_getResource();
$this->cache->storeAttachment('test', '1', '1', $resource);
$this->cache->storeAttachment('test', '1', '2', $resource2);
rewind($resource);
rewind($resource2);
$this->assertSame(
$resource, $this->cache->loadAttachment('test', '1', '1')
stream_get_contents($resource),
stream_get_contents($this->cache->loadAttachment('test', '1', '1'))
);
$this->assertSame(
$resource2, $this->cache->loadAttachment('test', '1', '2')
stream_get_contents($resource2),
stream_get_contents($this->cache->loadAttachment('test', '1', '2'))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function testDefaultType()
{
$this->assertEquals(
'event',
$this->_getDataCache()
->getType()
$this->_getDataCache()->getType()
);
}

Expand Down

0 comments on commit 7a82dd6

Please sign in to comment.