<commit_before><?php

namespace SilverStripe\Blog\Tests;

use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Widgets\BlogArchiveWidget;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\SS_List;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Widgets\Model\Widget;

class BlogArchiveWidgetTest extends SapphireTest
{
    protected static $fixture_file = 'BlogArchiveWidgetTest.yml';

    protected function setUp()
    {
        if (!class_exists(Widget::class)) {
            self::$fixture_file = null;
            parent::setUp();
            $this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
        }

        DBDatetime::set_mock_now('2017-09-20 12:00:00');

        parent::setUp();
    }

    protected function tearDown()
    {
        parent::tearDown();

        DBDatetime::clear_mock_now();
    }

    public function testArchiveMonthlyFromStage()
    {
        $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf(SS_List::class, $archive);
        $this->assertCount(3, $archive);
        $this->assertDOSContains([
            ['Title' => 'August 2017'],
            ['Title' => 'September 2017'],
            ['Title' => 'May 2015'],
        ], $archive);
    }

    public function testArchiveMonthlyFromLive()
    {
        $original = Versioned::get_stage();

        $this->objFromFixture(BlogPost::class, 'post-b')->publishRecursive();
        $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly')->publishRecursive();
        Versioned::set_stage(Versioned::LIVE);

        $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertCount(1, $archive);
        $this->assertDOSContains([
            ['Title' => 'August 2017'],
        ], $archive);

        if ($original) {
            Versioned::set_stage($original);
        }
    }

    public function testArchiveYearly()
    {
        $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf(SS_List::class, $archive);
        $this->assertCount(2, $archive);
        $this->assertDOSContains([
            ['Title' => '2017'],
            ['Title' => '2015'],
        ], $archive);
    }

    public function testArchiveMonthlyWithNewPostsAdded()
    {
        $original = Versioned::get_stage();<commit_msg>Remove use of deprecated assertDOSContains<commit_after><?php

namespace SilverStripe\Blog\Tests;

use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Widgets\BlogArchiveWidget;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\SS_List;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Widgets\Model\Widget;

class BlogArchiveWidgetTest extends SapphireTest
{
    protected static $fixture_file = 'BlogArchiveWidgetTest.yml';

    protected function setUp()
    {
        if (!class_exists(Widget::class)) {
            self::$fixture_file = null;
            parent::setUp();
            $this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
        }

        DBDatetime::set_mock_now('2017-09-20 12:00:00');

        parent::setUp();
    }

    protected function tearDown()
    {
        parent::tearDown();

        DBDatetime::clear_mock_now();
    }

    public function testArchiveMonthlyFromStage()
    {
        $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf(SS_List::class, $archive);
        $this->assertCount(3, $archive);
        $this->assertListContains([
            ['Title' => 'August 2017'],
            ['Title' => 'September 2017'],
            ['Title' => 'May 2015'],
        ], $archive);
    }

    public function testArchiveMonthlyFromLive()
    {
        $original = Versioned::get_stage();

        $this->objFromFixture(BlogPost::class, 'post-b')->publishRecursive();
        $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly')->publishRecursive();
        Versioned::set_stage(Versioned::LIVE);

        $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly');
        $archive = $widget->getArchive();

        $this->assertCount(1, $archive);
        $this->assertListContains([
            ['Title' => 'August 2017'],
        ], $archive);

        if ($original) {
            Versioned::set_stage($original);
        }
    }

    public function testArchiveYearly()
    {
        $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly');
        $archive = $widget->getArchive();

        $this->assertInstanceOf(SS_List::class, $archive);
        $this->assertCount(2, $archive);
        $this->assertListContains([
            ['Title' => '2017'],
            ['Title' => '2015'],
        ], $archive);
    }

    public function testArchiveMonthlyWithNewPostsAdded()
    {
        $original = Versioned::get_stage();
{'fraction_non_alphanumeric': 0.1448170731707317, 'fraction_numerical': 0.015625, 'mean_word_length': 2.985573272589218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5437045', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1546, 'n_words': 243}