Skip to content
Snippets Groups Projects
Commit 76be5746 authored by Demian Katz's avatar Demian Katz
Browse files

Fixed broken test.

parent fd13cd2b
No related merge requests found
...@@ -139,7 +139,8 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa ...@@ -139,7 +139,8 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa
// If this is a PostgreSQL connection, we may need to initialize the ID // If this is a PostgreSQL connection, we may need to initialize the ID
// from a sequence: // from a sequence:
if ($this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql" if ($this->adapter
&& $this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql"
&& $obj instanceof \VuFind\Db\Row\RowGateway && $obj instanceof \VuFind\Db\Row\RowGateway
) { ) {
// Do we have a sequence feature? // Do we have a sequence feature?
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* @link http://www.vufind.org Main Page * @link http://www.vufind.org Main Page
*/ */
namespace VuFindTest\Auth; namespace VuFindTest\Auth;
use VuFind\Auth\Database, Zend\Stdlib\Parameters; use VuFind\Auth\Database, Zend\Db\ResultSet\ResultSet, Zend\Stdlib\Parameters;
/** /**
* Database authentication test class. * Database authentication test class.
...@@ -110,9 +110,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase ...@@ -110,9 +110,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase
public function testCreateDuplicateEmail() public function testCreateDuplicateEmail()
{ {
// Fake services: // Fake services:
$table = $this->getMock( $table = $this->getMockTable(['getByEmail', 'getByUsername']);
'VuFind\Db\Table\Tags', ['getByEmail', 'getByUsername']
);
$table->expects($this->once())->method('getByEmail') $table->expects($this->once())->method('getByEmail')
->with($this->equalTo('me@mysite.com')) ->with($this->equalTo('me@mysite.com'))
->will($this->returnValue(true)); ->will($this->returnValue(true));
...@@ -136,9 +134,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase ...@@ -136,9 +134,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase
public function testCreateDuplicateUsername() public function testCreateDuplicateUsername()
{ {
// Fake services: // Fake services:
$table = $this->getMock( $table = $this->getMockTable(['getByUsername']);
'VuFind\Db\Table\Tags', ['getByUsername']
);
$table->expects($this->any())->method('getByUsername') $table->expects($this->any())->method('getByUsername')
->with($this->equalTo('good')) ->with($this->equalTo('good'))
->will($this->returnValue(true)); ->will($this->returnValue(true));
...@@ -156,10 +152,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase ...@@ -156,10 +152,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase
public function testSuccessfulCreation() public function testSuccessfulCreation()
{ {
// Fake services: // Fake services:
$table = $this->getMock( $table = $this->getMockTable(['insert', 'getByEmail', 'getByUsername']);
'VuFind\Db\Table\Tags', ['insert', 'getByEmail', 'getByUsername']
);
$table->expects($this->once())->method('insert');
$table->expects($this->once())->method('getByEmail') $table->expects($this->once())->method('getByEmail')
->with($this->equalTo('me@mysite.com')) ->with($this->equalTo('me@mysite.com'))
->will($this->returnValue(false)); ->will($this->returnValue(false));
...@@ -167,9 +160,10 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase ...@@ -167,9 +160,10 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase
->with($this->equalTo('good')) ->with($this->equalTo('good'))
->will($this->returnValue(false)); ->will($this->returnValue(false));
$db = $this->getDatabase($table); $db = $this->getDatabase($table);
$this->assertEquals( $prototype = $table->getResultSetPrototype()->getArrayObjectPrototype();
false, $db->create($this->getRequest($this->getCreateParams())) $prototype->expects($this->once())->method('save');
); $user = $db->create($this->getRequest($this->getCreateParams()));
$this->assertTrue(is_object($user));
} }
// INTERNAL API // INTERNAL API
...@@ -191,6 +185,43 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase ...@@ -191,6 +185,43 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase
]; ];
} }
/**
* Get a mock row object
*
* @return \VuFind\Db\Row\User
*/
protected function getMockRow()
{
return $this->getMockBuilder('VuFind\Db\Row\User')
->disableOriginalConstructor()
->getMock();
}
/**
* Get a mock table object
*
* @param array $methods Methods to mock
*
* @return \VuFind\Db\Table\User
*/
protected function getMockTable($methods = [])
{
$methods[] = 'getResultSetPrototype';
$mock = $this->getMockBuilder('VuFind\Db\Table\User')
->disableOriginalConstructor()
->setMethods($methods)
->getMock();
$mock->expects($this->any())->method('getResultSetPrototype')
->will(
$this->returnValue(
new ResultSet(
ResultSet::TYPE_ARRAYOBJECT, $this->getMockRow()
)
)
);
return $mock;
}
/** /**
* Get a fake HTTP request. * Get a fake HTTP request.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment