/** * Get default asset data (used in template) * @return array $assetData */ public static function getDefaultAssetData() { $data = array('videoTitle' => wfMessage('videopagetool-video-title-default-text')->plain(), 'videoKey' => '', 'videoThumb' => '', 'largeThumbUrl' => '', 'altThumbName' => wfMessage('videopagetool-image-title-default-text')->plain(), 'altThumbKey' => '', 'displayTitle' => '', 'description' => '', 'videoTitleClass' => 'alternative', 'altThumbClass' => 'alternative'); $defaultData = array_merge($data, parent::getDefaultAssetData()); return $defaultData; }
/** * Format form data * @param integer $requiredRows * @param array $formValues * @param string $errMsg * @return array $data */ public static function formatFormData($requiredRows, $formValues, &$errMsg) { // set displayTitle = categoryName if displayTitle is empty foreach ($formValues['displayTitle'] as $order => &$value) { if (empty($value)) { $value = $formValues['categoryName'][$order]; } } // Remove rows where categoryName is empty $resetRows = false; $rows = count($formValues['categoryName']); $helper = new VideoPageToolHelper(); for ($i = $rows - 1; $i >= $helper->getRequiredRowsMin('category'); $i--) { if (!empty($formValues['categoryName'][$i])) { break; } foreach (STATIC::$dataFields as $formFieldName => $varName) { unset($formValues[$formFieldName][$i]); } $resetRows = true; } // update required rows if ($resetRows) { $requiredRows = $helper->getRequiredRows('category', $formValues); } return parent::formatFormData($requiredRows, $formValues, $errMsg); }
/** * Format form data * @param string $section * @param integer $requiredRows * @param array $formValues * @param string $errMsg * @return array */ public function formatFormData($section, $requiredRows, $formValues, &$errMsg) { $className = VideoPageToolAsset::getClassNameFromSection($section); $data = $className::formatFormData($requiredRows, $formValues, $errMsg); return $data; }
/** * Get default values by section * @param string $section [featured/category/fan] * @param integer $requiredRows * @return array */ public function getDefaultValuesBySection($section, $requiredRows = 0) { $className = VideoPageToolAsset::getClassNameFromSection($section); $values = array(); if (empty($requiredRows)) { $requiredRows = $this->getRequiredRowsMax($section); } for ($i = 1; $i <= $requiredRows; $i++) { $values[$i] = $className::getDefaultAssetData(); } return $values; }
/** * @dataProvider CRUDAssetData */ public function testCRUDAsset($type, $order, $data) { $section = $type::SECTION; /** * Create and save the object */ // Check creation $asset = VideoPageToolAsset::newAsset($this->programID, $section, $order); $this->assertInstanceOf($type, $asset, "Failed to create new {$type} object"); $asset->setData($data); global $wgUser; $asset->setUpdatedBy($wgUser->getId()); $status = $asset->save(); $this->assertTrue($status->isGood(), 'Failed to save new $type object'); $this->assertInternalType('integer', $asset->getAssetId(), 'Result of getAssetId is not an integer'); $this->assertGreaterThan(0, $asset->getAssetId(), 'Asset ID is not greater than zero'); // Make sure we can get the program $program = $asset->getProgram(); $this->assertTrue($program instanceof VideoPageToolProgram, 'Did not get a program object back from getProgram'); /** * Check loading the object from cache */ $memcLoadedAsset = VideoPageToolAsset::newAsset($this->programID, $section, $order); $this->assertEquals($asset->getAssetId(), $memcLoadedAsset->getAssetId(), "Not able to load saved asset"); // Check getters $this->assertEquals($this->programID, $memcLoadedAsset->getProgramId(), 'Got wrong program ID'); $this->assertEquals($section, $memcLoadedAsset->getSection(), 'Got wrong section name'); $this->assertEquals($order, $memcLoadedAsset->getOrder(), 'Got wrong order number'); // Check for default data $defaultAssetData = $memcLoadedAsset->getDefaultAssetData(); $this->assertNotNull($defaultAssetData, 'No default data present'); // Get the data $assetData = $memcLoadedAsset->getAssetData(); // Note that $assetData will always be the classes default data since the test data // we're sending in does not name a valid video title $this->assertNotNull($assetData, 'No asset data present'); // Check the asset data against what we saved foreach ($data as $prop => $value) { $this->assertObjectHasAttribute($prop, $memcLoadedAsset); $this->assertAttributeEquals($value, $prop, $memcLoadedAsset, "Attribute {$prop} has incorrect value"); } // Let slave catch up sleep(1); /** * Check loading the object from database */ // Make sure memcache doesn't fulfill our request $this->disableMemcached(); $dbLoadedAsset = VideoPageToolAsset::newAsset($this->programID, $section, $order); $this->assertEquals($asset->getAssetId(), $dbLoadedAsset->getAssetId(), "Not able to load saved asset"); // Check getters $this->assertEquals($this->programID, $dbLoadedAsset->getProgramId(), 'Got wrong program ID'); $this->assertEquals($section, $dbLoadedAsset->getSection(), 'Got wrong section name'); $this->assertEquals($order, $dbLoadedAsset->getOrder(), 'Got wrong order number'); // Check for default data $defaultAssetData = $dbLoadedAsset->getDefaultAssetData(); $this->assertNotNull($defaultAssetData, 'No default data present'); // Get the data $assetData = $dbLoadedAsset->getAssetData(); // Note that $assetData will always be the classes default data since the test data // we're sending in does not name a valid video title $this->assertNotNull($assetData, 'No asset data present'); // Check the asset data against what we saved foreach ($data as $prop => $value) { $this->assertObjectHasAttribute($prop, $dbLoadedAsset); $this->assertAttributeEquals($value, $prop, $dbLoadedAsset, "Attribute {$prop} has incorrect value"); } // Check delete $this->enableMemcached(); $status = $asset->delete(); $this->assertTrue($status->isGood(), 'Failed to delete new $type object'); $deletedAsset = VideoPageToolAsset::newAsset($this->programID, $section, $order); $this->assertNull($deletedAsset->getAssetId(), 'Unsuccessful delete'); }