/** * Tests that all_element_texts can correctly produce an array as output. */ public function testArrayOutput() { $title = 'title'; $subject = 'subject'; $description = 'description'; $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)), 'Subject' => array(array('text' => $subject, 'html' => false)), 'Description' => array(array('text' => $description, 'html' => false)))); $item = new Item(); $item->addElementTextsByArray($elementTexts); $item->save(); $metadataOutput = all_element_texts($item, array('return_type' => 'array')); $this->assertInternalType('array', $metadataOutput); $this->assertArrayHasKey('Dublin Core', $metadataOutput); $this->assertEquals($title, $metadataOutput['Dublin Core']['Title'][0]); $this->assertEquals($subject, $metadataOutput['Dublin Core']['Subject'][0]); $this->assertEquals($description, $metadataOutput['Dublin Core']['Description'][0]); }
/** * Creates a test Item and returns a citation string. * * @todo This function, like Item::getCitation(), uses date() to generate a date * accessed for the citation. This should be changed when we * internationalize date outputs. * * @param string|null The Item title. * @param string|null The Item creator. * @return string The Item's citation string. */ protected function _createItemCitationString($title = null, $creator = null) { $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)), 'Creator' => array(array('text' => $creator, 'html' => false)))); $item = new Item(); $item->addElementTextsByArray($elementTexts); $item->save(); set_current_record('item', $item, true); $siteTitle = option('site_title'); $dateAccessed = format_date(time(), Zend_Date::DATE_LONG); $itemUrl = record_url('item', null, true); $citationHtml = "“{$title},” <em>{$siteTitle}</em>, accessed {$dateAccessed}, {$itemUrl}."; if ($creator) { $citationHtml = "{$creator}, {$citationHtml}"; } return $citationHtml; }
/** * Creates some feature items for use in our tests. */ protected function _createFeaturedItems($featured = true) { $db = $this->db; $ids = array(); for ($i = 1; $i < 6; $i++) { $title = "Title {$i}"; $description = "Description for item {$i}."; $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)), 'Description' => array(array('text' => $description, 'html' => false)))); $item = new Item(); $item->public = 1; $item->featured = $featured ? '1' : '0'; $item->addElementTextsByArray($elementTexts); $item->save(); $ids[] = $item->id; } return $ids; }