diff --git a/module/VuFind/src/VuFind/Db/Table/Gateway.php b/module/VuFind/src/VuFind/Db/Table/Gateway.php index 474abc0c93c3b96a70c3814cd3d3f595b2e1a641..cc010df9acb0a84dac774785c5b7f0bf11750abb 100644 --- a/module/VuFind/src/VuFind/Db/Table/Gateway.php +++ b/module/VuFind/src/VuFind/Db/Table/Gateway.php @@ -139,7 +139,8 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa // If this is a PostgreSQL connection, we may need to initialize the ID // from a sequence: - if ($this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql" + if ($this->adapter + && $this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql" && $obj instanceof \VuFind\Db\Row\RowGateway ) { // Do we have a sequence feature? diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseUnitTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseUnitTest.php index 11b8251e2f4ddab2c5533e4d08f1046d4121037e..2f2057bb8b26f68dc484e4550b20181c6d4bc46c 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseUnitTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/DatabaseUnitTest.php @@ -26,7 +26,7 @@ * @link http://www.vufind.org Main Page */ 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. @@ -110,9 +110,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase public function testCreateDuplicateEmail() { // Fake services: - $table = $this->getMock( - 'VuFind\Db\Table\Tags', ['getByEmail', 'getByUsername'] - ); + $table = $this->getMockTable(['getByEmail', 'getByUsername']); $table->expects($this->once())->method('getByEmail') ->with($this->equalTo('me@mysite.com')) ->will($this->returnValue(true)); @@ -136,9 +134,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase public function testCreateDuplicateUsername() { // Fake services: - $table = $this->getMock( - 'VuFind\Db\Table\Tags', ['getByUsername'] - ); + $table = $this->getMockTable(['getByUsername']); $table->expects($this->any())->method('getByUsername') ->with($this->equalTo('good')) ->will($this->returnValue(true)); @@ -156,10 +152,7 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase public function testSuccessfulCreation() { // Fake services: - $table = $this->getMock( - 'VuFind\Db\Table\Tags', ['insert', 'getByEmail', 'getByUsername'] - ); - $table->expects($this->once())->method('insert'); + $table = $this->getMockTable(['insert', 'getByEmail', 'getByUsername']); $table->expects($this->once())->method('getByEmail') ->with($this->equalTo('me@mysite.com')) ->will($this->returnValue(false)); @@ -167,9 +160,10 @@ class DatabaseUnitTest extends \VuFindTest\Unit\DbTestCase ->with($this->equalTo('good')) ->will($this->returnValue(false)); $db = $this->getDatabase($table); - $this->assertEquals( - false, $db->create($this->getRequest($this->getCreateParams())) - ); + $prototype = $table->getResultSetPrototype()->getArrayObjectPrototype(); + $prototype->expects($this->once())->method('save'); + $user = $db->create($this->getRequest($this->getCreateParams())); + $this->assertTrue(is_object($user)); } // INTERNAL API @@ -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. *