/** * Driver function */ public static function execute(&$parser, $project = '', $class = '', $importance = '') { $newRecord = false; // Title class object for the Main page of this Talk page $pageObj = $parser->getTitle()->getSubjectPage(); $pageTitle = $pageObj->getText(); $exists = PageAssessmentsBody::checkIfExists($pageTitle, $project, $class, $importance); switch ($exists) { case 'nochange': return; case 'change': break; default: $newRecord = true; break; } $pageNamespace = $pageObj->getNamespace(); $pageId = $pageObj->getArticleID(); $revisionId = $pageObj->getLatestRevID(); // Compile the array to be inserted to the DB $values = array('pa_page_id' => $pageId, 'pa_page_name' => $pageTitle, 'pa_page_namespace' => $pageNamespace, 'pa_project' => $project, 'pa_class' => $class, 'pa_importance' => $importance, 'pa_page_revision' => $revisionId); if ($newRecord) { PageAssessmentsBody::insertRecord($values); } else { PageAssessmentsBody::updateRecord($values); } $values['pa_user_id'] = $parser->getRevisionUser(); PageAssessmentsBody::insertLogRecord($values); return; }
/** * Test the getAllProjects() function in PageAssessmentsBody class */ public function testGetAllProjects() { $pageBody = new PageAssessmentsBody(); // Insert a record $this->testInsert(); $values = array('pa_page_id' => '10', 'pa_project_id' => '4', 'pa_class' => 'B', 'pa_importance' => 'Low', 'pa_page_revision' => '21'); // Insert another record $pageBody->insertRecord($values); $res = $pageBody->getAllProjects('10'); $expected = array(3, 4); // Since the projects may be returned in any order, we can't do a simple // assertEquals() on the arrays. Instead we compare the arrays using array_diff() // in both directions and make sure that the results are empty. $this->assertEmpty(array_merge(array_diff($expected, $res), array_diff($res, $expected))); }