public function testGetAddedOrDeletedModelsFromReadSubscriptionTable() { ReadPermissionsSubscriptionUtil::buildTables(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $messageLogger = new DebuggingMessageLogger(); $task = TaskTestHelper::createTaskByNameForOwner('Test Task', $super); // Because ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables completed in previous test // status need to be ReadPermissionsSubscriptionUtil::STATUS_COMPLETED $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $this->assertTrue(ReadPermissionsSubscriptionUtil::isReadPermissionSubscriptionUpdateCompleted()); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $this->assertTrue(ReadPermissionsSubscriptionUtil::isReadPermissionSubscriptionUpdateCompleted()); $sql = "SELECT * FROM task_read_subscription WHERE userid = " . $super->id; $permissionTableRows = ZurmoRedBean::getAll($sql); $this->assertEquals(1, count($permissionTableRows)); $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super); $this->asserttrue(is_array($addedModelIds)); $this->assertEquals(1, count($addedModelIds)); ModelCreationApiSyncUtil::insertItem('TestService', $task->id, 'Task', '2013-05-03 15:16:06'); $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super); $this->asserttrue(is_array($addedModelIds)); $this->assertEquals(0, count($addedModelIds)); }
public function testGetDeletedModelIds() { ReadPermissionsSubscriptionUtil::recreateTable('account_read_subscription'); ModelCreationApiSyncUtil::buildTable(); $messageLogger = new DebuggingMessageLogger(); $timestamp = time(); sleep(1); $account1 = AccountTestHelper::createAccountByNameForOwner('First Test Delete Account', Yii::app()->user->userModel); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $models = ModelStateChangesSubscriptionUtil::getDeletedModelIds('apiTest', 'Account', 2, 0, $timestamp); $this->assertTrue(is_array($models)); $this->assertTrue(empty($models)); $account1Id = $account1->id; $this->assertTrue($account1->delete()); $models = ModelStateChangesSubscriptionUtil::getDeletedModelIds('apiTest', 'Account', 2, 0, $timestamp); $this->assertTrue(is_array($models)); $this->assertTrue(empty($models)); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $models = ModelStateChangesSubscriptionUtil::getDeletedModelIds('apiTest', 'Account', 2, 0, $timestamp); $this->assertTrue(is_array($models)); $this->assertEquals(1, count($models)); $this->assertEquals($account1Id, $models[0]); // Check pagination sleep(1); $timestamp = time(); sleep(1); $account2 = AccountTestHelper::createAccountByNameForOwner('Second Test Delete Account', Yii::app()->user->userModel); $account3 = AccountTestHelper::createAccountByNameForOwner('Third Test Delete Account', Yii::app()->user->userModel); $account4 = AccountTestHelper::createAccountByNameForOwner('Forth Test Delete Account', Yii::app()->user->userModel); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $account2Id = $account2->id; $account3Id = $account3->id; $account4Id = $account4->id; $this->assertTrue($account2->delete()); $this->assertTrue($account3->delete()); $this->assertTrue($account4->delete()); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $models = ModelStateChangesSubscriptionUtil::getDeletedModelIds('apiTest', 'Account', 2, 0, $timestamp); $this->assertTrue(is_array($models)); $this->assertEquals(2, count($models)); $this->assertEquals($account2Id, $models[0]); $this->assertEquals($account3Id, $models[1]); // Second page $models = ModelStateChangesSubscriptionUtil::getDeletedModelIds('apiTest', 'Account', 2, 2, $timestamp); $this->assertTrue(is_array($models)); $this->assertEquals(1, count($models)); $this->assertEquals($account4Id, $models[0]); }