/** * Test users count using NonSystemUsersStateMetadataAdapter */ public function testGetUsersListUsingNonSystemUsersStateMetadataAdapter() { $users = User::getAll(); $this->assertEquals(5, count($users)); $user = UserTestHelper::createBasicUser('mysysuser'); $user->setIsSystemUser(); $this->assertTrue($user->save()); $nonSystemUsersStateMetadataAdapter = new NonSystemUsersStateMetadataAdapter(array('clauses' => array(), 'structure' => '')); $metadata = $nonSystemUsersStateMetadataAdapter->getAdaptedDataProviderMetadata(); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('User'); $where = RedBeanModelDataProvider::makeWhere('User', $metadata, $joinTablesAdapter); $models = User::getSubset($joinTablesAdapter, null, null, $where, null); $this->assertEquals(5, count($models)); $actualUsers = User::getAll(); $this->assertEquals(6, count($actualUsers)); unset($user); $user = User::getByUsername('mysysuser'); $this->assertTrue((bool) $user->isSystemUser); $user->setIsNotSystemUser(); $this->assertTrue($user->save()); unset($user); $user = User::getByUsername('mysysuser'); $this->assertEquals(0, $user->isSystemUser); $where = RedBeanModelDataProvider::makeWhere('User', $metadata, $joinTablesAdapter); $models = User::getSubset($joinTablesAdapter, null, null, $where, null); $this->assertEquals(6, count($models)); }
/** * Test structure and clauses for NonSystemUsersStateMetadataAdapter */ public function testNonSystemUsersStateMetadataAdapter() { $nonSystemUsersStateMetadataAdapter = new NonSystemUsersStateMetadataAdapter(array('clauses' => array(), 'structure' => '')); $metadata = $nonSystemUsersStateMetadataAdapter->getAdaptedDataProviderMetadata(); $this->assertEquals('(1 or 2)', $metadata['structure']); $nonSystemUsersStateMetadataAdapter1 = new NonSystemUsersStateMetadataAdapter(array('clauses' => array(), 'structure' => 'x and y')); $metadata = $nonSystemUsersStateMetadataAdapter1->getAdaptedDataProviderMetadata(); $this->assertEquals('(x and y) and (1 or 2)', $metadata['structure']); }