You are here

class AssetDataTest in Media: Acquia DAM 8

Tests to validate that the asset data service works as expected.

@group media_acquiadam

Hierarchy

Expanded class hierarchy of AssetDataTest

File

tests/src/Unit/AssetDataTest.php, line 16

Namespace

Drupal\Tests\media_acquiadam\Unit
View source
class AssetDataTest extends UnitTestCase {
  use AcquiadamAssetDataTrait;

  /**
   * Container builder helper.
   *
   * @var \Drupal\Core\DependencyInjection\ContainerBuilder
   */
  protected $container;

  /**
   * Media: Acquia DAM asset data service.
   *
   * Mocked to have a fixed set/get.
   *
   * @var \Drupal\media_acquiadam\AssetData|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $acquiaAssetData;

  /**
   * Validates that we can correctly determine if an asset has been updated.
   */
  public function testIsUpdatedAsset() {
    $asset = $this
      ->getAssetData();
    $this
      ->assertTrue($this->acquiaAssetData
      ->isUpdatedAsset($asset));
    $asset->id = 3455970;
    $this
      ->assertFalse($this->acquiaAssetData
      ->isUpdatedAsset($asset));
  }

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $connection = $this
      ->getMockBuilder(Connection::class)
      ->disableOriginalConstructor()
      ->getMock();
    $asset_data = $this
      ->getMockBuilder(AssetData::class)
      ->disableOriginalConstructor()
      ->setMethods([
      'get',
      'set',
    ])
      ->getMock();
    $asset_data
      ->method('get')
      ->willReturnMap([
      [
        3455969,
        'version',
        3,
      ],
      [
        3455970,
        'version',
        4,
      ],
    ]);
    $this->acquiaAssetData = $asset_data;
    $this->container = new ContainerBuilder();
    $this->container
      ->set('database', $connection);
    \Drupal::setContainer($this->container);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiadamAssetDataTrait::generateNewVersion protected function Create a new version of a given asset.
AcquiadamAssetDataTrait::getAssetData protected function Returns an Asset object for testing against.
AssetDataTest::$acquiaAssetData protected property Media: Acquia DAM asset data service.
AssetDataTest::$container protected property Container builder helper.
AssetDataTest::setUp protected function Overrides UnitTestCase::setUp
AssetDataTest::testIsUpdatedAsset public function Validates that we can correctly determine if an asset has been updated.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.