Skip to content

Commit

Permalink
Fix undefined user when retrieving metadata (#491)
Browse files Browse the repository at this point in the history
* Include dummy user to expose problem with $users
* Use correct user reference when retrieving metadata
* Update ChangeLog
* Added a link to the pull request explaining the issue
  • Loading branch information
matslindh authored and christeredvartsen committed Sep 27, 2016
1 parent 3545ea4 commit 1dc7809
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ __N/A__
* #440: Added configuration option to redirect clients hitting the index page (Christer Edvartsen)
* #408: Moved the metadata cache event listener to a separate project: https://github.com/imbo/imbo-metadata-cache (Christer Edvartsen)

Bug fixes:

* #491: Fix undefined user when retrieving metadata (Mats Lindh)

Imbo-2.2.0
----------
__2016-08-08__

* #475: Validate signed URLs regardless of t[] vs t[0] (Mats Lindh)
* #475: Validate signed URLs regardless of `t[]` vs `t[0]` (Mats Lindh)
* #459: Support wildcards when subscribing to events (Christer Edvartsen)
* #444: Added a getData() method to the Imbo\Model\ModelInterface (Christer Edvartsen)
* #431: Added an Amazon S3 storage adapter for the image variations (Ali Asaria)
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function getImages(array $users, Query $query, Images $model) {
];

if ($returnMetadata) {
$image['metadata'] = $this->getMetadata($user, $row['imageIdentifier']);
$image['metadata'] = $this->getMetadata($row['user'], $row['imageIdentifier']);
}

$images[] = $image;
Expand Down
21 changes: 18 additions & 3 deletions tests/phpunit/integration/Database/DatabaseTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ private function insertImages($alternateUser = false) {
$info = getimagesize($path);

$user = 'user';

if ($alternateUser && $i % 2 === 0) {
$user = 'user2';
}
Expand Down Expand Up @@ -403,25 +404,39 @@ public function testGetImagesWithStartAndEndTimestamps() {
$this->assertSame(1, $model->getHits());
}

/**
* @see https://github.com/imbo/imbo/pull/491
*/
public function testGetImagesAndReturnMetadata() {
$this->insertImages();
$this->insertImages(true);

$query = new Query();
$query->returnMetadata(true);

$images = $this->adapter->getImages(['user'], $query, $this->getMock('Imbo\Model\Images'));
$images = $this->adapter->getImages(['user', 'user2'], $query, $this->getMock('Imbo\Model\Images'));
$this->assertCount(6, $images, 'Incorrect length. Expected 6, got ' . count($images));

foreach ($images as $image) {
$this->assertArrayHasKey('metadata', $image);
}

$this->assertSame('user', $images[0]['user']);
$this->assertSame(['key5' => 'value5'], $images[0]['metadata']);

$this->assertSame('user2', $images[1]['user']);
$this->assertSame(['key4' => 'value4'], $images[1]['metadata']);

$this->assertSame('user', $images[2]['user']);
$this->assertSame(['key3' => 'value3'], $images[2]['metadata']);

$this->assertSame('user2', $images[3]['user']);
$this->assertSame(['key2' => 'value2'], $images[3]['metadata']);

$this->assertSame('user', $images[4]['user']);
$this->assertSame(['key1' => 'value1'], $images[4]['metadata']);
$this->assertSame(['key0' => 'value0'], $images[5]['metadata']);

$this->assertSame('user2', $images[5]['user']);
$this->assertSame(['key0' => 'value0'], $images[5]['metadata']);
}

public function testGetImagesReturnsImagesOnlyForSpecifiedUsers() {
Expand Down

0 comments on commit 1dc7809

Please sign in to comment.