Skip to content

Commit

Permalink
Clean up BuilderTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Rapaport committed Apr 27, 2017
1 parent f36377f commit 3647771
Showing 1 changed file with 49 additions and 30 deletions.
79 changes: 49 additions & 30 deletions tests/Unit/Fluent/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,115 @@

class BuilderTest extends TestCase
{
/** @var \Samrap\Acf\Fluent\Builder */
protected $builder;

public function setUp()
{
$this->setFields(['foo' => 'bar']);

$this->builder = new Builder(new RunnerMock);
}

/** @test */
public function setField()
{
$this->builder->field('foo');
$builder = new Builder(new RunnerMock);

$this->assertEquals('foo', $this->builder->field);
$builder->field('foo');

$this->assertEquals('foo', $builder->field);
}

/** @test */
public function setExpect()
{
$this->builder->expect('string');
$builder = new Builder(new RunnerMock);

$builder->expect('string');

$this->assertEquals('string', $this->builder->expect);
$this->assertEquals('string', $builder->expect);
}

/** @test */
public function setDefault()
{
$this->builder->default('bar');
$builder = new Builder(new RunnerMock);

$this->assertEquals('bar', $this->builder->default);
$builder->default('bar');

$this->assertEquals('bar', $builder->default);
}

/** @test */
public function setEscape()
{
$this->builder->escape();
$builder = new Builder(new RunnerMock);

$builder->escape();

$this->assertEquals('esc_html', $this->builder->escape);
$this->assertEquals('esc_html', $builder->escape);
}

/** @test */
public function setEscapeAllowsCustomFunction()
{
$this->builder->escape('htmlentities');
$builder = new Builder(new RunnerMock);

$builder->escape('htmlentities');

$this->assertEquals('htmlentities', $this->builder->escape);
$this->assertEquals('htmlentities', $builder->escape);
}

/** @test */
public function setId()
{
$this->builder->id(2);
$builder = new Builder(new RunnerMock);

$this->assertEquals(2, $this->builder->id);
$builder->id(2);

$this->assertEquals(2, $builder->id);
}

/** @test */
public function setShortcodes()
{
$this->builder->shortcodes();
$builder = new Builder(new RunnerMock);

$builder->shortcodes();

$this->assertTrue($this->builder->shortcodes);
$this->assertTrue($builder->shortcodes);
}

/** @test */
public function setRaw()
{
$this->builder->raw();
$builder = new Builder(new RunnerMock);

$this->assertTrue($this->builder->raw);
$builder->raw();

$this->assertTrue($builder->raw);
}

/** @test */
public function fluentBuilder()
{
$this->builder
$builder = new Builder(new RunnerMock);

$builder
->field('foo')
->id(2)
->expect('string')
->default('bar')
->escape();

$this->assertEquals('foo', $this->builder->field);
$this->assertEquals('string', $this->builder->expect);
$this->assertEquals('bar', $this->builder->default);
$this->assertEquals('esc_html', $this->builder->escape);
$this->assertEquals('foo', $builder->field);
$this->assertEquals('string', $builder->expect);
$this->assertEquals('bar', $builder->default);
$this->assertEquals('esc_html', $builder->escape);
}

/** @test */
public function builderGet()
{
$this->assertEquals('bar', $this->builder->field('foo')->get());
$builder = new Builder(new RunnerMock);

$this->assertEquals('bar', $builder->field('foo')->get());
}

/**
Expand All @@ -108,14 +123,18 @@ public function builderGet()
*/
public function builderGetThrowsExceptionIfFieldNotSet()
{
$this->builder->get();
$builder = new Builder(new RunnerMock);

$builder->get();
}

/** @test */
public function builderUpdate()
{
$this->builder->field('foo')->update('fiz');
$builder = new Builder(new RunnerMock);

$builder->field('foo')->update('fiz');

$this->assertEquals('fiz', $this->builder->field('foo')->get());
$this->assertEquals('fiz', $builder->field('foo')->get());
}
}

0 comments on commit 3647771

Please sign in to comment.