<commit_before><?php
/**
 * ownCloud - mediametadata
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> (:imjalpreet) <<EMAIL>>
 * @copyright <NAME> (:imjalpreet) 2016
 */

namespace OCA\MediaMetadata\Hooks;


use OCA\MediaMetadata\AppInfo\Application;
use OCA\MediaMetadata\Tests\TestCase;

/**
 * Class ImageHooksTest
 *
 * @package OCA\MediaMetadata\Hooks
 */
class ImageHooksTest extends TestCase {
	/**
	 * @var \OCA\MediaMetadata\Hooks\ImageHooks
	 */
	protected $imageHooks;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root
	 */
	protected $root;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCA\MediaMetadata\Services\ImageDimensionMapper
	 */
	protected $mapper;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCP\IDb
	 */
	protected $db;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCA\MediaMetadata\Services\ExtractMetadata
	 */
	protected $extractor;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCA\MediaMetadata\Services\StoreMetadata
	 */
	protected $dbManager;
	/**
	 * @var $container
	 */
	private $container;

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

		$app = new Application();
		$this->container = $app->getContainer();

		$this->root = $this->getMockBuilder('OC\Files\Node\Root')
			->disableOriginalConstructor()
			->getMock();
		$this->db = $this->getMockBuilder(
			'\OCP\IDBConnection')
			->disableOriginalConstructor()
			->getMock();
		$this->mapper = $this->getMockBuilder('OCA\MediaMetadata\Services\ImageDimensionMapper')
			->setConstructorArgs([
				$this->db,
			])
			->getMock();
		$this->extractor = $this->getMockBuilder(
			'OCA\MediaMetadata\Services\ExtractMetadata')
			->disableOriginalConstructor()
			->getMock();
		$this->dbManager = $this->getMockBuilder(
			'\OCA\MediaMetadata\Services\StoreMetadata')
			->setConstructorArgs([
				$this->mapper
			])
			->getMock();
		$this->imageHooks = new ImageHooks(
			$this->root,
			$this->mapper,
			$this->extractor,
			$this->dbManager,
			$this->container->query('ServerContainer')->getConfig()->getSystemValue('datadirectory')
		);
	}

	public function testPostCreate() {
		$location = '/testFolder/test.jpg';
		$fileId = 260495;
		$jpgFile = $this->mockJpgFile($location, $fileId);

		$absolutePath = $this->container->query('ServerContainer')->getConfig()->getSystemValue('datadirectory').$location;

		$this->assertEquals($jpgFile->getPath(), $location);

		$metadata = null;

		$this->extractor->expects($this->once())
			->method('extract')
			->with($absolutePath)
			->willReturn($metadata);

		$this->dbManager->expects($this->once())
			->method('store')
			->with(
				$metadata,
				$jpgFile
			)
			->willReturn(true);<commit_msg>Issue #27: Minor update to the test<commit_after><?php
/**
 * ownCloud - mediametadata
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> (:imjalpreet) <<EMAIL>>
 * @copyright <NAME> (:imjalpreet) 2016
 */

namespace OCA\MediaMetadata\Hooks;


use OCA\MediaMetadata\AppInfo\Application;
use OCA\MediaMetadata\Tests\TestCase;

/**
 * Class ImageHooksTest
 *
 * @package OCA\MediaMetadata\Hooks
 */
class ImageHooksTest extends TestCase {
	/**
	 * @var \OCA\MediaMetadata\Hooks\ImageHooks
	 */
	protected $imageHooks;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root
	 */
	protected $root;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCA\MediaMetadata\Services\ImageDimensionMapper
	 */
	protected $mapper;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCP\IDb
	 */
	protected $db;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCA\MediaMetadata\Services\ExtractMetadata
	 */
	protected $extractor;
	/**
	 * @var \PHPUnit_Framework_MockObject_MockObject|\OCA\MediaMetadata\Services\StoreMetadata
	 */
	protected $dbManager;
	/**
	 * @var $container
	 */
	private $container;

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

		$app = new Application();
		$this->container = $app->getContainer();

		$this->root = $this->getMockBuilder('OC\Files\Node\Root')
			->disableOriginalConstructor()
			->getMock();
		$this->db = $this->getMockBuilder(
			'\OCP\IDBConnection')
			->disableOriginalConstructor()
			->getMock();
		$this->mapper = $this->getMockBuilder('OCA\MediaMetadata\Services\ImageDimensionMapper')
			->setConstructorArgs([
				$this->db,
			])
			->getMock();
		$this->extractor = $this->getMockBuilder(
			'OCA\MediaMetadata\Services\ExtractMetadata')
			->disableOriginalConstructor()
			->getMock();
		$this->dbManager = $this->getMockBuilder(
			'\OCA\MediaMetadata\Services\StoreMetadata')
			->setConstructorArgs([
				$this->mapper
			])
			->getMock();
		$this->imageHooks = new ImageHooks(
			$this->root,
			$this->mapper,
			$this->extractor,
			$this->dbManager,
			$this->container->query('ServerContainer')->getConfig()->getSystemValue('datadirectory')
		);
	}

	public function testPostCreate() {
		$location = '/testFolder/test.jpg';
		$fileId = 260495;
		$jpgFile = $this->mockJpgFile($location, $fileId);

		$absolutePath = $this->container->query('ServerContainer')->getConfig()->getSystemValue('datadirectory').$location;

		$this->assertEquals($jpgFile->getPath(), $location);

		$metadata = array(
			'imageWidth' => 100,
			'imageHeight' => 100
		);

		$this->extractor->expects($this->once())
			->method('extract')
			->with($absolutePath)
			->willReturn($metadata);

		$this->dbManager->expects($this->once())
			->method('store')
			->with(
				$metadata,
				$jpgFile
			)
			->willReturn(true);
{'fraction_non_alphanumeric': 0.16819302571327932, 'fraction_numerical': 0.0052835505459668895, 'mean_word_length': 4.2778810408921935, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 117, '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': '1348462', 'n_tokens_mistral': 2088, 'n_tokens_neox': 1844, 'n_words': 287}