public function testAttributes() { $item = new Item('Test of content', 'index.html', ['name' => 'test']); $this->assertCount(1, $item->getAttributes()); $item->setAttributes(['attr1' => 'text 1', 'attr2' => 'text 2']); $this->assertCount(2, $item->getAttributes()); }
/** * @inheritDoc */ public function getAttributes() { $attributes = parent::getAttributes(); if (isset($attributes['pagination']) === false) { return $attributes; } $attributes['pagination']['items'] = []; foreach ($this->pageItems as $item) { $attributes['pagination']['items'][$item->getId()] = $this->getItemAttributes($item); } return $attributes; }
public function testTaxonomyWithDefaulValues() { $post1 = new Item('Post 1', 'posts/2015-05-26-new-release', ['categories' => ['news', 'releases']]); $post2 = new Item('Post 2', 'posts/2015-05-26-new-feature', ['categories' => ['news', '']]); $collections = ['posts' => [$post1, $post2]]; $templateItem = new Item('Categories content', 'categories/index.html', ['max_page' => 1]); $templateItem->setPath('categories/index.html', Item::SNAPSHOT_PATH_RELATIVE); $catetoriesItems = $this->taxonomy->generateItems($templateItem, $collections); $this->assertTrue(is_array($catetoriesItems)); $this->assertCount(3, $catetoriesItems); $this->assertContainsOnly('\\Yosymfony\\Spress\\Core\\DataSource\\ItemInterface', $catetoriesItems); $item = $catetoriesItems[0]; $this->assertArrayHasKey('pagination', $item->getAttributes()); $this->assertArrayHasKey('term', $item->getAttributes()); $this->assertEquals('news', $item->getAttributes()['term']); $this->assertEquals('categories/news/index.html', $item->getPath(Item::SNAPSHOT_PATH_RELATIVE)); $this->assertEquals('/categories/news', $item->getPath(Item::SNAPSHOT_PATH_PERMALINK)); $this->assertEquals('Categories content', $item->getContent()); $item = $catetoriesItems[1]; $this->assertArrayHasKey('pagination', $item->getAttributes()); $this->assertArrayHasKey('term', $item->getAttributes()); $this->assertEquals('news', $item->getAttributes()['term']); $this->assertEquals('categories/news/page2/index.html', $item->getPath(Item::SNAPSHOT_PATH_RELATIVE)); $this->assertEquals('/categories/news/page2', $item->getPath(Item::SNAPSHOT_PATH_PERMALINK)); $this->assertEquals('Categories content', $item->getContent()); $item = $catetoriesItems[2]; $this->assertArrayHasKey('pagination', $item->getAttributes()); $this->assertArrayHasKey('term', $item->getAttributes()); $this->assertEquals('releases', $item->getAttributes()['term']); $this->assertEquals('categories/releases/index.html', $item->getPath(Item::SNAPSHOT_PATH_RELATIVE)); $this->assertEquals('/categories/releases', $item->getPath(Item::SNAPSHOT_PATH_PERMALINK)); $this->assertEquals('Categories content', $item->getContent()); $attributes = $post1->getAttributes(); $this->assertArrayHasKey('terms_url', $attributes); $this->assertArrayHasKey('categories', $attributes['terms_url']); $this->assertCount(2, $attributes['terms_url']['categories']); $this->assertEquals('/categories/news', $attributes['terms_url']['categories']['news']); $this->assertEquals('/categories/releases', $attributes['terms_url']['categories']['releases']); }
public function testTaxonomiesPointingToSameSlugedTerm() { $post1 = new Item('Post 1', 'posts/2015-05-26-new-release', ['categories' => ['баш']]); $post2 = new Item('Post 2', 'posts/2015-05-27-new-feature', ['categories' => ['баШ']]); $post3 = new Item('Post 3', 'posts/2015-05-28-new-feature', ['categories' => ['bash']]); $collections = ['posts' => [$post1, $post2, $post3]]; $templateItem = new Item('Categories content', 'categories/index.html', ['max_page' => 3]); $templateItem->setPath('categories/index.html', Item::SNAPSHOT_PATH_RELATIVE); $catetoriesItems = $this->taxonomy->generateItems($templateItem, $collections); $this->assertTrue(is_array($catetoriesItems)); $this->assertCount(1, $catetoriesItems); $item = $catetoriesItems[0]; $this->assertArrayHasKey('pagination', $item->getAttributes()); $this->assertArrayHasKey('term', $item->getAttributes()); $this->assertEquals('баш', $item->getAttributes()['term']); $this->assertEquals('categories/bash/index.html', $item->getPath(Item::SNAPSHOT_PATH_RELATIVE)); $attributes = $post1->getAttributes(); $this->assertArrayHasKey('terms_url', $attributes); $this->assertArrayHasKey('categories', $attributes['terms_url']); $this->assertCount(2, $attributes['terms_url']['categories']); $this->assertEquals('/categories/bash', $attributes['terms_url']['categories']['bash']); $this->assertEquals('/categories/bash', $attributes['terms_url']['categories']['баш']); }